Add example of using up with create_table

This commit is contained in:
fabianlindfors 2023-11-22 22:22:41 +01:00
parent 6034dfebbd
commit 647ba2de5b

View File

@ -167,7 +167,7 @@ Every action has a `type`. The supported types are detailed below.
#### Create table
The `create_table` action will create a new table with the specified columns, indices and constraints.
The `create_table` action will create a new table with the specified columns, indices and constraints. You can optionally provide an `up` option to backfill values from an existing table.
_Example: create a `customers` table with a few columns and a primary key_
@ -226,6 +226,28 @@ primary_key = ["id"]
referenced_columns = ["id"]
```
_Example: create `profiles` table based on existing `users` table_
```toml
[[actions]]
type = "create_table"
name = "profiles"
primary_key = ["user_id"]
[[actions.columns]]
name = "user_id"
type = "INTEGER"
[[actions.columns]]
name = "user_email"
type = "TEXT"
# Backfill from `users` table and copy `users.email` to `user_email` column
[actions.up]
table = "users"
values = { user_id = "id", user_email = "email" }
```
#### Rename table
The `rename_table` action will change the name of an existing table.