From 6b0c280ff01aa6240f9118b0d9d172fe725cee93 Mon Sep 17 00:00:00 2001 From: Matt Beanland Date: Mon, 24 Aug 2026 14:19:10 +0930 Subject: [PATCH] fix: order temporal migration operations under the toposort --- lib/migration_generator/operation_deps.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/migration_generator/operation_deps.ex b/lib/migration_generator/operation_deps.ex index 6078174b..9a92b2f3 100644 --- a/lib/migration_generator/operation_deps.ex +++ b/lib/migration_generator/operation_deps.ex @@ -525,6 +525,17 @@ defmodule AshPostgres.MigrationGenerator.OperationDeps do [{:table_structure_ready, key(own_table, schema)}] ++ Enum.map(after_tables, &{:table_structure_ready, key(&1, schema)}) + %Operation.AddPrimaryKey{table: table, schema: schema} -> + # Every key column must exist first; on a temporal resource that includes the period. + [{:table_ready, key(table, schema)}, {:table_columns_settled, key(table, schema)}] + + %Operation.AddTemporalForeignKey{} = op -> + # References the destination's temporal primary key, so both tables must be complete. + [ + {:table_structure_ready, key(op.table, op.schema)}, + {:table_structure_ready, key(op.destination_table, op.destination_schema)} + ] + _ -> [] end