feat(medusa): Allow custom database schema (#2819)
This commit is contained in:
5
.changeset/few-tomatoes-tie.md
Normal file
5
.changeset/few-tomatoes-tie.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
Allow custom database schema
|
||||
@@ -25,6 +25,7 @@ const t = async function ({ directory }) {
|
||||
const connection = await createConnection({
|
||||
type: configModule.projectConfig.database_type,
|
||||
url: configModule.projectConfig.database_url,
|
||||
schema: configModule.projectConfig.database_schema,
|
||||
extra: configModule.projectConfig.database_extra || {},
|
||||
migrations: enabledMigrations,
|
||||
logging: true,
|
||||
|
||||
@@ -44,6 +44,7 @@ const t = async function ({ directory, migrate, seedFile }) {
|
||||
const connection = await createConnection({
|
||||
type: configModule.projectConfig.database_type,
|
||||
database: configModule.projectConfig.database_database,
|
||||
schema: configModule.projectConfig.database_schema,
|
||||
url: configModule.projectConfig.database_url,
|
||||
extra: configModule.projectConfig.database_extra || {},
|
||||
migrations: migrationDirs,
|
||||
|
||||
@@ -32,6 +32,7 @@ export default async ({
|
||||
url: configModule.projectConfig.database_url,
|
||||
database: configModule.projectConfig.database_database,
|
||||
extra: configModule.projectConfig.database_extra || {},
|
||||
schema: configModule.projectConfig.database_schema,
|
||||
entities,
|
||||
namingStrategy: new ShortenedNamingStrategy(),
|
||||
logging: configModule.projectConfig.database_logging || false,
|
||||
|
||||
@@ -68,7 +68,7 @@ export class claims1612284947120 implements MigrationInterface {
|
||||
`ALTER TABLE "line_item" ADD "claim_order_id" character varying`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."refund_reason_enum" RENAME TO "refund_reason_enum_old"`
|
||||
`ALTER TYPE "refund_reason_enum" RENAME TO "refund_reason_enum_old"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "refund_reason_enum" AS ENUM('discount', 'return', 'swap', 'claim', 'other')`
|
||||
|
||||
@@ -11,7 +11,7 @@ export class draftOrders1613384784316 implements MigrationInterface {
|
||||
await queryRunner.query(`CREATE INDEX "IDX_8f6dd6c49202f1466ebf21e77d" ON "draft_order" ("order_id") `);
|
||||
await queryRunner.query(`ALTER TABLE "order" ADD "draft_order_id" character varying`);
|
||||
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "UQ_727b872f86c7378474a8fa46147" UNIQUE ("draft_order_id")`);
|
||||
await queryRunner.query(`ALTER TYPE "public"."cart_type_enum" RENAME TO "cart_type_enum_old"`);
|
||||
await queryRunner.query(`ALTER TYPE "cart_type_enum" RENAME TO "cart_type_enum_old"`);
|
||||
await queryRunner.query(`CREATE TYPE "cart_type_enum" AS ENUM('default', 'swap', 'draft_order', 'payment_link')`);
|
||||
await queryRunner.query(`ALTER TABLE "cart" ALTER COLUMN "type" DROP DEFAULT`);
|
||||
await queryRunner.query(`ALTER TABLE "cart" ALTER COLUMN "type" TYPE "cart_type_enum" USING "type"::"text"::"cart_type_enum"`);
|
||||
|
||||
@@ -11,10 +11,10 @@ export class extendedUserApi1633512755401 implements MigrationInterface {
|
||||
`CREATE TABLE "invite" ("id" character varying NOT NULL, "user_email" character varying NOT NULL, "role" "invite_role_enum" DEFAULT 'member', "accepted" boolean NOT NULL DEFAULT false, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP WITH TIME ZONE, "metadata" jsonb, CONSTRAINT "PK_fc9fa190e5a3c5d80604a4f63e1" PRIMARY KEY ("id"))`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "public"."invite" ADD "token" character varying NOT NULL`
|
||||
`ALTER TABLE "invite" ADD "token" character varying NOT NULL`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "public"."invite" ADD "expires_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
|
||||
`ALTER TABLE "invite" ADD "expires_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
|
||||
)
|
||||
|
||||
await queryRunner.query(
|
||||
@@ -32,22 +32,22 @@ export class extendedUserApi1633512755401 implements MigrationInterface {
|
||||
)
|
||||
await queryRunner.query(`DROP INDEX "IDX_e12875dfb3b1d92d7d7c5377e2"`)
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_ba8de19442d86957a3aa3b5006" ON "public"."user" ("email") WHERE deleted_at IS NULL`
|
||||
`CREATE UNIQUE INDEX "IDX_ba8de19442d86957a3aa3b5006" ON "user" ("email") WHERE deleted_at IS NULL`
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_ba8de19442d86957a3aa3b5006"`)
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_e12875dfb3b1d92d7d7c5377e2" ON "public"."user" ("email") `
|
||||
`CREATE UNIQUE INDEX "IDX_e12875dfb3b1d92d7d7c5377e2" ON "user" ("email") `
|
||||
)
|
||||
await queryRunner.query(`DROP INDEX "IDX_6b0ce4b4bcfd24491510bf19d1"`)
|
||||
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "role"`)
|
||||
await queryRunner.query(`DROP TYPE "user_role_enum"`)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "public"."invite" DROP COLUMN "expires_at"`
|
||||
`ALTER TABLE "invite" DROP COLUMN "expires_at"`
|
||||
)
|
||||
await queryRunner.query(`ALTER TABLE "public"."invite" DROP COLUMN "token"`)
|
||||
await queryRunner.query(`ALTER TABLE "invite" DROP COLUMN "token"`)
|
||||
|
||||
await queryRunner.query(`DROP TABLE "invite"`)
|
||||
await queryRunner.query(`DROP TYPE "invite_role_enum"`)
|
||||
|
||||
@@ -131,22 +131,22 @@ export class newTaxSystem1641636508055 implements MigrationInterface {
|
||||
`ALTER TABLE "tax_rate" DROP CONSTRAINT "FK_b95a1e03b051993d208366cb960"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_f672727ab020df6c50fb64c1a7"`
|
||||
`DROP INDEX "IDX_f672727ab020df6c50fb64c1a7"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_346e0016cf045b998074774764"`
|
||||
`DROP INDEX "IDX_346e0016cf045b998074774764"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_25a3138bb236f63d9bb6c8ff11"`
|
||||
`DROP INDEX "IDX_25a3138bb236f63d9bb6c8ff11"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_ece65a774192b34253abc4cd67"`
|
||||
`DROP INDEX "IDX_ece65a774192b34253abc4cd67"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_1d04aebeabb6a89f87e536a124"`
|
||||
`DROP INDEX "IDX_1d04aebeabb6a89f87e536a124"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_2484cf14c437a04586b07e7ddd"`
|
||||
`DROP INDEX "IDX_2484cf14c437a04586b07e7ddd"`
|
||||
)
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "order" ALTER COLUMN "tax_rate" SET NOT NULL`
|
||||
@@ -165,11 +165,11 @@ export class newTaxSystem1641636508055 implements MigrationInterface {
|
||||
await queryRunner.query(`DROP TABLE "product_type_tax_rate"`)
|
||||
await queryRunner.query(`DROP TABLE "product_tax_rate"`)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_926ca9f29014af8091722dede0"`
|
||||
`DROP INDEX "IDX_926ca9f29014af8091722dede0"`
|
||||
)
|
||||
await queryRunner.query(`DROP TABLE "shipping_method_tax_line"`)
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_5077fa54b0d037e984385dfe8a"`
|
||||
`DROP INDEX "IDX_5077fa54b0d037e984385dfe8a"`
|
||||
)
|
||||
await queryRunner.query(`DROP TABLE "line_item_tax_line"`)
|
||||
await queryRunner.query(`DROP TABLE "tax_provider"`)
|
||||
|
||||
@@ -17,7 +17,7 @@ export class extendedBatchJob1657267320181 implements MigrationInterface {
|
||||
if (batchJobColumnStatusExists[0].exists) {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE "batch_job" DROP COLUMN "status";
|
||||
DROP TYPE "public"."batch_job_status_enum";
|
||||
DROP TYPE "batch_job_status_enum";
|
||||
ALTER TABLE "batch_job" ADD "dry_run" boolean NOT NULL DEFAULT false;
|
||||
ALTER TABLE "batch_job" ADD "pre_processed_at" TIMESTAMP WITH TIME ZONE;
|
||||
ALTER TABLE "batch_job" ADD "processing_at" TIMESTAMP WITH TIME ZONE;
|
||||
|
||||
@@ -17,7 +17,7 @@ export class addAnalyticsConfig1666173221888 implements MigrationInterface {
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_379ca70338ce9991f3affdeedf"`
|
||||
`DROP INDEX "IDX_379ca70338ce9991f3affdeedf"`
|
||||
)
|
||||
await queryRunner.query(`DROP TABLE "analytics_config"`)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export class updateCustomerEmailConstraint_1669032280562
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "public"."IDX_fdb2f3ad8115da4c7718109a6e"`
|
||||
`DROP INDEX "IDX_fdb2f3ad8115da4c7718109a6e"`
|
||||
)
|
||||
|
||||
await queryRunner.query(
|
||||
|
||||
@@ -61,6 +61,7 @@ export type ConfigModule = {
|
||||
database_url?: string
|
||||
database_type: string
|
||||
database_database?: string
|
||||
database_schema?: string
|
||||
database_logging: LoggerOptions
|
||||
|
||||
database_extra?: Record<string, unknown> & {
|
||||
|
||||
Reference in New Issue
Block a user