-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12054f5
commit e2cb72e
Showing
8 changed files
with
352 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
287 changes: 287 additions & 0 deletions
287
packages/region/src/migrations/.snapshot-medusa-region.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,287 @@ | ||
{ | ||
"namespaces": [ | ||
"public" | ||
], | ||
"name": "public", | ||
"tables": [ | ||
{ | ||
"columns": { | ||
"code": { | ||
"name": "code", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"symbol": { | ||
"name": "symbol", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"symbol_native": { | ||
"name": "symbol_native", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
} | ||
}, | ||
"name": "region_currency", | ||
"schema": "public", | ||
"indexes": [ | ||
{ | ||
"keyName": "region_currency_pkey", | ||
"columnNames": [ | ||
"code" | ||
], | ||
"composite": false, | ||
"primary": true, | ||
"unique": true | ||
} | ||
], | ||
"checks": [], | ||
"foreignKeys": {} | ||
}, | ||
{ | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"currency_code": { | ||
"name": "currency_code", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"metadata": { | ||
"name": "metadata", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": true, | ||
"mappedType": "json" | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "timestamptz", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 6, | ||
"default": "now()", | ||
"mappedType": "datetime" | ||
}, | ||
"updated_at": { | ||
"name": "updated_at", | ||
"type": "timestamptz", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 6, | ||
"default": "now()", | ||
"mappedType": "datetime" | ||
}, | ||
"deleted_at": { | ||
"name": "deleted_at", | ||
"type": "timestamptz", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": true, | ||
"length": 6, | ||
"mappedType": "datetime" | ||
} | ||
}, | ||
"name": "region", | ||
"schema": "public", | ||
"indexes": [ | ||
{ | ||
"columnNames": [ | ||
"currency_id" | ||
], | ||
"composite": false, | ||
"keyName": "IDX_region_currency_code", | ||
"primary": false, | ||
"unique": false | ||
}, | ||
{ | ||
"columnNames": [ | ||
"deleted_at" | ||
], | ||
"composite": false, | ||
"keyName": "IDX_region_deleted_at", | ||
"primary": false, | ||
"unique": false | ||
}, | ||
{ | ||
"keyName": "region_pkey", | ||
"columnNames": [ | ||
"id" | ||
], | ||
"composite": false, | ||
"primary": true, | ||
"unique": true | ||
} | ||
], | ||
"checks": [], | ||
"foreignKeys": { | ||
"region_currency_id_foreign": { | ||
"constraintName": "region_currency_code_foreign", | ||
"columnNames": [ | ||
"currency_code" | ||
], | ||
"localTableName": "public.region", | ||
"referencedColumnNames": [ | ||
"code" | ||
], | ||
"referencedTableName": "public.region_currency", | ||
"deleteRule": "cascade", | ||
"updateRule": "cascade" | ||
} | ||
} | ||
}, | ||
{ | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"iso_2": { | ||
"name": "iso_2", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"iso_3": { | ||
"name": "iso_3", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"num_code": { | ||
"name": "num_code", | ||
"type": "int", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "integer" | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"display_name": { | ||
"name": "display_name", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "text" | ||
}, | ||
"region_id": { | ||
"name": "region_id", | ||
"type": "text", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": true, | ||
"mappedType": "text" | ||
} | ||
}, | ||
"name": "region_country", | ||
"schema": "public", | ||
"indexes": [ | ||
{ | ||
"columnNames": [ | ||
"region_id" | ||
], | ||
"composite": false, | ||
"keyName": "IDX_country_region_id", | ||
"primary": false, | ||
"unique": false | ||
}, | ||
{ | ||
"keyName": "region_country_pkey", | ||
"columnNames": [ | ||
"id" | ||
], | ||
"composite": false, | ||
"primary": true, | ||
"unique": true | ||
} | ||
], | ||
"checks": [], | ||
"foreignKeys": { | ||
"region_country_region_id_foreign": { | ||
"constraintName": "region_country_region_id_foreign", | ||
"columnNames": [ | ||
"region_id" | ||
], | ||
"localTableName": "public.region_country", | ||
"referencedColumnNames": [ | ||
"id" | ||
], | ||
"referencedTableName": "public.region", | ||
"deleteRule": "cascade", | ||
"updateRule": "cascade" | ||
} | ||
} | ||
} | ||
] | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/region/src/migrations/RegionModuleSetup20240205173216.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Migration } from "@mikro-orm/migrations" | ||
|
||
export class RegionModuleSetup20240205173216 extends Migration { | ||
async up(): Promise<void> { | ||
this.addSql(` | ||
-- Create or update "region" table | ||
CREATE TABLE IF NOT EXISTS "region" ( | ||
"id" text NOT NULL, | ||
"name" text NOT NULL, | ||
"currency_code" text NOT NULL, | ||
"metadata" jsonb NULL, | ||
"created_at" timestamptz NOT NULL DEFAULT now(), | ||
"updated_at" timestamptz NOT NULL DEFAULT now(), | ||
"deleted_at" timestamptz NULL, | ||
CONSTRAINT "region_pkey" PRIMARY KEY ("id") | ||
); | ||
-- Create or update "region_currency" table | ||
CREATE TABLE IF NOT EXISTS "region_currency" ( | ||
"code" text NOT NULL, | ||
"symbol" text NOT NULL, | ||
"symbol_native" text NOT NULL, | ||
"name" text NOT NULL, | ||
CONSTRAINT "region_currency_pkey" PRIMARY KEY ("code") | ||
); | ||
-- Adjust "region" table | ||
ALTER TABLE "region" DROP CONSTRAINT IF EXISTS "FK_3bdd5896ec93be2f1c62a3309a5"; | ||
ALTER TABLE "region" DROP CONSTRAINT IF EXISTS "FK_91f88052197680f9790272aaf5b"; | ||
ALTER TABLE "region" ADD CONSTRAINT "region_currency_code_foreign" FOREIGN KEY ("currency_code") REFERENCES "region_currency" ("code") ON UPDATE CASCADE; | ||
CREATE INDEX IF NOT EXISTS "IDX_region_currency_code" ON "region" ("currency_code"); | ||
CREATE INDEX IF NOT EXISTS "IDX_region_deleted_at" ON "region" ("deleted_at") WHERE "deleted_at" IS NOT NULL; | ||
-- Create or update "region_country" table | ||
CREATE TABLE IF NOT EXISTS "region_country" ( | ||
"id" text NOT NULL, | ||
"iso_2" text NOT NULL, | ||
"iso_3" text NOT NULL, | ||
"num_code" int NOT NULL, | ||
"name" text NOT NULL, | ||
"display_name" text NOT NULL, | ||
"region_id" text NULL, | ||
CONSTRAINT "region_country_pkey" PRIMARY KEY ("id") | ||
); | ||
CREATE INDEX IF NOT EXISTS "IDX_country_region_id" ON "region_country" ("region_id"); | ||
-- Adjust foreign keys for "region_country" | ||
ALTER TABLE "region_country" DROP CONSTRAINT IF EXISTS "FK_91f88052197680f9790272aaf5b"; | ||
ALTER TABLE "region_country" ADD CONSTRAINT "region_country_region_id_foreign" FOREIGN KEY ("region_id") REFERENCES "region" ("id") ON UPDATE CASCADE; | ||
`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.