You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/topics/development/migrations-and-tasks.md
+23-4Lines changed: 23 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,30 @@ Ash comes with its own tasks, and AshSqlite exposes lower level tasks that you c
6
6
7
7
## Basic Workflow
8
8
9
-
- Make resource changes
10
-
- Run `mix ash.codegen --name add_a_combobulator` to generate migrations and resource snapshots
11
-
- Run `mix ash.migrate` to run those migrations
9
+
### Development Workflow (Recommended)
12
10
13
-
For more information on generating migrations, run `mix help ash_sqlite.generate_migrations` (the underlying task that is called by `mix ash.migrate`)
11
+
For development iterations, use the dev workflow to avoid naming migrations prematurely:
12
+
13
+
1. Make resource changes
14
+
2. Run `mix ash.codegen --dev` to generate dev migrations
15
+
3. Review the migrations and run `mix ash.migrate` to run them
16
+
4. Continue making changes and running `mix ash.codegen --dev` as needed
17
+
5. When your feature is complete, run `mix ash.codegen add_feature_name` to generate final named migrations (this will remove dev migrations and squash them)
18
+
6. Review the migrations and run `mix ash.migrate` to run them
19
+
20
+
### Traditional Migration Generation
21
+
22
+
For single-step changes or when you know the final feature name:
23
+
24
+
1. Make resource changes
25
+
2. Run `mix ash.codegen --name add_a_combobulator` to generate migrations and resource snapshots
26
+
3. Run `mix ash.migrate` to run those migrations
27
+
28
+
> **Tip**: The dev workflow (`--dev` flag) is preferred during development as it allows you to iterate without thinking of migration names and provides better development ergonomics.
29
+
30
+
> **Warning**: Always review migrations before applying them to ensure they are correct and safe.
31
+
32
+
For more information on generating migrations, run `mix help ash_sqlite.generate_migrations` (the underlying task that is called by `mix ash.codegen`)
> **Development Tip**: For iterative development, you can use `mix ash_sqlite.generate_migrations --dev` to create dev migrations without needing to name them immediately. When you're ready to finalize your changes, run the command with a proper name to consolidate all dev migrations into a single, well-named migration.
174
+
173
175
If you are unfamiliar with database migrations, it is a good idea to get a rough idea of what they are and how they work. See the links at the bottom of this guide for more. A rough overview of how migrations work is that each time you need to make changes to your database, they are saved as small, reproducible scripts that can be applied in order. This is necessary both for clean deploys as well as working with multiple developers making changes to the structure of a single database.
174
176
175
177
Typically, you need to write these by hand. AshSqlite, however, will store snapshots each time you run the command to generate migrations and will figure out what migrations need to be created.
0 commit comments