-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple 'alter column' sub operations (#338)
Allow 'alter column' operations to include multiple sub-operations. This means migrations like this one are now possible: ```json { "name": "35_alter_column_multiple", "operations": [ { "alter_column": { "table": "events", "column": "name", "name": "event_name", "type": "text", "nullable": false, "unique": { "name": "events_event_name_unique" }, "check": { "name": "event_name_length", "constraint": "length(name) > 3" }, "up": "(SELECT CASE WHEN name IS NULL THEN 'placeholder' ELSE name END)", "down": "name" } } ] } ``` This 'alter column' operation: * Renames a column * Changes its type * Sets it `NOT NULL` * Adds a unique constraint * Adds a check constraint Previously, this would have required 5 different operations. Builds on #337. Fixes #336
- Loading branch information
1 parent
a444723
commit a4222d8
Showing
15 changed files
with
583 additions
and
201 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,22 @@ | ||
{ | ||
"name": "34_create_events_table", | ||
"operations": [ | ||
{ | ||
"create_table": { | ||
"name": "events", | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"type": "serial", | ||
"pk": true | ||
}, | ||
{ | ||
"name": "name", | ||
"type": "varchar(255)", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
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,23 @@ | ||
{ | ||
"name": "35_alter_column_multiple", | ||
"operations": [ | ||
{ | ||
"alter_column": { | ||
"table": "events", | ||
"column": "name", | ||
"name": "event_name", | ||
"type": "text", | ||
"nullable": false, | ||
"unique": { | ||
"name": "events_event_name_unique" | ||
}, | ||
"check": { | ||
"name": "event_name_length", | ||
"constraint": "length(name) > 3" | ||
}, | ||
"up": "(SELECT CASE WHEN name IS NULL OR LENGTH(name) <= 3 THEN 'placeholder' ELSE name END)", | ||
"down": "name" | ||
} | ||
} | ||
] | ||
} |
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
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
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
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,18 @@ | ||
This is an invalid 'alter_column' migration. | ||
It specifies a table and column but no changes. | ||
|
||
-- alter_column.json -- | ||
{ | ||
"name": "migration_name", | ||
"operations": [ | ||
{ | ||
"alter_column": { | ||
"table": "reviews", | ||
"column": "review" | ||
} | ||
} | ||
] | ||
} | ||
|
||
-- valid -- | ||
false |
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
Oops, something went wrong.