-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert ADD COLUMN SQL into pgroll operations (#544)
Converts `ALTER TABLE ADD COLUMN` statements into `pgroll` operations. There are many combinations, at the moment we support the following: ```sql ALTER TABLE foo ADD COLUMN bar int ALTER TABLE foo ADD COLUMN bar int NOT NULL ALTER TABLE schema.foo ADD COLUMN bar int ALTER TABLE foo ADD COLUMN bar int DEFAULT 123 ALTER TABLE foo ADD COLUMN bar int DEFAULT 'baz' ALTER TABLE foo ADD COLUMN bar int DEFAULT null ALTER TABLE foo ADD COLUMN bar int NULL ALTER TABLE foo ADD COLUMN bar int UNIQUE ALTER TABLE foo ADD COLUMN bar int UNIQUE NOT DEFERRABLE ALTER TABLE foo ADD COLUMN bar int UNIQUE INITIALLY IMMEDIATE ALTER TABLE foo ADD COLUMN bar int PRIMARY KEY ALTER TABLE foo ADD COLUMN bar int CHECK (bar > 0) ALTER TABLE foo ADD COLUMN bar int CONSTRAINT check_bar CHECK (bar > 0) ALTER TABLE foo ADD COLUMN bar int CONSTRAINT fk_baz REFERENCES baz (bar) ALTER TABLE foo ADD COLUMN bar int CONSTRAINT fk_baz REFERENCES baz (bar) ON UPDATE NO ACTION ALTER TABLE foo ADD COLUMN bar int CONSTRAINT fk_baz REFERENCES baz (bar) ON DELETE NO ACTION ALTER TABLE foo ADD COLUMN bar int CONSTRAINT fk_baz REFERENCES baz (bar) ON DELETE RESTRICT ALTER TABLE foo ADD COLUMN bar int CONSTRAINT fk_baz REFERENCES baz (bar) ON DELETE SET NULL ALTER TABLE foo ADD COLUMN bar int CONSTRAINT fk_baz REFERENCES baz (bar) ON DELETE SET DEFAULT ALTER TABLE foo ADD COLUMN bar int CONSTRAINT fk_baz REFERENCES baz (bar) ON DELETE CASCADE ``` And fall back to raw SQL for these cases: ```sql ALTER TABLE foo ADD COLUMN bar int REFERENCES bar (c) ON UPDATE RESTRICT ALTER TABLE foo ADD COLUMN bar int REFERENCES bar (c) ON UPDATE CASCADE ALTER TABLE foo ADD COLUMN bar int REFERENCES bar (c) ON UPDATE SET NULL ALTER TABLE foo ADD COLUMN bar int REFERENCES bar (c) ON UPDATE SET DEFAULT ALTER TABLE foo ADD COLUMN IF NOT EXISTS bar int ALTER TABLE foo ADD COLUMN bar int UNIQUE DEFERRABLE ALTER TABLE foo ADD COLUMN bar int UNIQUE INITIALLY DEFERRED ALTER TABLE foo ADD COLUMN bar int GENERATED BY DEFAULT AS IDENTITY ALTER TABLE foo ADD COLUMN bar int GENERATED ALWAYS AS ( 123 ) STORED ``` Part of #504
- Loading branch information
Showing
3 changed files
with
365 additions
and
29 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
Oops, something went wrong.