diff --git a/elixir/apps/domain/priv/repo/manual_migrations/20250806045735_add_gateway_cascade_on_delete_constraint.exs b/elixir/apps/domain/priv/repo/manual_migrations/20250806045735_add_gateway_cascade_on_delete_constraint.exs new file mode 100644 index 000000000..210e8bdc5 --- /dev/null +++ b/elixir/apps/domain/priv/repo/manual_migrations/20250806045735_add_gateway_cascade_on_delete_constraint.exs @@ -0,0 +1,33 @@ +defmodule Domain.Repo.Migrations.AddGatewayCascadeOnDeleteConstraint do + use Ecto.Migration + + def up do + execute(""" + ALTER TABLE gateways + DROP CONSTRAINT IF EXISTS gateways_group_id_fkey + """) + + execute(""" + ALTER TABLE gateways + ADD CONSTRAINT gateways_group_id_fkey + FOREIGN KEY (group_id) + REFERENCES gateway_groups(id) + ON DELETE CASCADE + """) + end + + def down do + execute(""" + ALTER TABLE gateways + DROP CONSTRAINT IF EXISTS gateways_group_id_fkey + """) + + execute(""" + ALTER TABLE gateways + ADD CONSTRAINT gateways_group_id_fkey + FOREIGN KEY (group_id) + REFERENCES gateway_groups(id) + ON DELETE NO ACTION + """) + end +end diff --git a/elixir/apps/domain/priv/repo/manual_migrations/20250806050048_add_auth_identity_cascade_on_delete_constraint.exs b/elixir/apps/domain/priv/repo/manual_migrations/20250806050048_add_auth_identity_cascade_on_delete_constraint.exs new file mode 100644 index 000000000..f0aa520c1 --- /dev/null +++ b/elixir/apps/domain/priv/repo/manual_migrations/20250806050048_add_auth_identity_cascade_on_delete_constraint.exs @@ -0,0 +1,59 @@ +defmodule Domain.Repo.Migrations.AddAuthIdentityCascadeOnDeleteConstraint do + use Ecto.Migration + + def up do + execute(""" + ALTER TABLE auth_identities + DROP CONSTRAINT IF EXISTS auth_identities_provider_id_fkey + """) + + execute(""" + ALTER TABLE auth_identities + DROP CONSTRAINT IF EXISTS auth_identities_actor_id_fkey + """) + + execute(""" + ALTER TABLE auth_identities + ADD CONSTRAINT auth_identities_provider_id_fkey + FOREIGN KEY (provider_id) + REFERENCES auth_providers(id) + ON DELETE CASCADE + """) + + execute(""" + ALTER TABLE auth_identities + ADD CONSTRAINT auth_identities_actor_id_fkey + FOREIGN KEY (actor_id) + REFERENCES actors(id) + ON DELETE CASCADE + """) + end + + def down do + execute(""" + ALTER TABLE auth_identities + DROP CONSTRAINT IF EXISTS auth_identities_provider_id_fkey + """) + + execute(""" + ALTER TABLE auth_identities + DROP CONSTRAINT IF EXISTS auth_identities_actor_id_fkey + """) + + execute(""" + ALTER TABLE auth_identities + ADD CONSTRAINT auth_identities_provider_id_fkey + FOREIGN KEY (provider_id) + REFERENCES auth_providers(id) + ON DELETE NO ACTION + """) + + execute(""" + ALTER TABLE auth_identities + ADD CONSTRAINT auth_identities_actor_id_fkey + FOREIGN KEY (actor_id) + REFERENCES actors(id) + ON DELETE NO ACTION + """) + end +end diff --git a/elixir/apps/domain/priv/repo/manual_migrations/20250806050140_update_client_fk_constraints.exs b/elixir/apps/domain/priv/repo/manual_migrations/20250806050140_update_client_fk_constraints.exs new file mode 100644 index 000000000..56c1108b1 --- /dev/null +++ b/elixir/apps/domain/priv/repo/manual_migrations/20250806050140_update_client_fk_constraints.exs @@ -0,0 +1,157 @@ +defmodule Domain.Repo.Migrations.UpdateClientFkConstraints do + use Ecto.Migration + + def up do + # Rename Identity FK and add ON DELETE CASCADE + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS devices_identity_id_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT clients_identity_id_fkey + FOREIGN KEY (identity_id) + REFERENCES auth_identities(id) + ON DELETE CASCADE + """) + + # Rename Actor FK and add ON DELETE CASCADE + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS devices_actor_id_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT clients_actor_id_fkey + FOREIGN KEY (actor_id) + REFERENCES actors(id) + ON DELETE CASCADE + """) + + # Rename Account FK + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS devices_account_id_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT clients_account_id_fkey + FOREIGN KEY (account_id) + REFERENCES accounts(id) + ON DELETE CASCADE + """) + + # Rename IPv4 FK + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS devices_ipv4_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT clients_ipv4_fkey + FOREIGN KEY (ipv4, account_id) + REFERENCES network_addresses(address, account_id) + ON DELETE NO ACTION + """) + + # Rename IPv6 FK + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS devices_ipv6_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT clients_ipv6_fkey + FOREIGN KEY (ipv6, account_id) + REFERENCES network_addresses(address, account_id) + ON DELETE NO ACTION + """) + + # Rename Primary Key Index + execute(""" + ALTER INDEX devices_pkey RENAME TO clients_pkey; + """) + end + + def down do + # Undo rename Identity FK and add ON DELETE CASCADE + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS clients_identity_id_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT devices_identity_id_fkey + FOREIGN KEY (identity_id) + REFERENCES auth_identities(id) + ON DELETE NO ACTION + """) + + # Undo rename Actor FK and add ON DELETE CASCADE + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS clients_actor_id_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT devices_actor_id_fkey + FOREIGN KEY (actor_id) + REFERENCES actors(id) + ON DELETE NO ACTION + """) + + # Undo rename Account FK + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS clients_account_id_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT devices_account_id_fkey + FOREIGN KEY (account_id) + REFERENCES accounts(id) + ON DELETE NO ACTION + """) + + # Undo rename IPv4 FK + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS clients_ipv4_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT devices_ipv4_fkey + FOREIGN KEY (ipv4, account_id) + REFERENCES network_addresses(address, account_id) + ON DELETE NO ACTION + """) + + # Undo rename IPv6 FK + execute(""" + ALTER TABLE clients + DROP CONSTRAINT IF EXISTS clients_ipv6_fkey + """) + + execute(""" + ALTER TABLE clients + ADD CONSTRAINT devices_ipv6_fkey + FOREIGN KEY (ipv6, account_id) + REFERENCES network_addresses(address, account_id) + ON DELETE NO ACTION + """) + + # Undo rename Primary Key Index + execute(""" + ALTER INDEX clients_pkey RENAME TO devices_pkey; + """) + end +end diff --git a/elixir/apps/domain/priv/repo/manual_migrations/20250806050230_update_relay_fk_constraint.exs b/elixir/apps/domain/priv/repo/manual_migrations/20250806050230_update_relay_fk_constraint.exs new file mode 100644 index 000000000..20aaefe32 --- /dev/null +++ b/elixir/apps/domain/priv/repo/manual_migrations/20250806050230_update_relay_fk_constraint.exs @@ -0,0 +1,33 @@ +defmodule Domain.Repo.Migrations.UpdateRelayFkConstraint do + use Ecto.Migration + + def up do + execute(""" + ALTER TABLE relays + DROP CONSTRAINT IF EXISTS relays_group_id_fkey + """) + + execute(""" + ALTER TABLE relays + ADD CONSTRAINT relays_group_id_fkey + FOREIGN KEY (group_id) + REFERENCES relay_groups(id) + ON DELETE CASCADE + """) + end + + def down do + execute(""" + ALTER TABLE relays + DROP CONSTRAINT IF EXISTS relays_group_id_fkey + """) + + execute(""" + ALTER TABLE relays + ADD CONSTRAINT relays_group_id_fkey + FOREIGN KEY (group_id) + REFERENCES relay_groups(id) + ON DELETE NO ACTION + """) + end +end diff --git a/elixir/apps/domain/priv/repo/manual_migrations/20250806050303_allow_null_last_used_token_id_on_clients.exs b/elixir/apps/domain/priv/repo/manual_migrations/20250806050303_allow_null_last_used_token_id_on_clients.exs new file mode 100644 index 000000000..7a04d3262 --- /dev/null +++ b/elixir/apps/domain/priv/repo/manual_migrations/20250806050303_allow_null_last_used_token_id_on_clients.exs @@ -0,0 +1,15 @@ +defmodule Domain.Repo.Migrations.AllowNullLastUsedTokenIdOnClients do + use Ecto.Migration + + def up do + alter table(:clients) do + modify(:last_used_token_id, :uuid, null: true) + end + end + + def down do + alter table(:clients) do + modify(:last_used_token_id, :uuid, null: false) + end + end +end