Commit Graph

7 Commits

Author SHA1 Message Date
Andrew Farries
b4efd8ad50
Support up SQL on add column operations (#34)
Add a new field `Up` to **add column** migrations:

```json
{
  "name": "03_add_column_to_products",
  "operations": [
    {
      "add_column": {
        "table": "products",
        "up": "UPPER(name)",
        "column": {
          "name": "description",
          "type": "varchar(255)",
          "nullable": true
        }
      }
    }
  ]
}
```

The SQL specified by the `up` field will be run whenever an row is
inserted into the underlying table when the session's `search_path` is
not set to the latest version of the schema.

The `up` SQL snippet can refer to existing columns in the table by name
(as in the the above example, where the `description` field is set to
`UPPER(name)`).
2023-07-20 06:37:03 +01:00
Andrew Farries
dce42da85a
Support adding columns with UNIQUE, NOT NULL and DEFAULT constraints (#30)
Allow the **add column** operation to add columns with `NOT NULL`,
`UNIQUE` and `DEFAULT` constraints by re-using the SQL generation code
that adds columns to tables.
2023-07-13 08:38:43 +01:00
Carlos Pérez-Aradros Herce
28187f3cb3
Rename table op (#23)
Add rename table operation.

I worked a bit toward table-based testing with reusable code in
`op_common_test.go`

---------

Co-authored-by: Andrew Farries <andyrb@gmail.com>
2023-07-11 08:01:05 +00:00
Andrew Farries
6430f05353
Implement 'add column' migrations for nullable columns (#20)
Add support for **add column** migrations in the simple case where the
new column is nullable.

Add tests for the new operation, covering start, rollback and complete,
in the cases where the add column operation is running against a table
created in an earlier migration and in the case where the the column is
added to a table created in an operation earlier in the migration.

Reshape [offers](https://github.com/fabianlindfors/reshape#add-column)
an `up` option when adding a column, to allow users to backfill the new
column. This PR does not implement this feature.
2023-07-07 11:23:19 +01:00
Andrew Farries
1a7eb3271a
Format the examples with jq (#21) 2023-07-06 15:26:29 +01:00
Carlos Pérez-Aradros Herce
a8c4fddd14
Add migrations state handling (#7)
This migrations introduces state handling by creating a dedicated
`pgroll` schema (name configurable). We will store migrations there, as
well as their state. So we keep some useful information, ie the
migration definition (so we don't need it for the `complete` state).

Schema includes the proper constraints to guarantee that:
* Only a migration is active at a time
* Migration history is linear (all migrations have a unique parent,
except the first one which is NULL)
* We now the current migration at all times

Some helper functions are included:

* `is_active_migration_period()` will return true if there is an active
migration.
* `latest_version()` will return the name of the latest version of the
schema.
2023-06-28 11:10:03 +02:00
Carlos Pérez-Aradros Herce
bdaf08f54c Initial commit
Basic skeleton and simple op
2023-06-22 17:30:40 +02:00