on main help sign in
Add example of using up with create_table
commit647ba2de5b4d721a57fad0bf6ede56d871b483a4 authorfabianlindfors <fabian@flapplabs.se> dateWed 22 Nov 2023, 22:22 (3 years ago) parent6034dfe
1 file changed+23−1
README.md+23−1
README.md+23−1
@@ -167,7 +167,7 @@ Every action has a `type`. The supported types are detailed below.
167167
168168#### Create table
169169
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.
171171
172172_Example: create a `customers` table with a few columns and a primary key_
173173
@@ -226,6 +226,28 @@ primary_key = ["id"]
226226 referenced_columns = ["id"]
227227```
228228
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+
229251#### Rename table
230252
231253The `rename_table` action will change the name of an existing table.