on main help sign in
Add example of using up with create_table
647ba2dfabianlindfors
README.md+23−1
@@ -167,7 +167,7 @@ Every action has a `type`. The supported types are detailed below.
167
167
168#### Create table
168#### Create table
169
169
170−The `create_table` action will create a new table with the specified columns, indices and constraints.
170+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.
171
171
172_Example: create a `customers` table with a few columns and a primary key_
172_Example: create a `customers` table with a few columns and a primary key_
173
173
@@ -226,6 +226,28 @@ primary_key = ["id"]
226 referenced_columns = ["id"]
226 referenced_columns = ["id"]
227```
227```
228
228
229+_Example: create `profiles` table based on existing `users` table_
230+
231+```toml
232+[[actions]]
233+type = "create_table"
234+name = "profiles"
235+primary_key = ["user_id"]
236+
237+ [[actions.columns]]
238+ name = "user_id"
239+ type = "INTEGER"
240+
241+ [[actions.columns]]
242+ name = "user_email"
243+ type = "TEXT"
244+
245+ # Backfill from `users` table and copy `users.email` to `user_email` column
246+ [actions.up]
247+ table = "users"
248+ values = { user_id = "id", user_email = "email" }
249+```
250+
229#### Rename table
251#### Rename table
230
252
231The `rename_table` action will change the name of an existing table.
253The `rename_table` action will change the name of an existing table.