Repository navigation
feat(schema): apply ordered CREATE, ALTER, and DROP TABLE statements - #45
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Schema files are now applied in order to one schema model, so a migration directory that creates tables and later alters or drops them loads as the schema the application actually has, instead of failing on the first statement other than
CREATE TABLE.Changes
CREATE TABLEandDROP TABLE(one or several names) update the model.CREATE TABLE IF NOT EXISTSdoes nothing for an existing table, andDROP TABLE IF EXISTSdoes nothing for a missing one.ALTER TABLEsupportsADD COLUMN,DROP COLUMN,RENAME COLUMN,RENAME TO,ALTER COLUMN ... TYPE, andALTER COLUMN ... SET/DROP NOT NULL, applied in written order, withADD COLUMN IF NOT EXISTS,DROP COLUMN IF EXISTS, andALTER TABLE IF EXISTS.CREATE TABLEcolumns. Renamed and retyped columns keep their position, and a retyped column keeps its nullability. Recorded primary-key and unique constraints follow a renamed column and are removed with a dropped one.Table not found in schema: <name>,Column not found in table <table>: <column>,Table already exists in schema: <name>,Column already exists in table <table>: <column>. A repeatedCREATE TABLE, which previously loaded silently, now fails.ALTER TABLEaction, includingSET/DROP DEFAULT, constraint changes,SET STATISTICS/STORAGE/COMPRESSION, and identity or generated-column changes, fails withUnsupported schema statement: Alter.DROPof anything other than a table is still rejected.Scope and non-goals
ALTER COLUMN ... SET DATA TYPEandALTER TABLE ONLYare not supported, and aUSINGclause is not evaluated beyond reading the new type.