ash_postgres v0.23.2 mix ash_postgres.generate_migrations View Source

Generates migrations, and stores a snapshot of your resources.

Options:

  • apis - a comma separated list of API modules, for which migrations will be generated
  • snapshot_path - a custom path to store the snapshots, defaults to "priv/resource_snapshots"
  • migration_path - a custom path to store the migrations, defaults to "priv". Migrations are stored in a folder for each repo, so priv/repo_name/migrations

Flags:

  • quiet - messages for file creations will not be printed
  • no_format - files that are created will not be formatted with the code formatter
  • dry_run - no files are created, instead the new migration is printed

Conflicts/Multiple Resources

The migration generator can support multiple schemas using the same table. It will raise on conflicts that it can't resolve, like the same field with different types. It will prompt to resolve conflicts that can be resolved with human input. For example, if you remove an attribute and add an attribute, it will ask you if you are renaming the column in question. If not, it will remove one column and add the other.

Additionally, it lowers things to the database where possible:

Defaults

There are three anonymous functions that will translate to database-specific defaults currently:

  • &Ash.uuid/0 - Only if uuid-ossp is in your c:AshPostgres.Repo.installed_extensions()
  • &Ecto.UUID.generate/0 - Only if uuid-ossp is in your c:AshPostgres.Repo.installed_extensions()
  • &DateTime.utc_now/0

Non-function default values will be dumped to their native type and inspected. This may not work for some types, and may require manual intervention/patches to the migration generator code.

Identities

Identities will cause the migration generator to generate unique constraints. If multiple resources target the same table, you will be asked to select the primary key, and any others will be added as unique constraints.

Link to this section Summary

Functions

Callback implementation for Mix.Task.run/1.

Link to this section Functions

Callback implementation for Mix.Task.run/1.