@@ -35,10 +35,10 @@ Designed for Postgres 12 and later.
35 - [Remove enum](#remove-enum)
35 - [Remove enum](#remove-enum)
36 - [Custom](#custom)
36 - [Custom](#custom)
37- [Commands and options](#commands-and-options)
37- [Commands and options](#commands-and-options)
38− - [`reshape migrate`](#reshape-migrate)
38+ - [`reshape migration start`](#reshape-migration-start)
39− - [`reshape complete`](#reshape-complete)
39+ - [`reshape migration complete`](#reshape-migration-complete)
40− - [`reshape abort`](#reshape-abort)
40+ - [`reshape migration abort`](#reshape-migration-abort)
41− - [`reshape generate-schema-query`](#reshape-generate-schema-query)
41+ - [`reshape schema-query`](#reshape-schema-query)
42 - [Connection options](#connection-options)
42 - [Connection options](#connection-options)
43- [License](#license)
43- [License](#license)
@@ -47,11 +47,11 @@ Designed for Postgres 12 and later.
48Reshape works by creating views that encapsulate the underlying tables, which your application will interact with. During a migration, Reshape will automatically create a new set of views and set up triggers to translate inserts and updates between the old and new schema. This means that every deployment is a three-phase process:
48Reshape works by creating views that encapsulate the underlying tables, which your application will interact with. During a migration, Reshape will automatically create a new set of views and set up triggers to translate inserts and updates between the old and new schema. This means that every deployment is a three-phase process:
50−1. **Start migration** (`reshape migrate`): Sets up views and triggers to ensure both the new and old schema are usable at the same time.
50+1. **Start migration** (`reshape migration start`): Sets up views and triggers to ensure both the new and old schema are usable at the same time.
512. **Roll out application**: Your application can be gradually rolled out without downtime. The existing deployment will continue using the old schema whilst the new deployment uses the new schema.
512. **Roll out application**: Your application can be gradually rolled out without downtime. The existing deployment will continue using the old schema whilst the new deployment uses the new schema.
52−3. **Complete migration** (`reshape complete`): Removes the old schema and any intermediate data and triggers.
52+3. **Complete migration** (`reshape migration complete`): Removes the old schema and any intermediate data and triggers.
54−If the application deployment fails, you should run `reshape abort` which will roll back any changes made by `reshape migrate` without losing data.
54+If the application deployment fails, you should run `reshape migration abort` which will roll back any changes made by `reshape migration start` without losing data.
56## Getting started
56## Getting started
@@ -74,7 +74,7 @@ cargo install reshape
74Reshape is available as a Docker image on [Docker Hub](https://hub.docker.com/repository/docker/fabianlindfors/reshape).
74Reshape is available as a Docker image on [Docker Hub](https://hub.docker.com/repository/docker/fabianlindfors/reshape).
77−docker run -v $(pwd):/usr/share/app fabianlindfors/reshape reshape migrate
77+docker run -v $(pwd):/usr/share/app fabianlindfors/reshape reshape migration start
80### Creating your first migration
80### Creating your first migration
@@ -103,9 +103,9 @@ This is the equivalent of running `CREATE TABLE users (id INTEGER GENERATED ALWA
104### Preparing your application
104### Preparing your application
106−Reshape relies on your application using a specific schema. When establishing the connection to Postgres in your application, you need to run a query to select the most recent schema. This query can be generated using: `reshape generate-schema-query`.
106+Reshape relies on your application using a specific schema. When establishing the connection to Postgres in your application, you need to run a query to select the most recent schema. This query can be generated using: `reshape schema-query`.
108−To pass it along to your application, you can for example use an environment variable in your run script: `RESHAPE_SCHEMA_QUERY=$(reshape generate-schema-query)`. Then in your application:
108+To pass it along to your application, you can for example use an environment variable in your run script: `RESHAPE_SCHEMA_QUERY=$(reshape schema-query)`. Then in your application:
111# Example for Python
111# Example for Python
@@ -120,16 +120,16 @@ If your application is written in Rust, you might prefer the [Rust helper librar
120To create your new `users` table, run:
120To create your new `users` table, run:
123−reshape migrate --complete
123+reshape migration start --complete
126−We use the `--complete` flag to automatically complete the migration. During a production deployment, you should first run `reshape migrate` followed by `reshape complete` once your application has been fully rolled out.
126+We use the `--complete` flag to automatically complete the migration. During a production deployment, you should first run `reshape migration start` followed by `reshape migration complete` once your application has been fully rolled out.
128If nothing else is specified, Reshape will try to connect to a Postgres database running on `localhost` using `postgres` as both username and password. See [Connection options](#connection-options) for details on how to change the connection settings.
128If nothing else is specified, Reshape will try to connect to a Postgres database running on `localhost` using `postgres` as both username and password. See [Connection options](#connection-options) for details on how to change the connection settings.
130### Using during development
130### Using during development
132−When adding new migrations during development, we recommend running `reshape migrate` but skipping `reshape complete`. This way, the new migrations can be iterated on by updating the migration file and running `reshape abort` followed by `reshape migrate`.
132+When adding new migrations during development, we recommend running `reshape migration start` but skipping `reshape migration complete`. This way, the new migrations can be iterated on by updating the migration file and running `reshape migration abort` followed by `reshape migration start`.
134## Writing migrations
134## Writing migrations
@@ -538,9 +538,9 @@ The `custom` action lets you create a migration which runs custom SQL. It should
539There are three optional settings available which all accept SQL queries. All queries need to be idempotent, for example by using `IF NOT EXISTS` wherever available.
539There are three optional settings available which all accept SQL queries. All queries need to be idempotent, for example by using `IF NOT EXISTS` wherever available.
541−- `start`: run when a migration is started using `reshape migrate`
541+- `start`: run when a migration is started using `reshape migration start`
542−- `complete`: run when a migration is completed using `reshape complete`
542+- `complete`: run when a migration is completed using `reshape migration complete`
543−- `abort`: run when a migration is aborted using `reshape abort`
543+- `abort`: run when a migration is aborted using `reshape migration abort`
545*Example: enable PostGIS and pg_stat_statements extensions*
545*Example: enable PostGIS and pg_stat_statements extensions*
@@ -561,9 +561,9 @@ abort = """
562## Commands and options
562## Commands and options
564−### `reshape migrate`
564+### `reshape migration start`
566−Starts a new migration, applying all migrations under `migrations/` that haven't yet been applied. After the command has completed, both the old and new schema will be usable at the same time. When you have rolled out the new version of your application which uses the new schema, you should run `reshape complete`.
566+Starts a new migration, applying all migrations under `migrations/` that haven't yet been applied. After the command has completed, both the old and new schema will be usable at the same time. When you have rolled out the new version of your application which uses the new schema, you should run `reshape migration complete`.
568#### Options
568#### Options
@@ -574,15 +574,15 @@ Starts a new migration, applying all migrations under `migrations/` that haven't
574| `--complete`, `-c` | `false` | Automatically complete migration after applying it. |
574| `--complete`, `-c` | `false` | Automatically complete migration after applying it. |
575| `--dirs` | `migrations/` | Directories to search for migration files. Multiple directories can be specified using `--dirs dir1 dir2 dir3`. |
575| `--dirs` | `migrations/` | Directories to search for migration files. Multiple directories can be specified using `--dirs dir1 dir2 dir3`. |
577−### `reshape complete`
577+### `reshape migration complete`
579−Completes migrations previously started with `reshape complete`.
579+Completes migrations previously started with `reshape migration complete`.
581#### Options
581#### Options
583See [Connection options](#connection-options)
583See [Connection options](#connection-options)
585−### `reshape abort`
585+### `reshape migration abort`
587Aborts any migrations which haven't yet been completed.
587Aborts any migrations which haven't yet been completed.
@@ -590,10 +590,12 @@ Aborts any migrations which haven't yet been completed.
591See [Connection options](#connection-options)
591See [Connection options](#connection-options)
593−### `reshape generate-schema-query`
593+### `reshape schema-query`
595Generates the SQL query you need to run in your application before using the database. This command does not require a database connection. Instead it will generate the query based on the latest migration in the `migrations/` directory (or the directories specified by `--dirs`).
595Generates the SQL query you need to run in your application before using the database. This command does not require a database connection. Instead it will generate the query based on the latest migration in the `migrations/` directory (or the directories specified by `--dirs`).
597+If your application is written in Rust, we recommend using the [Rust helper library](https://github.com/fabianlindfors/reshape-helper/) instead.
597The query should look something like `SET search_path TO migration_1_initial_migration`.
599The query should look something like `SET search_path TO migration_1_initial_migration`.
599#### Options
601#### Options