|
| 1 | +defmodule AshPostgres.TestRepo.Migrations.AddCrossSchemaM2MTest do |
| 2 | + @moduledoc """ |
| 3 | + Migration for cross-schema many_to_many regression test. |
| 4 | +
|
| 5 | + Creates: |
| 6 | + - "interest" schema |
| 7 | + - interests table in "interest" schema |
| 8 | + - profile_interests table in "profiles" schema (join table) |
| 9 | +
|
| 10 | + This tests true cross-schema many_to_many between two custom schemas: |
| 11 | + - Interest in "interest" schema |
| 12 | + - Profile in "profiles" schema |
| 13 | + - ProfileInterest join table in "profiles" schema |
| 14 | + """ |
| 15 | + use Ecto.Migration |
| 16 | + |
| 17 | + def up do |
| 18 | + # Create the "interest" schema |
| 19 | + execute "CREATE SCHEMA IF NOT EXISTS interest" |
| 20 | + |
| 21 | + # Interest table in "interest" schema |
| 22 | + create table(:interests, primary_key: false, prefix: "interest") do |
| 23 | + add :id, :uuid, null: false, primary_key: true |
| 24 | + add :name, :text |
| 25 | + end |
| 26 | + |
| 27 | + # ProfileInterest join table in "profiles" schema |
| 28 | + create table(:profile_interests, primary_key: false, prefix: "profiles") do |
| 29 | + add :id, :uuid, null: false, primary_key: true |
| 30 | + |
| 31 | + add :profile_id, |
| 32 | + references(:profile, |
| 33 | + column: :id, |
| 34 | + name: "profile_interests_profile_id_fkey", |
| 35 | + type: :uuid, |
| 36 | + prefix: "profiles" |
| 37 | + ), |
| 38 | + null: false |
| 39 | + |
| 40 | + add :interest_id, |
| 41 | + references(:interests, |
| 42 | + column: :id, |
| 43 | + name: "profile_interests_interest_id_fkey", |
| 44 | + type: :uuid, |
| 45 | + prefix: "interest" |
| 46 | + ), |
| 47 | + null: false |
| 48 | + end |
| 49 | + |
| 50 | + create unique_index(:profile_interests, [:profile_id, :interest_id], prefix: "profiles") |
| 51 | + end |
| 52 | + |
| 53 | + def down do |
| 54 | + drop table(:profile_interests, prefix: "profiles") |
| 55 | + drop table(:interests, prefix: "interest") |
| 56 | + execute "DROP SCHEMA IF EXISTS interest" |
| 57 | + end |
| 58 | +end |
0 commit comments