mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
feat: add create?
and drop?
callbacks to AshPostgres.Repo
(#143)
Co-authored-by: Zach Daniel <zach@zachdaniel.dev>
This commit is contained in:
parent
3ad3f5f5d6
commit
b66427e9bd
3 changed files with 16 additions and 3 deletions
|
@ -34,7 +34,9 @@ defmodule Mix.Tasks.AshPostgres.Create do
|
|||
def run(args) do
|
||||
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
||||
|
||||
repos = AshPostgres.MixHelpers.repos!(opts, args)
|
||||
repos =
|
||||
AshPostgres.MixHelpers.repos!(opts, args)
|
||||
|> Enum.filter(fn repo -> repo.create? end)
|
||||
|
||||
repo_args =
|
||||
Enum.flat_map(repos, fn repo ->
|
||||
|
|
|
@ -44,7 +44,9 @@ defmodule Mix.Tasks.AshPostgres.Drop do
|
|||
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
||||
opts = Keyword.merge(@default_opts, opts)
|
||||
|
||||
repos = AshPostgres.MixHelpers.repos!(opts, args)
|
||||
repos =
|
||||
AshPostgres.MixHelpers.repos!(opts, args)
|
||||
|> Enum.filter(fn repo -> repo.drop? end)
|
||||
|
||||
repo_args =
|
||||
Enum.flat_map(repos, fn repo ->
|
||||
|
|
11
lib/repo.ex
11
lib/repo.ex
|
@ -71,6 +71,10 @@ defmodule AshPostgres.Repo do
|
|||
|
||||
@doc "Allows overriding a given migration type for *all* fields, for example if you wanted to always use :timestamptz for :utc_datetime fields"
|
||||
@callback override_migration_type(atom) :: atom
|
||||
@doc "Should the repo should be created by `mix ash_postgres.create`?"
|
||||
@callback create?() :: boolean
|
||||
@doc "Should the repo should be dropped by `mix ash_postgres.drop`?"
|
||||
@callback drop?() :: boolean
|
||||
|
||||
defmacro __using__(opts) do
|
||||
quote bind_quoted: [opts: opts] do
|
||||
|
@ -91,6 +95,9 @@ defmodule AshPostgres.Repo do
|
|||
def migrations_path, do: nil
|
||||
def default_prefix, do: "public"
|
||||
def override_migration_type(type), do: type
|
||||
def create?, do: true
|
||||
def drop?, do: true
|
||||
|
||||
|
||||
def transaction!(fun) do
|
||||
case fun.() do
|
||||
|
@ -226,7 +233,9 @@ defmodule AshPostgres.Repo do
|
|||
all_tenants: 0,
|
||||
tenant_migrations_path: 0,
|
||||
default_prefix: 0,
|
||||
override_migration_type: 1
|
||||
override_migration_type: 1,
|
||||
create?: 0,
|
||||
drop?: 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue