1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2
3 export class Migration20240529080336 extends Migration {
4 async up(): Promise<void> {
5 this.addSql(
6 'create table if not exists "provider_identity" ("id" text not null, "entity_id" text not null, "provider" text not null, "auth_identity_id" text not null, "user_metadata" jsonb null, "provider_metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), constraint "provider_identity_pkey" primary key ("id"));'
7 )
8 this.addSql(
9 'CREATE INDEX IF NOT EXISTS "IDX_provider_identity_auth_identity_id" ON "provider_identity" (auth_identity_id);'
10 )
11 this.addSql(
12 'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_provider_identity_provider_entity_id" ON "provider_identity" (entity_id, provider);'
13 )
14
15 this.addSql(
16 'alter table if exists "provider_identity" add constraint "provider_identity_auth_identity_id_foreign" foreign key ("auth_identity_id") references "auth_identity" ("id") on update cascade on delete cascade;'
17 )
18
19 this.addSql(
20 'alter table if exists "auth_identity" add column if not exists "created_at" timestamptz not null default now(), add column "updated_at" timestamptz not null default now();'
21 )
22
23 this.addSql(
24 'alter table if exists "auth_identity" drop constraint if exists "IDX_auth_identity_provider_entity_id";'
25 )
26 this.addSql(
27 'alter table if exists "auth_identity" drop column if exists "entity_id";'
28 )
29 this.addSql(
30 'alter table if exists "auth_identity" drop column if exists "provider";'
31 )
32 this.addSql(
33 'alter table if exists "auth_identity" drop column if exists "user_metadata";'
34 )
35 this.addSql(
36 'alter table if exists "auth_identity" drop column if exists "provider_metadata";'
37 )
38 }
39
40 async down(): Promise<void> {
41 this.addSql('drop table if exists "provider_identity" cascade;')
42
43 this.addSql(
44 'alter table if exists "auth_identity" add column if not exists "entity_id" text not null, add column "provider" text not null, add column "user_metadata" jsonb null, add column "provider_metadata" jsonb null;'
45 )
46 this.addSql(
47 'alter table if exists "auth_identity" alter column "app_metadata" type jsonb using ("app_metadata"::jsonb);'
48 )
49 this.addSql(
50 'alter table if exists "auth_identity" alter column "app_metadata" set not null;'
51 )
52 this.addSql(
53 'alter table if exists "auth_identity" add constraint "IDX_auth_identity_provider_entity_id" unique ("provider", "entity_id");'
54 )
55 }
56 }