Skip to content

feat: --dev flag for codegen #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ if Mix.env() == :test do
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox

config :ash_postgres, AshPostgres.DevTestRepo,
username: "postgres",
password: "postgres",
database: "ash_postgres_dev_test",
hostname: "localhost",
migration_primary_key: [name: :id, type: :binary_id],
pool: Ecto.Adapters.SQL.Sandbox

# sobelow_skip ["Config.Secrets"]
config :ash_postgres, AshPostgres.TestRepo, password: "postgres"

Expand All @@ -54,7 +62,7 @@ if Mix.env() == :test do
migration_primary_key: [name: :id, type: :binary_id]

config :ash_postgres,
ecto_repos: [AshPostgres.TestRepo, AshPostgres.TestNoSandboxRepo],
ecto_repos: [AshPostgres.TestRepo, AshPostgres.DevTestRepo, AshPostgres.TestNoSandboxRepo],
ash_domains: [
AshPostgres.Test.Domain,
AshPostgres.MultitenancyTest.Domain,
Expand Down
9 changes: 8 additions & 1 deletion documentation/topics/development/migrations-and-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ Ash comes with its own tasks, and AshPostgres exposes lower level tasks that you
## Basic Workflow

- Make resource changes
- Run `mix ash.codegen --name add_a_combobulator` to generate migrations and resource snapshots
- Run `mix ash.codegen --dev` to generate a migration tagged as a `dev` migration, which will later be squashed and does not require a name.
- Run `mix ash.migrate` to run the migrations.
- Make some more resource changes.
- Once you're all done, run `mix ash.codegen add_a_combobulator`, using a good name for your changes to generate migrations and resource snapshots. This will **rollback** the dev migrations, and squash them into a the new named migration (or sometimes migrations).
- Run `mix ash.migrate` to run those migrations

The `--dev` workflow enables you to avoid having to think of a name for migrations while developing, and also enables some
upcoming workflows that will detect when code generation needs to be run on page load and will show you a button to generate
dev migrations and run them.

For more information on generating migrations, run `mix help ash_postgres.generate_migrations` (the underlying task that is called by `mix ash.migrate`)

> ### list_tenants/0 {: .info}
Expand Down
Loading
Loading