-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change type and nullability. More complex changes might still fail, but the it's a step in the right direction.
- Loading branch information
1 parent
0cd5f5d
commit 6836d86
Showing
7 changed files
with
288 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE <%- tableId %> ALTER COLUMN <%- columnName %> <%- nullable %>; |
2 changes: 1 addition & 1 deletion
2
...-generators/column/different-template.ejs → ...ement-generators/column/type-template.ejs
This file contains 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 +1 @@ | ||
ALTER TABLE <%- tableId %> ALTER COLUMN <%- columnName %> TYPE <%- constraint %>; | ||
ALTER TABLE <%- tableId %> ALTER COLUMN <%- columnName %> TYPE <%- type %>; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-env mocha */ | ||
|
||
const executionWithJson = require('./fixtures/execution-with-json.json') | ||
const executionWithString = require('./fixtures/execution-with-string.json') | ||
const executionWithAdditionalColumn = require('./fixtures/execution-with-additional-column.json') | ||
|
||
const pgDiffSync = require('./../lib') | ||
const expect = require('chai').expect | ||
|
||
describe('columns', () => { | ||
it('add a column', () => { | ||
const statements = pgDiffSync(executionWithJson, executionWithAdditionalColumn) | ||
expect(statements).to.eql( | ||
[ | ||
'ALTER TABLE pg_diff_sync_test.execution ADD COLUMN additional text NOT NULL;' | ||
] | ||
) | ||
}) | ||
|
||
it('remove a column', () => { | ||
const statements = pgDiffSync(executionWithAdditionalColumn, executionWithJson) | ||
expect(statements).to.eql( | ||
[ | ||
// We don't actually remove it | ||
] | ||
) | ||
}) | ||
|
||
it('change column types', () => { | ||
const statements = pgDiffSync(executionWithJson, executionWithString) | ||
expect(statements).to.eql( | ||
[ | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN ctx TYPE text;', | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN ctx DROP NOT NULL;', | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN executionOptions TYPE text;', | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN executionOptions DROP NOT NULL;' | ||
] | ||
) | ||
}) | ||
|
||
it('change column type, add another column', () => { | ||
const statements = pgDiffSync(executionWithString, executionWithAdditionalColumn) | ||
expect(statements).to.eql( | ||
[ | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN ctx TYPE jsonb USING ctx::jsonb;', | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN ctx SET NOT NULL;', | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN executionOptions TYPE jsonb USING executionOptions::jsonb;', | ||
'ALTER TABLE pg_diff_sync_test.execution ALTER COLUMN executionOptions SET NOT NULL;', | ||
'ALTER TABLE pg_diff_sync_test.execution ADD COLUMN additional text NOT NULL;' | ||
] | ||
) | ||
|
||
}) | ||
|
||
}) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"generated": "2017-05-22T16:06:17.034Z", | ||
"schemas": { | ||
"pg_diff_sync_test": { | ||
"schemaExistsInDatabase": true, | ||
"comment": "Schema auto-generated by Relationize.js!", | ||
"tables": { | ||
"execution": { | ||
"comment": "Statebox executions instances", | ||
"pkColumnNames": [ | ||
"execution_name" | ||
], | ||
"columns": { | ||
"executionName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"ctx": { | ||
"array": false, | ||
"dataType": "jsonb", | ||
"isNullable": "NO" | ||
}, | ||
"currentStateName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"currentResource": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"stateMachineName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"status": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"executionOptions": { | ||
"array": false, | ||
"dataType": "jsonb", | ||
"isNullable": "NO" | ||
}, | ||
"additional": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
} | ||
}, | ||
"indexes": {}, | ||
"fkConstraints":{} | ||
} | ||
} | ||
} | ||
}, | ||
"expectedDbSchemaNames": [ | ||
"pg_diff_sync_test" | ||
] | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"generated": "2017-05-22T16:06:17.034Z", | ||
"schemas": { | ||
"pg_diff_sync_test": { | ||
"schemaExistsInDatabase": true, | ||
"comment": "Schema auto-generated by Relationize.js!", | ||
"tables": { | ||
"execution": { | ||
"comment": "Statebox executions instances", | ||
"pkColumnNames": [ | ||
"execution_name" | ||
], | ||
"columns": { | ||
"executionName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"ctx": { | ||
"array": false, | ||
"dataType": "jsonb", | ||
"isNullable": "NO" | ||
}, | ||
"currentStateName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"currentResource": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"stateMachineName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"status": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"executionOptions": { | ||
"array": false, | ||
"dataType": "jsonb", | ||
"isNullable": "NO" | ||
} | ||
}, | ||
"indexes": {}, | ||
"fkConstraints":{} | ||
} | ||
} | ||
} | ||
}, | ||
"expectedDbSchemaNames": [ | ||
"pg_diff_sync_test" | ||
] | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"generated": "2017-05-22T16:06:17.034Z", | ||
"schemas": { | ||
"pg_diff_sync_test": { | ||
"schemaExistsInDatabase": true, | ||
"comment": "Schema auto-generated by Relationize.js!", | ||
"tables": { | ||
"execution": { | ||
"comment": "Statebox executions instances", | ||
"pkColumnNames": [ | ||
"execution_name" | ||
], | ||
"columns": { | ||
"executionName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"ctx": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "YES" | ||
}, | ||
"currentStateName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"currentResource": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"stateMachineName": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"status": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "NO" | ||
}, | ||
"executionOptions": { | ||
"array": false, | ||
"dataType": "text", | ||
"isNullable": "YES" | ||
} | ||
}, | ||
"indexes": {}, | ||
"fkConstraints":{} | ||
} | ||
} | ||
} | ||
}, | ||
"expectedDbSchemaNames": [ | ||
"pg_diff_sync_test" | ||
] | ||
} |