@@ -34,6 +34,7 @@ Designed for Postgres 12 and later.
34 - [Create enum](#create-enum)
34 - [Create enum](#create-enum)
35 - [Remove enum](#remove-enum)
35 - [Remove enum](#remove-enum)
36 - [Custom](#custom)
36 - [Custom](#custom)
37+ - [Complex changes across tables](#complex-changes-across-tables)
37- [Commands and options](#commands-and-options)
38- [Commands and options](#commands-and-options)
38 - [`reshape migration start`](#reshape-migration-start)
39 - [`reshape migration start`](#reshape-migration-start)
39 - [`reshape migration complete`](#reshape-migration-complete)
40 - [`reshape migration complete`](#reshape-migration-complete)
@@ -284,7 +285,7 @@ foreign_key = "items_user_id_fkey"
285#### Add column
286#### Add column
287−The `add_column` action will add a new column to an existing table. You can optionally provide an `up` setting. This should be an SQL expression which will be run for all existing rows to backfill the new column.
288+The `add_column` action will add a new column to an existing table. You can optionally provide an `up` setting. This should be an SQL expression which will be run for all existing rows to backfill the new column. `up` may also reference another table to perform cross-table migrations (see ["Complex changes across tables"](#complex-changes-across-tables)).
289_Example: add a new column `reference` to table `products`_
290_Example: add a new column `reference` to table `products`_
@@ -448,7 +449,7 @@ column = "created_at"
449#### Remove column
450#### Remove column
451−The `remove_column` action will remove an existing column from a table. You can optionally provide a `down` setting. This should be an SQL expression which will be used to determine values for the old schema when inserting or updating rows using the new schema. The `down` setting must be provided when the removed column is `NOT NULL` or doesn't have a default value.
452+The `remove_column` action will remove an existing column from a table. You can optionally provide a `down` setting. This should be an SQL expression which will be used to determine values for the old schema when inserting or updating rows using the new schema. `down` may also reference another table to perform cross-table migrations (see ["Complex changes across tables"](#complex-changes-across-tables)) . The `down` setting must be provided when the removed column is `NOT NULL` or doesn't have a default value.
453Any indices that cover the column will be removed.
454Any indices that cover the column will be removed.
@@ -596,6 +597,40 @@ abort = """
600+### Complex changes across tables
602+The `up` and `down` options available for many actions can also perform more complex changes that span tables.
604+_Example: move `email` column from `users` to `profiles` table_
608+type = "remove_column"
612+ # When `profiles` is changed in the new schema, we write the email address back to the removed column
616+ where = "id = user_id"
627+ # When `users` is updated in the old schema, we write the email value to `profiles`
631+ where = "user_id = id"
599## Commands and options
634## Commands and options
601### `reshape migration start`
636### `reshape migration start`