OptimumCredo.Check.Warning.SchemaModuleInMigration (OptimumCredo v0.5.0)
View SourceBasics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of low and works with any version of Elixir.
Explanation
Migrations must not depend on application modules such as Ecto schemas. Those modules evolve (or disappear) after the migration is written, which breaks it when it runs against production data later.
Bad
alias MyApp.Accounts.User
def up, do: Repo.update_all(User, set: [active: true])Good
def up do
repo().update_all(from(u in "users"), set: [active: true])
endThis lexical check reports references under the app namespace (except Repo) in
files under priv/*/migrations. Aliases are resolved lexically.
Check-Specific Parameters
Use the following parameters to configure this check:
:app_namespace
Application namespace; inferred from the migration module when nil.
This parameter defaults to nil.
:allowed_modules
Modules under the namespace that migrations may reference.
This parameter defaults to [].
:ignore_files
Path suffixes or regexes for migrations to skip.
This parameter defaults to [].
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.