pgroll/examples
Andrew Farries edc78acf0a
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.
2023-11-06 11:56:03 +00:00
..
01_create_tables.json Format the examples with jq (#21) 2023-07-06 15:26:29 +01:00
02_create_another_table.json Format the examples with jq (#21) 2023-07-06 15:26:29 +01:00
03_add_column.json Implement Start for adding columns with NOT NULL and no DEFAULT (#37) 2023-07-21 07:47:42 +01:00
04_rename_table.json Rename table op (#23) 2023-07-11 08:01:05 +00:00
05_sql.json Add raw SQL operation (#43) 2023-08-30 11:50:59 +02:00
06_add_column_to_sql_table.json Add raw SQL operation (#43) 2023-08-30 11:50:59 +02:00
07_drop_table.json Implement the drop table operation (#45) 2023-08-17 06:43:42 +01:00
08_create_fruits_table.json Implement 'drop column' migrations (#48) 2023-08-17 07:37:48 +01:00
09_drop_column.json Implement 'drop column' migrations (#48) 2023-08-17 07:37:48 +01:00
10_create_index.json Make index name mandatory on create index operation (#59) 2023-08-18 08:55:25 +01:00
11_drop_index.json Make index name mandatory on create index operation (#59) 2023-08-18 08:55:25 +01:00
12_create_employees_table.json Implement 'rename column' migrations (#52) 2023-08-18 06:49:27 +01:00
13_rename_column.json Add 'alter column' operation to combine some existing operations (#91) 2023-09-12 12:10:13 +01:00
14_add_reviews_table.json Implement the set column NOT NULL operation (#63) 2023-08-29 14:53:29 +01:00
15_set_column_unique.json Make set_unique operations respect the contract for old schema versions (#118) 2023-09-22 08:52:15 +00:00
16_set_nullable.json fix(#132): consistent naming for nullable columns in migration files (#181) 2023-10-11 13:14:34 +01:00
17_add_rating_column.json Implement the 'change column type' operation (#74) 2023-09-01 13:37:43 +01:00
18_change_column_type.json Add 'alter column' operation to combine some existing operations (#91) 2023-09-12 12:10:13 +01:00
19_create_orders_table.json Make naming FOREIGN KEY constraints mandatory (#100) 2023-09-15 11:39:17 +01:00
20_create_posts_table.json Add support for adding a foreign key constraint to an existing column (#82) 2023-09-11 06:12:59 +01:00
21_add_foreign_key_constraint.json Make naming FOREIGN KEY constraints mandatory (#100) 2023-09-15 11:39:17 +01:00
22_add_check_constraint.json Move constraint name and expression into a new CheckConstraint struct (#107) 2023-09-19 10:49:40 +01:00
23_drop_check_constraint.json Implement the drop_constraint operation (#103) 2023-09-19 05:32:53 +01:00
24_drop_foreign_key_constraint.json Implement the drop_constraint operation (#103) 2023-09-19 05:32:53 +01:00
25_add_table_with_check_constraint.json Allow columns with CHECK constraints in create table operations (#108) 2023-09-19 10:00:55 +00:00
26_add_column_with_check_constraint.json Allow columns with CHECK constraints on add column operations (#109) 2023-09-20 09:52:22 +01:00
27_drop_unique_constraint.json Add a testcase for dropping unique constraints (#117) 2023-09-21 08:27:20 +00:00
28_different_defaults.json Stop quoting column default values (#200) 2023-11-06 11:56:03 +00:00