Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop quoting column default values (#200)
When adding a column to a table (either at creation time or afterwards with an alter table migration), any default value for the column is automatically single quoted. This makes it easier to define migrations, as the user does not have to remember to add the single quotes in the migration. For example in this migration: ```json { "name": "28_different_defaults", "operations": [ { "create_table": { "name": "items", "columns": [ { "name": "id", "type": "serial", "pk": true }, { "name": "name", "type": "varchar(255)", "default": "unnamed" } ] } } ] } ``` the default value for the `name` column (`unnamed`) does not need to be quoted as `pgroll` does that automatically. However, this automatic quoting causes a problem when assigning a default value of `now()` to a timestamp column: ```json { "name": "28_different_defaults", "operations": [ { "create_table": { "name": "items", "columns": [ { "name": "id", "type": "serial", "pk": true }, { "name": "created_at", "type": "timestamptz", "default": "now()" } ] } } ] } ``` when run, this will result in a `created_at` column with a default value of the time at which the migration was run, eg: ``` | created_at | timestamp with time zone | not null default '2023-11-06 08:37:01.203691+00'::timestamp with time zone | ``` rather than the desired default: ``` | created_at | timestamp with time zone | not null default now() | ``` This PR removes the automatic quoting of default values so that `now()`, `CURRENT_TIMESTAMP` etc can be used correctly as column defaults. This pushes some complexity onto users who now have to single-quote those default values that require it.
- Loading branch information