Skip to content
Merged
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
58 changes: 58 additions & 0 deletions test/migration_generator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,63 @@ defmodule AshPostgres.MigrationGeneratorTest do
end
end

describe "custom_indexes with `concurrently: true` and an explicit name" do
test "it gives each generated migration a unique name and module", %{
snapshot_path: snapshot_path,
migration_path: migration_path
} do
:ok

defposts do
postgres do
custom_indexes do
index([:title], concurrently: true)
end
end

attributes do
uuid_primary_key(:id)
attribute(:title, :string, public?: true)
end
end

defdomain([Post])

AshPostgres.MigrationGenerator.generate(Domain,
snapshot_path: snapshot_path,
migration_path: migration_path,
quiet: true,
format: false,
name: "repro_case"
)

assert [first_migration, second_migration] =
Enum.sort(Path.wildcard("#{migration_path}/**/*.exs"))
|> Enum.reject(&String.contains?(&1, "extensions"))

first_contents = File.read!(first_migration)
second_contents = File.read!(second_migration)

first_name =
first_migration
|> Path.basename(".exs")
|> then(&Regex.replace(~r/^\d+_/, &1, ""))

second_name =
second_migration
|> Path.basename(".exs")
|> then(&Regex.replace(~r/^\d+_/, &1, ""))

assert [_, first_module] = Regex.run(~r/^defmodule\s+(.+)\s+do$/m, first_contents)
assert [_, second_module] = Regex.run(~r/^defmodule\s+(.+)\s+do$/m, second_contents)

# Split migrations still need unique derived names and modules, even
# when the generation run uses an explicit `name`.
assert first_name != second_name
assert first_module != second_module
end
end

describe "unique identities with `concurrent_indexes: true`" do
test "dependent foreign keys are generated only after the unique index migration", %{
snapshot_path: snapshot_path,
Expand Down Expand Up @@ -588,6 +645,7 @@ defmodule AshPostgres.MigrationGeneratorTest do
# Step 2: concurrent unique index (in a @disable_ddl_transaction migration)
assert index_contents =~ ~S|@disable_ddl_transaction true|
assert index_contents =~ ~S|@disable_migration_lock true|

assert index_contents =~
~S|create unique_index(:concurrent_unique_targets, [:code], name: "concurrent_unique_targets_uniq_code_index", concurrently: true)|

Expand Down
Loading