PostgreSQL zero-downtime migrations made easy
Go to file
Andrew Farries f764993640
Implement 'drop column' migrations (#48)
Implement the **drop column**  migration operation.

A migration to drop a column looks like this:

```json
{
  "name": "09_drop_column",
  "operations": [
    {
      "drop_column": {
        "table": "fruits",
        "column": "price",
        "down": "0"
      }
    }
  ]
}
```

The migration takes the name of the table and column that should be
dropped along with (optionally) some `down` SQL to run to populate the
field in the underlying table when insertions are done via the new
schema version while the migration is in progress.

* On `Start`, the relevant view in the new version schema is created
without the dropped column. The column is not deleted from the
underlying table.
* If `down` SQL is specified, a trigger is created on the underlying
table to populate the column to be removed when inserts are made from
the new schema version.
* On `Rollback` any triggers on the underlying table are removed.
* On `Complete` the old version of the schema is removed and the column
is removed from the underlying table. Any triggers are also removed.
2023-08-17 07:37:48 +01:00
.github Pin Go to 1.20.5 to work around testcontainers/Go breakage (#40) 2023-07-21 07:44:35 +01:00
.vscode Add linter to tests (#9) 2023-06-27 16:33:50 +01:00
cmd Add a --complete flag to to the start command (#33) 2023-07-18 09:08:49 +01:00
examples Implement 'drop column' migrations (#48) 2023-08-17 07:37:48 +01:00
pkg Implement 'drop column' migrations (#48) 2023-08-17 07:37:48 +01:00
.golangci.yml Add linter to tests (#9) 2023-06-27 16:33:50 +01:00
docker-compose.yml Initial commit 2023-06-22 17:30:40 +02:00
go.mod Rename table op (#23) 2023-07-11 08:01:05 +00:00
go.sum Rename table op (#23) 2023-07-11 08:01:05 +00:00
main.go Add linter to tests (#9) 2023-06-27 16:33:50 +01:00
README.md Add migrations state handling (#7) 2023-06-28 11:10:03 +02:00

pg-roll

⚠️ Under development ⚠️

PostgreSQL zero-downtime migrations made easy.

Getting started (development)

  • Bring a development PostgreSQL up:

    docker compose up
    
  • Initialize pg-roll (first time only):

    go run . init
    
  • Start a migration:

    go run . start examples/01_create_tables.json
    
  • Inspect the results:

    psql postgres://localhost -U postgres
    
    \d+ public.*
    \d+ 01_create_tables.*
    
  • (Optional) Rollback the migration (undo):

    go run . rollback
    
  • Complete the migration:

    go run . complete