-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
#4338 pg schema upgrade #4375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vitaly-t
merged 11 commits into
parse-community:master
from
paulovitin:fix/4338-pg-schema-upgrade
Jan 3, 2018
Merged
#4338 pg schema upgrade #4375
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ce984b8
Method to upgrade schemas in Postgres;
paulovitin c87d4d5
Remove the columns delete in schemaUpgrade method;
paulovitin 9ed3536
ESLint fix and PostgresStorageAdapter.schemaUpgrade spec test
paulovitin 248d7c0
Add check columns before and after schema upgrade, and remove the unn…
paulovitin 3b9acb4
Optimize the schemaUpgrade method following @vitaly-t instructions, a…
paulovitin 59dacea
If the class does not have any columns and needs an upgrade the code …
paulovitin 6f5db46
Update PostgresStorageAdapter.js
vitaly-t fe54648
Update PostgresStorageAdapter.spec.js
vitaly-t 6ceee07
Update PostgresStorageAdapter.spec.js
vitaly-t d80eb2f
Merge branch 'master' into fix/4338-pg-schema-upgrade
flovilmart 4b348ad
Merge branch 'master' into fix/4338-pg-schema-upgrade
vitaly-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter'; | ||
const databaseURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database'; | ||
|
||
const getColumns = (client, className) => { | ||
return client.map('SELECT column_name FROM information_schema.columns WHERE table_name = $<className>', { className }, a => a.column_name); | ||
}; | ||
|
||
describe_only_db('postgres')('PostgresStorageAdapter', () => { | ||
beforeEach(done => { | ||
const adapter = new PostgresStorageAdapter({ uri: databaseURI }) | ||
|
@@ -19,4 +23,100 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => { | |
expect(adapter._client.$pool.ending).toEqual(true); | ||
done(); | ||
}); | ||
|
||
it('schemaUpgrade, upgrade the database schema when schema changes', done => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo fixed... |
||
const adapter = new PostgresStorageAdapter({ uri: databaseURI }); | ||
const client = adapter._client; | ||
const className = '_PushStatus'; | ||
const schema = { | ||
fields: { | ||
"pushTime": { type: 'String' }, | ||
"source": { type: 'String' }, | ||
"query": { type: 'String' }, | ||
}, | ||
}; | ||
|
||
adapter.createTable(className, schema) | ||
.then(() => getColumns(client, className)) | ||
.then(columns => { | ||
expect(columns).toContain('pushTime'); | ||
expect(columns).toContain('source'); | ||
expect(columns).toContain('query'); | ||
expect(columns).not.toContain('expiration_interval'); | ||
|
||
schema.fields.expiration_interval = { type:'Number' }; | ||
return adapter.schemaUpgrade(className, schema); | ||
}) | ||
.then(() => getColumns(client, className)) | ||
.then(columns => { | ||
expect(columns).toContain('pushTime'); | ||
expect(columns).toContain('source'); | ||
expect(columns).toContain('query'); | ||
expect(columns).toContain('expiration_interval'); | ||
done(); | ||
}) | ||
.catch(error => done.fail(error)); | ||
}); | ||
|
||
it('schemaUpgrade, maintain correct schema', done => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo fixed... |
||
const adapter = new PostgresStorageAdapter({ uri: databaseURI }); | ||
const client = adapter._client; | ||
const className = 'Table'; | ||
const schema = { | ||
fields: { | ||
"columnA": { type: 'String' }, | ||
"columnB": { type: 'String' }, | ||
"columnC": { type: 'String' }, | ||
}, | ||
}; | ||
|
||
adapter.createTable(className, schema) | ||
.then(() => getColumns(client, className)) | ||
.then(columns => { | ||
expect(columns).toContain('columnA'); | ||
expect(columns).toContain('columnB'); | ||
expect(columns).toContain('columnC'); | ||
|
||
return adapter.schemaUpgrade(className, schema); | ||
}) | ||
.then(() => getColumns(client, className)) | ||
.then(columns => { | ||
expect(columns.length).toEqual(3); | ||
expect(columns).toContain('columnA'); | ||
expect(columns).toContain('columnB'); | ||
expect(columns).toContain('columnC'); | ||
done(); | ||
}) | ||
.catch(error => done.fail(error)); | ||
}); | ||
|
||
it('Create a table without columns and upgrade with columns', done => { | ||
const adapter = new PostgresStorageAdapter({ uri: databaseURI }); | ||
const client = adapter._client; | ||
const className = 'EmptyTable'; | ||
let schema = {}; | ||
|
||
adapter.createTable(className, schema) | ||
.then(() => getColumns(client, className)) | ||
.then(columns => { | ||
expect(columns.length).toBe(0); | ||
|
||
schema = { | ||
fields: { | ||
"columnA": { type: 'String' }, | ||
"columnB": { type: 'String' } | ||
}, | ||
}; | ||
|
||
return adapter.schemaUpgrade(className, schema); | ||
}) | ||
.then(() => getColumns(client, className)) | ||
.then(columns => { | ||
expect(columns.length).toEqual(2); | ||
expect(columns).toContain('columnA'); | ||
expect(columns).toContain('columnB'); | ||
done(); | ||
}) | ||
.catch(error => done.fail(error)); | ||
}) | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize the above was finally changed, alright!