Remove v1-related code from medusa app (#7326)

* chore: Remove unused validations and utilities

* chore: Remove all resources that are not being loaded

* chore: Remove unused dependencies, typeorm related code and fix tests

* chore: Use createAdminUser in all module tests
This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-05-14 13:21:30 +02:00
1 parent 9dae86daa2
commit d680c7ee4c
226 files changed
+110 -13506

No files matched your search

@@ -73,7 +73,7 @@ const getProductFixture = (overrides) => ({
}) })
medusaIntegrationTestRunner({ medusaIntegrationTestRunner({
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true }, env: { MEDUSA_FF_PRODUCT_CATEGORIES: true, MEDUSA_FF_MEDUSA_V2: true },
testSuite: ({ dbConnection, getContainer, api }) => { testSuite: ({ dbConnection, getContainer, api }) => {
let baseProduct let baseProduct
let proposedProduct let proposedProduct
@@ -9,9 +9,6 @@ module.exports = async (dataSource, data = {}) => {
const user = await manager.insert("user", { const user = await manager.insert("user", {
id: "admin_user", id: "admin_user",
email: "admin@medusa.js", email: "admin@medusa.js",
api_token: "test_token",
role: "admin",
password_hash,
...data, ...data,
}) })
@@ -1,8 +1,11 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types" import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
import Scrypt from "scrypt-kdf" import Scrypt from "scrypt-kdf"
import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -23,7 +26,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
}) })
const password = "supersecret" const password = "supersecret"
@@ -6,8 +6,11 @@ import {
} from "@medusajs/modules-sdk" } from "@medusajs/modules-sdk"
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types" import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -32,7 +35,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
}) })
describe("POST /store/carts/:id/promotions", () => { describe("POST /store/carts/:id/promotions", () => {
@@ -28,7 +28,10 @@ import {
} from "@medusajs/types" } from "@medusajs/types"
import { ContainerRegistrationKeys, RuleOperator } from "@medusajs/utils" import { ContainerRegistrationKeys, RuleOperator } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import adminSeeder from "../../../../helpers/admin-seeder" import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(200000) jest.setTimeout(200000)
@@ -84,7 +87,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
// Here, so we don't have to create a region for each test // Here, so we don't have to create a region for each test
defaultRegion = await regionModuleService.create({ defaultRegion = await regionModuleService.create({
@@ -6,8 +6,11 @@ import {
} from "@medusajs/modules-sdk" } from "@medusajs/modules-sdk"
import { ICartModuleService, IPromotionModuleService } from "@medusajs/types" import { ICartModuleService, IPromotionModuleService } from "@medusajs/types"
import { PromotionType } from "@medusajs/utils" import { PromotionType } from "@medusajs/utils"
import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -32,7 +35,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
}) })
describe("DELETE /store/carts/:id/promotions", () => { describe("DELETE /store/carts/:id/promotions", () => {
@@ -1,9 +1,12 @@
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types" import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../../helpers/admin-seeder"
import jwt from "jsonwebtoken" import jwt from "jsonwebtoken"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -24,7 +27,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
}) })
it("should create a customer", async () => { it("should create a customer", async () => {
@@ -8,10 +8,10 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -40,7 +40,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
@@ -5,9 +5,9 @@ import {
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -38,7 +38,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
@@ -5,9 +5,9 @@ import {
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -36,7 +36,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
@@ -5,9 +5,9 @@ import {
import { IPricingModuleService } from "@medusajs/types" import { IPricingModuleService } from "@medusajs/types"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -36,7 +36,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
@@ -10,10 +10,10 @@ import {
PriceListStatus, PriceListStatus,
PriceListType, PriceListType,
} from "@medusajs/types" } from "@medusajs/types"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -43,7 +43,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
@@ -1,9 +1,9 @@
import { simpleCartFactory, simpleRegionFactory } from "../../../factories" import { simpleCartFactory, simpleRegionFactory } from "../../../factories"
import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../helpers/create-default-rule-types"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../helpers/create-admin-user"
jest.setTimeout(5000000) jest.setTimeout(5000000)
@@ -34,7 +34,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await createDefaultRuleTypes(medusaContainer) await createDefaultRuleTypes(medusaContainer)
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, medusaContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
id: "region-1", id: "region-1",
currency_code: "usd", currency_code: "usd",
@@ -4,9 +4,9 @@ import {
simpleProductFactory, simpleProductFactory,
simpleRegionFactory, simpleRegionFactory,
} from "../../../../factories" } from "../../../../factories"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { medusaIntegrationTestRunner } from "medusa-test-utils" import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -33,7 +33,7 @@ medusaIntegrationTestRunner({
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
@@ -5,9 +5,12 @@ import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container" import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db" import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleSalesChannelFactory } from "../../../../factories" import { simpleSalesChannelFactory } from "../../../../factories"
import adminSeeder from "../../../../helpers/admin-seeder"
import productSeeder from "../../../../helpers/product-seeder" import productSeeder from "../../../../helpers/product-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
const setupServer = require("../../../../environment-helpers/setup-server") const setupServer = require("../../../../environment-helpers/setup-server")
const userSeeder = require("../../../../helpers/user-seeder") const userSeeder = require("../../../../helpers/user-seeder")
@@ -64,7 +67,7 @@ describe.skip("Batch job of product-export type", () => {
const container = getContainer() const container = getContainer()
await createDefaultRuleTypes(container) await createDefaultRuleTypes(container)
await productSeeder(dbConnection) await productSeeder(dbConnection)
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, container)
await userSeeder(dbConnection) await userSeeder(dbConnection)
await simpleSalesChannelFactory(dbConnection, { await simpleSalesChannelFactory(dbConnection, {
@@ -7,9 +7,12 @@ import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db" import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { simpleProductFactory } from "../../../../factories" import { simpleProductFactory } from "../../../../factories"
import { simpleProductCollectionFactory } from "../../../../factories/simple-product-collection-factory" import { simpleProductCollectionFactory } from "../../../../factories/simple-product-collection-factory"
import adminSeeder from "../../../../helpers/admin-seeder"
import batchJobSeeder from "../../../../helpers/batch-job-seeder" import batchJobSeeder from "../../../../helpers/batch-job-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
const setupServer = require("../../../../environment-helpers/setup-server") const setupServer = require("../../../../environment-helpers/setup-server")
const userSeeder = require("../../../../helpers/user-seeder") const userSeeder = require("../../../../helpers/user-seeder")
@@ -98,7 +101,7 @@ describe.skip("Product import batch job", () => {
const container = getContainer() const container = getContainer()
await createDefaultRuleTypes(container) await createDefaultRuleTypes(container)
await batchJobSeeder(dbConnection) await batchJobSeeder(dbConnection)
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, container)
await userSeeder(dbConnection) await userSeeder(dbConnection)
await simpleProductCollectionFactory(dbConnection, [ await simpleProductCollectionFactory(dbConnection, [
{ {
@@ -3,8 +3,6 @@ import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app
import { useApi } from "../../../../environment-helpers/use-api" import { useApi } from "../../../../environment-helpers/use-api"
import { initDb, useDb } from "../../../../environment-helpers/use-db" import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk" import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
import { MedusaV2Flag } from "@medusajs/utils" import { MedusaV2Flag } from "@medusajs/utils"
import { AxiosInstance } from "axios" import { AxiosInstance } from "axios"
@@ -14,6 +12,7 @@ import {
simpleSalesChannelFactory, simpleSalesChannelFactory,
} from "../../../../factories" } from "../../../../factories"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -67,7 +66,7 @@ describe.skip("/admin/products", () => {
describe("POST /admin/products", () => { describe("POST /admin/products", () => {
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, medusaContainer)
await createDefaultRuleTypes(medusaContainer) await createDefaultRuleTypes(medusaContainer)
await simpleSalesChannelFactory(dbConnection, { await simpleSalesChannelFactory(dbConnection, {
@@ -442,7 +441,7 @@ describe.skip("/admin/products", () => {
beforeEach(async () => { beforeEach(async () => {
await productSeeder(dbConnection) await productSeeder(dbConnection)
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, medusaContainer)
await createDefaultRuleTypes(medusaContainer) await createDefaultRuleTypes(medusaContainer)
await simpleSalesChannelFactory(dbConnection, { await simpleSalesChannelFactory(dbConnection, {
@@ -1,16 +1,17 @@
import {initDb, useDb} from "../../../../environment-helpers/use-db" import { initDb, useDb } from "../../../../environment-helpers/use-db"
import {simpleProductFactory, simpleRegionFactory,} from "../../../../factories"
import {AxiosInstance} from "axios"
import adminSeeder from "../../../../helpers/admin-seeder"
import { import {
createDefaultRuleTypes simpleProductFactory,
} from "../../../helpers/create-default-rule-types" simpleRegionFactory,
import {createVariantPriceSet} from "../../../helpers/create-variant-price-set" } from "../../../../factories"
import {getContainer} from "../../../../environment-helpers/use-container"
import { AxiosInstance } from "axios"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { getContainer } from "../../../../environment-helpers/use-container"
import path from "path" import path from "path"
import {startBootstrapApp} from "../../../../environment-helpers/bootstrap-app" import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import {useApi} from "../../../../environment-helpers/use-api" import { useApi } from "../../../../environment-helpers/use-api"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -49,7 +50,7 @@ describe.skip("POST /admin/products/:id/variants/:id", () => {
}) })
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await simpleRegionFactory(dbConnection, { await simpleRegionFactory(dbConnection, {
@@ -7,9 +7,9 @@ import { Region } from "@medusajs/medusa"
import { AxiosInstance } from "axios" import { AxiosInstance } from "axios"
import path from "path" import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app" import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import adminSeeder from "../../../../helpers/admin-seeder"
import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types" import { createDefaultRuleTypes } from "../../../helpers/create-default-rule-types"
import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set"
import { createAdminUser } from "../../../../helpers/create-admin-user"
jest.setTimeout(50000) jest.setTimeout(50000)
@@ -49,7 +49,7 @@ describe.skip("POST /admin/products/:id", () => {
beforeEach(async () => { beforeEach(async () => {
const manager = dbConnection.manager const manager = dbConnection.manager
await adminSeeder(dbConnection) await createAdminUser(dbConnection, adminHeaders, appContainer)
await createDefaultRuleTypes(appContainer) await createDefaultRuleTypes(appContainer)
await manager.insert(Region, { await manager.insert(Region, {
@@ -1,6 +1,5 @@
const path = require("path") const path = require("path")
const { getConfigFile } = require("medusa-core-utils")
const { asValue } = require("awilix") const { asValue } = require("awilix")
const { const {
isObject, isObject,
@@ -33,44 +32,19 @@ module.exports = {
require("@medusajs/medusa/dist/loaders/feature-flags").default require("@medusajs/medusa/dist/loaders/feature-flags").default
const featureFlagRouter = featureFlagsLoader(configModule) const featureFlagRouter = featureFlagsLoader(configModule)
const modelsLoader = require("@medusajs/medusa/dist/loaders/models").default
const entities = modelsLoader({}, { register: false })
// get migrations with enabled featureflags
const migrationDir = path.resolve(
path.join(
cwd,
`../../`,
`node_modules`,
`@medusajs`,
`medusa`,
`dist`,
`migrations`,
`*.js`
)
)
const { const {
getEnabledMigrations,
getModuleSharedResources, getModuleSharedResources,
} = require("@medusajs/medusa/dist/commands/utils/get-migrations") } = require("@medusajs/medusa/dist/commands/utils/get-migrations")
const { migrations: moduleMigrations, models: moduleModels } = const { migrations: moduleMigrations, models: moduleModels } =
getModuleSharedResources(configModule, featureFlagRouter) getModuleSharedResources(configModule, featureFlagRouter)
const enabledMigrations = getEnabledMigrations([migrationDir], (flag) =>
featureFlagRouter.isFeatureEnabled(flag)
)
const enabledEntities = entities.filter(
(e) => typeof e.isFeatureEnabled === "undefined" || e.isFeatureEnabled()
)
const dbDataSource = new DataSource({ const dbDataSource = new DataSource({
type: "postgres", type: "postgres",
url: dbUrl || configModule.projectConfig.database_url, url: dbUrl || configModule.projectConfig.database_url,
entities: enabledEntities.concat(moduleModels), entities: moduleModels,
migrations: enabledMigrations.concat(moduleMigrations), migrations: moduleMigrations,
extra: database_extra ?? {}, extra: database_extra ?? {},
//name: "integration-tests", //name: "integration-tests",
schema: dbSchema, schema: dbSchema,
+1 -13
View File
@@ -38,7 +38,6 @@
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"supertest": "^4.0.2", "supertest": "^4.0.2",
"ts-jest": "^25.5.1", "ts-jest": "^25.5.1",
"typeorm": "^0.3.16",
"typescript": "^4.4.4" "typescript": "^4.4.4"
}, },
"scripts": { "scripts": {
@@ -49,8 +48,7 @@
"test": "jest --silent --bail --maxWorkers=50% --forceExit" "test": "jest --silent --bail --maxWorkers=50% --forceExit"
}, },
"peerDependencies": { "peerDependencies": {
"medusa-interfaces": "^1.3.7", "medusa-interfaces": "^1.3.7"
"typeorm": "^0.3.16"
}, },
"dependencies": { "dependencies": {
"@medusajs/core-flows": "^0.0.9", "@medusajs/core-flows": "^0.0.9",
@@ -63,16 +61,12 @@
"awilix": "^8.0.0", "awilix": "^8.0.0",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"boxen": "^5.0.1", "boxen": "^5.0.1",
"bullmq": "^5.4.2",
"chokidar": "^3.4.2", "chokidar": "^3.4.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"compression": "^1.7.4", "compression": "^1.7.4",
"connect-redis": "^5.0.0", "connect-redis": "^5.0.0",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"cors": "^2.8.5", "cors": "^2.8.5",
"cross-spawn": "^7.0.3",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"express": "^4.18.2", "express": "^4.18.2",
"express-session": "^1.17.3", "express-session": "^1.17.3",
@@ -80,7 +74,6 @@
"glob": "^7.1.6", "glob": "^7.1.6",
"ioredis": "^5.2.5", "ioredis": "^5.2.5",
"ioredis-mock": "8.4.0", "ioredis-mock": "8.4.0",
"iso8601-duration": "^1.3.0",
"jsonwebtoken": "^9.0.0", "jsonwebtoken": "^9.0.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"medusa-core-utils": "^1.2.2", "medusa-core-utils": "^1.2.2",
@@ -88,21 +81,16 @@
"morgan": "^1.9.1", "morgan": "^1.9.1",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"node-schedule": "^2.1.1", "node-schedule": "^2.1.1",
"papaparse": "5.3.2",
"passport": "^0.6.0", "passport": "^0.6.0",
"passport-custom": "^1.1.1", "passport-custom": "^1.1.1",
"passport-jwt": "^4.0.1", "passport-jwt": "^4.0.1",
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
"pg": "^8.11.2", "pg": "^8.11.2",
"qs": "^6.11.2", "qs": "^6.11.2",
"randomatic": "^3.1.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"regenerator-runtime": "^0.13.11", "regenerator-runtime": "^0.13.11",
"request-ip": "^3.3.0", "request-ip": "^3.3.0",
"scrypt-kdf": "^2.0.1",
"ulid": "^2.3.0",
"uuid": "^9.0.0", "uuid": "^9.0.0",
"winston": "^3.8.2",
"zod": "3.22.4" "zod": "3.22.4"
}, },
"gitHead": "cd1f5afa5aa8c0b15ea957008ee19f1d695cbd2e" "gitHead": "cd1f5afa5aa8c0b15ea957008ee19f1d695cbd2e"
@@ -4,7 +4,7 @@ import {
createOperatorMap, createOperatorMap,
createSelectParams, createSelectParams,
} from "../../utils/validators" } from "../../utils/validators"
import { optionalBooleanMapper } from "../../../utils/validators/is-boolean" import { OptionalBooleanValidator } from "../../utils/common-validators"
export type AdminGetInventoryItemParamsType = z.infer< export type AdminGetInventoryItemParamsType = z.infer<
typeof AdminGetInventoryItemParams typeof AdminGetInventoryItemParams
@@ -27,12 +27,7 @@ export const AdminGetInventoryItemsParams = createFindParams({
mid_code: z.union([z.string(), z.array(z.string())]).optional(), mid_code: z.union([z.string(), z.array(z.string())]).optional(),
hs_code: z.union([z.string(), z.array(z.string())]).optional(), hs_code: z.union([z.string(), z.array(z.string())]).optional(),
material: z.union([z.string(), z.array(z.string())]).optional(), material: z.union([z.string(), z.array(z.string())]).optional(),
requires_shipping: z requires_shipping: OptionalBooleanValidator,
.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional()
)
.optional(),
weight: createOperatorMap(z.number(), parseFloat).optional(), weight: createOperatorMap(z.number(), parseFloat).optional(),
length: createOperatorMap(z.number(), parseFloat).optional(), length: createOperatorMap(z.number(), parseFloat).optional(),
height: createOperatorMap(z.number(), parseFloat).optional(), height: createOperatorMap(z.number(), parseFloat).optional(),
@@ -1,24 +1,18 @@
import { z } from "zod" import { z } from "zod"
import { optionalBooleanMapper } from "../../../utils/validators/is-boolean"
import { import {
createFindParams, createFindParams,
createOperatorMap, createOperatorMap,
createSelectParams, createSelectParams,
} from "../../utils/validators" } from "../../utils/validators"
import { OptionalBooleanValidator } from "../../utils/common-validators"
export type AdminProductCategoryParamsType = z.infer< export type AdminProductCategoryParamsType = z.infer<
typeof AdminProductCategoryParams typeof AdminProductCategoryParams
> >
export const AdminProductCategoryParams = createSelectParams().merge( export const AdminProductCategoryParams = createSelectParams().merge(
z.object({ z.object({
include_ancestors_tree: z.preprocess( include_ancestors_tree: OptionalBooleanValidator,
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()), include_descendants_tree: OptionalBooleanValidator,
z.boolean().optional()
),
include_descendants_tree: z.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional()
),
}) })
) )
@@ -35,22 +29,10 @@ export const AdminProductCategoriesParams = createFindParams({
description: z.union([z.string(), z.array(z.string())]).optional(), description: z.union([z.string(), z.array(z.string())]).optional(),
handle: z.union([z.string(), z.array(z.string())]).optional(), handle: z.union([z.string(), z.array(z.string())]).optional(),
parent_category_id: z.union([z.string(), z.array(z.string())]).optional(), parent_category_id: z.union([z.string(), z.array(z.string())]).optional(),
include_ancestors_tree: z.preprocess( include_ancestors_tree: OptionalBooleanValidator,
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()), include_descendants_tree: OptionalBooleanValidator,
z.boolean().optional() is_internal: OptionalBooleanValidator,
), is_active: OptionalBooleanValidator,
include_descendants_tree: z.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional()
),
is_internal: z.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional()
),
is_active: z.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional()
),
created_at: createOperatorMap().optional(), created_at: createOperatorMap().optional(),
updated_at: createOperatorMap().optional(), updated_at: createOperatorMap().optional(),
deleted_at: createOperatorMap().optional(), deleted_at: createOperatorMap().optional(),
@@ -1,24 +1,18 @@
import { z } from "zod" import { z } from "zod"
import { optionalBooleanMapper } from "../../../utils/validators/is-boolean"
import { import {
createFindParams, createFindParams,
createOperatorMap, createOperatorMap,
createSelectParams, createSelectParams,
} from "../../utils/validators" } from "../../utils/validators"
import { OptionalBooleanValidator } from "../../utils/common-validators"
export type StoreProductCategoryParamsType = z.infer< export type StoreProductCategoryParamsType = z.infer<
typeof StoreProductCategoryParams typeof StoreProductCategoryParams
> >
export const StoreProductCategoryParams = createSelectParams().merge( export const StoreProductCategoryParams = createSelectParams().merge(
z.object({ z.object({
include_ancestors_tree: z.preprocess( include_ancestors_tree: OptionalBooleanValidator,
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()), include_descendants_tree: OptionalBooleanValidator,
z.boolean().optional()
),
include_descendants_tree: z.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional()
),
}) })
) )
@@ -35,14 +29,8 @@ export const StoreProductCategoriesParams = createFindParams({
description: z.union([z.string(), z.array(z.string())]).optional(), description: z.union([z.string(), z.array(z.string())]).optional(),
handle: z.union([z.string(), z.array(z.string())]).optional(), handle: z.union([z.string(), z.array(z.string())]).optional(),
parent_category_id: z.union([z.string(), z.array(z.string())]).optional(), parent_category_id: z.union([z.string(), z.array(z.string())]).optional(),
include_ancestors_tree: z.preprocess( include_ancestors_tree: OptionalBooleanValidator,
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()), include_descendants_tree: OptionalBooleanValidator,
z.boolean().optional()
),
include_descendants_tree: z.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional()
),
created_at: createOperatorMap().optional(), created_at: createOperatorMap().optional(),
updated_at: createOperatorMap().optional(), updated_at: createOperatorMap().optional(),
deleted_at: createOperatorMap().optional(), deleted_at: createOperatorMap().optional(),
@@ -1,5 +1,4 @@
import { z } from "zod" import { z } from "zod"
import { optionalBooleanMapper } from "../../../utils/validators/is-boolean"
export const AddressPayload = z export const AddressPayload = z
.object({ .object({
@@ -26,6 +25,13 @@ export const BigNumberInput = z.union([
}), }),
]) ])
const optionalBooleanMapper = new Map([
["undefined", undefined],
["null", null],
["true", true],
["false", false],
])
export const OptionalBooleanValidator = z.preprocess( export const OptionalBooleanValidator = z.preprocess(
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()), (val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
z.boolean().optional() z.boolean().optional()
@@ -1,98 +1,6 @@
import { MedusaModule, registerMedusaModule } from "@medusajs/modules-sdk" import { MedusaModule, registerMedusaModule } from "@medusajs/modules-sdk"
import fs from "fs"
import { sync as existsSync } from "fs-exists-cached"
import glob from "glob" import glob from "glob"
import { isString } from "lodash" import { isDefined } from "medusa-core-utils"
import {
createRequireFromPath,
getConfigFile,
isDefined,
} from "medusa-core-utils"
import path from "path"
import { handleConfigError } from "../../loaders/config"
import { MEDUSA_PROJECT_NAME } from "../../loaders/plugins"
function createFileContentHash(path, files) {
return path + files
}
// TODO: Create unique id for each plugin
function createPluginId(name) {
return name
}
/**
* Finds the correct path for the plugin. If it is a local plugin it will be
* found in the plugins folder. Otherwise we will look for the plugin in the
* installed npm packages.
* @param {string} pluginName - the name of the plugin to find. Should match
* the name of the folder where the plugin is contained.
* @return {object} the plugin details
*/
function resolvePlugin(pluginName) {
// Only find plugins when we're not given an absolute path
if (!existsSync(pluginName)) {
// Find the plugin in the local plugins folder
const resolvedPath = path.resolve(`./plugins/${pluginName}`)
if (existsSync(resolvedPath)) {
if (existsSync(`${resolvedPath}/package.json`)) {
const packageJSON = JSON.parse(
fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`)
)
const name = packageJSON.name || pluginName
// warnOnIncompatiblePeerDependency(name, packageJSON)
return {
resolve: resolvedPath,
name,
id: createPluginId(name),
options: {},
version:
packageJSON.version || createFileContentHash(resolvedPath, `**`),
}
} else {
// Make package.json a requirement for local plugins too
throw new Error(`Plugin ${pluginName} requires a package.json file`)
}
}
}
const rootDir = path.resolve(".")
/**
* Here we have an absolute path to an internal plugin, or a name of a module
* which should be located in node_modules.
*/
try {
const requireSource =
rootDir !== null
? createRequireFromPath(`${rootDir}/:internal:`)
: require
// If the path is absolute, resolve the directory of the internal plugin,
// otherwise resolve the directory containing the package.json
const resolvedPath = path.dirname(
requireSource.resolve(`${pluginName}/package.json`)
)
const packageJSON = JSON.parse(
fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`)
)
// warnOnIncompatiblePeerDependency(packageJSON.name, packageJSON)
return {
resolve: resolvedPath,
id: createPluginId(packageJSON.name),
name: packageJSON.name,
version: packageJSON.version,
}
} catch (err) {
throw new Error(
`Unable to find plugin "${pluginName}". Perhaps you need to install its package?`
)
}
}
export function getInternalModules(configModule) { export function getInternalModules(configModule) {
const modules = [] const modules = []
@@ -129,65 +37,6 @@ export function getInternalModules(configModule) {
return modules return modules
} }
export default (directory, featureFlagRouter) => {
const { configModule, error } = getConfigFile(directory, `medusa-config`)
if (error) {
handleConfigError(error)
}
const { plugins } = configModule
const resolved = plugins.map((plugin) => {
if (isString(plugin)) {
return resolvePlugin(plugin)
}
const details = resolvePlugin(plugin.resolve)
details.options = plugin.options
return details
})
// Resolve user's project as a plugin for loading purposes
resolved.push({
resolve: `${directory}/dist`,
name: MEDUSA_PROJECT_NAME,
id: createPluginId(MEDUSA_PROJECT_NAME),
options: {},
version: createFileContentHash(process.cwd(), `**`),
})
const migrationDirs = []
const corePackageMigrations = path.resolve(
path.join(__dirname, "..", "..", "migrations")
)
migrationDirs.push(path.join(corePackageMigrations, "*.js"))
for (const p of resolved) {
const exists = existsSync(`${p.resolve}/migrations`)
if (exists) {
migrationDirs.push(`${p.resolve}/migrations/*.js`)
continue
}
const distExists = existsSync(`${p.resolve}/dist/migrations`)
if (distExists) {
migrationDirs.push(`${p.resolve}/dist/migrations/*.js`)
}
}
const isFeatureFlagEnabled = (flag) =>
featureFlagRouter.isFeatureEnabled(flag)
const coreMigrations = getEnabledMigrations(
migrationDirs,
isFeatureFlagEnabled
)
return { coreMigrations }
}
export const getEnabledMigrations = (migrationDirs, isFlagEnabled) => { export const getEnabledMigrations = (migrationDirs, isFlagEnabled) => {
const allMigrations = migrationDirs.flatMap((dir) => { const allMigrations = migrationDirs.flatMap((dir) => {
return glob.sync(dir) return glob.sync(dir)
-209
View File
@@ -1,209 +0,0 @@
import {
moduleHelper,
moduleLoader,
ModulesDefinition,
registerMedusaModule,
} from "@medusajs/modules-sdk"
import { asValue, createContainer } from "awilix"
import express from "express"
import jwt from "jsonwebtoken"
import { MockManager } from "medusa-test-utils"
import querystring from "querystring"
import "reflect-metadata"
import supertest from "supertest"
import apiLoader from "../loaders/api"
import featureFlagLoader, { featureFlagRouter } from "../loaders/feature-flags"
import models from "../loaders/models"
import passportLoader from "../loaders/passport"
import repositories from "../loaders/repositories"
import servicesLoader from "../loaders/services"
import strategiesLoader from "../loaders/strategies"
const adminSessionOpts = {
cookieName: "session",
secret: "test",
}
export { adminSessionOpts, clientSessionOpts }
const clientSessionOpts = {
cookieName: "session",
secret: "test",
}
const moduleResolutions = {}
Object.entries(ModulesDefinition).forEach(([moduleKey, module]) => {
moduleResolutions[moduleKey] = registerMedusaModule(
moduleKey,
module.defaultModuleDeclaration,
undefined,
module
)[moduleKey]
})
const config = {
projectConfig: {
jwt_secret: "supersecret",
cookie_secret: "superSecret",
admin_cors: "",
store_cors: "",
},
}
const testApp = express()
function asArray(resolvers) {
return {
resolve: (container) =>
resolvers.map((resolver) => container.build(resolver)),
}
}
const container = createContainer()
// TODO: remove once the util is merged in master
container.registerAdd = function (name, registration) {
const storeKey = name + "_STORE"
if (this.registrations[storeKey] === undefined) {
this.register(storeKey, asValue([]))
}
const store = this.resolve(storeKey)
if (this.registrations[name] === undefined) {
this.register(name, asArray(store))
}
store.unshift(registration)
return this
}.bind(container)
container.register("featureFlagRouter", asValue(featureFlagRouter))
container.register("modulesHelper", asValue(moduleHelper))
container.register("configModule", asValue(config))
container.register({
logger: asValue({
error: () => {},
}),
manager: asValue(MockManager),
})
testApp.set("trust proxy", 1)
testApp.use((req, res, next) => {
req.session = {}
const data = req.get("Cookie")
if (data) {
req.session = {
...req.session,
...JSON.parse(data),
}
}
next()
})
let supertestRequest
let resolveIsInit
const isInit = new Promise((resolve) => {
resolveIsInit = resolve
})
async function init() {
featureFlagLoader(config)
models({ container, configModule: config, isTest: true })
repositories({ container, isTest: true })
servicesLoader({ container, configModule: config })
strategiesLoader({ container, configModule: config })
await passportLoader({ app: testApp, container, configModule: config })
await moduleLoader({ container, moduleResolutions })
testApp.use((req, res, next) => {
req.scope = container.createScope()
next()
})
await apiLoader({ container, app: testApp, configModule: config })
supertestRequest = supertest(testApp)
resolveIsInit(true)
}
init()
export async function request(method, url, opts = {}) {
await isInit
const { payload, query, headers = {}, flags = [] } = opts
flags.forEach((flag) => {
featureFlagRouter.setFlag(flag.key, true)
})
const queryParams = query && querystring.stringify(query)
const req = supertestRequest[method.toLowerCase()](
`${url}${queryParams ? "?" + queryParams : ""}`
)
headers.Cookie = headers.Cookie || ""
if (opts.adminSession) {
const token = jwt.sign(
{
user_id: opts.adminSession.userId || opts.adminSession.jwt?.userId,
domain: "admin",
},
config.projectConfig.jwt_secret
)
headers.Authorization = `Bearer ${token}`
}
if (opts.clientSession) {
const token = jwt.sign(
{
customer_id:
opts.clientSession.customer_id || opts.clientSession.jwt?.customer_id,
domain: "store",
},
config.projectConfig.jwt_secret
)
headers.Authorization = `Bearer ${token}`
}
for (const name in headers) {
if ({}.hasOwnProperty.call(headers, name)) {
req.set(name, headers[name])
}
}
if (payload && !req.get("content-type")) {
req.set("Content-Type", "application/json")
}
if (!req.get("accept")) {
req.set("Accept", "application/json")
}
req.set("Host", "localhost")
let res
try {
res = await req.send(JSON.stringify(payload))
} catch (e) {
if (e.response) {
res = e.response
} else {
throw e
}
}
// let c =
// res.headers["set-cookie"] && cookie.parse(res.headers["set-cookie"][0])
// res.adminSession =
// c &&
// c[adminSessionOpts.cookieName] &&
// sessions.util.decode(adminSessionOpts, c[adminSessionOpts.cookieName])
// .content
// res.clientSession =
// c &&
// c[clientSessionOpts.cookieName] &&
// sessions.util.decode(clientSessionOpts, c[clientSessionOpts.cookieName])
// .content
return res
}
-6
View File
@@ -1,12 +1,6 @@
export * from "./interfaces"
export * from "./models"
export * from "./modules-config"
export * from "./services"
export * from "./types/batch-job"
export * from "./types/common" export * from "./types/common"
export * from "./types/global" export * from "./types/global"
export * from "./types/middlewares" export * from "./types/middlewares"
export * from "./types/routing" export * from "./types/routing"
export * from "./types/scheduled-jobs"
export * from "./types/subscribers" export * from "./types/subscribers"
export * from "./utils" export * from "./utils"
@@ -1,34 +0,0 @@
import { MockManager } from "medusa-test-utils"
import { TransactionBaseService } from "../transaction-base-service"
describe("TransactionBaseService", () => {
it("should cloned the child class withTransaction", () => {
class Child extends TransactionBaseService {
constructor(protected readonly container) {
super(container);
this.container = container
}
message() {
return `child class message method called with title ${this.container.title}`
}
getTransactionManager() {
return this.transactionManager_
}
}
const child = new Child({ title: 'title' })
expect(child.message()).toBe(`child class message method called with title title`)
expect(child.getTransactionManager()).toBeFalsy()
const fakeManager = MockManager
fakeManager.testProp = 'testProp'
const child2 = child.withTransaction(fakeManager)
expect(child2.message()).toBe(`child class message method called with title title`)
expect(child2.getTransactionManager()).toBeTruthy()
expect((child2.getTransactionManager() as any)?.testProp).toBe('testProp')
})
})
-3
View File
@@ -1,3 +0,0 @@
export * from "./models/base-entity"
export * from "./models/soft-deletable-entity"
export * from "./transaction-base-service"
@@ -1,20 +0,0 @@
import {
CreateDateColumn,
PrimaryColumn,
UpdateDateColumn,
} from "typeorm"
import { resolveDbType } from "../../utils/db-aware-column"
/**
* Base abstract entity for all entities
*/
export abstract class BaseEntity {
@PrimaryColumn()
id: string
@CreateDateColumn({ type: resolveDbType("timestamptz") })
created_at: Date
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
updated_at: Date
}
@@ -1,8 +0,0 @@
import { BaseEntity } from "./base-entity"
import { DeleteDateColumn } from "typeorm"
import { resolveDbType } from "../../utils/db-aware-column"
export abstract class SoftDeletableEntity extends BaseEntity {
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
deleted_at: Date | null
}
@@ -1,152 +0,0 @@
import { EntityManager } from "typeorm"
import { IsolationLevel } from "typeorm/driver/types/IsolationLevel"
export abstract class TransactionBaseService {
protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined
protected get activeManager_(): EntityManager {
return this.transactionManager_ ?? this.manager_
}
protected constructor(
protected readonly __container__: any,
protected readonly __configModule__?: Record<string, unknown>,
protected readonly __moduleDeclaration__?: Record<string, unknown>
) {
this.manager_ = __container__?.manager
}
withTransaction(transactionManager?: EntityManager): this {
if (!transactionManager) {
return this
}
const cloned = new (this.constructor as any)(
this.__container__,
this.__configModule__,
this.__moduleDeclaration__
)
cloned.manager_ = transactionManager
cloned.transactionManager_ = transactionManager
return cloned
}
protected shouldRetryTransaction_(
err: { code: string } | Record<string, unknown>
): boolean {
if (!(err as { code: string })?.code) {
return false
}
const code = (err as { code: string })?.code
return code === "40001" || code === "40P01"
}
/**
* Wraps some work within a transactional block. If the service already has
* a transaction manager attached this will be reused, otherwise a new
* transaction manager is created.
* @param work - the transactional work to be done
* @param isolationOrErrorHandler - the isolation level to be used for the work.
* @param maybeErrorHandlerOrDontFail Potential error handler
* @return the result of the transactional work
*/
protected async atomicPhase_<TResult, TError>(
work: (transactionManager: EntityManager) => Promise<TResult | never>,
isolationOrErrorHandler?:
| IsolationLevel
| ((error: TError) => Promise<never | TResult | void>),
maybeErrorHandlerOrDontFail?: (
error: TError
) => Promise<never | TResult | void>
): Promise<never | TResult> {
let errorHandler = maybeErrorHandlerOrDontFail
let isolation:
| IsolationLevel
| ((error: TError) => Promise<never | TResult | void>)
| undefined
| null = isolationOrErrorHandler
let dontFail = false
if (typeof isolationOrErrorHandler === "function") {
isolation = null
errorHandler = isolationOrErrorHandler
dontFail = !!maybeErrorHandlerOrDontFail
}
if (this.transactionManager_) {
const doWork = async (m: EntityManager): Promise<never | TResult> => {
this.manager_ = m
this.transactionManager_ = m
try {
return await work(m)
} catch (error) {
if (errorHandler) {
const queryRunner = this.transactionManager_.queryRunner
if (queryRunner && queryRunner.isTransactionActive) {
await queryRunner.rollbackTransaction()
}
await errorHandler(error)
}
throw error
}
}
return await doWork(this.transactionManager_)
} else {
const temp = this.manager_
const doWork = async (m: EntityManager): Promise<never | TResult> => {
this.manager_ = m
this.transactionManager_ = m
try {
const result = await work(m)
this.manager_ = temp
this.transactionManager_ = undefined
return result
} catch (error) {
this.manager_ = temp
this.transactionManager_ = undefined
throw error
}
}
if (isolation && this.manager_) {
let result
try {
result = await this.manager_.transaction(
isolation as IsolationLevel,
async (m) => doWork(m)
)
return result
} catch (error) {
if (this.shouldRetryTransaction_(error)) {
return this.manager_.transaction(
isolation as IsolationLevel,
async (m): Promise<never | TResult> => doWork(m)
)
} else {
if (errorHandler) {
await errorHandler(error)
}
throw error
}
}
}
try {
return await this.manager_.transaction(async (m) => doWork(m))
} catch (error) {
if (errorHandler) {
const result = await errorHandler(error)
if (dontFail) {
return result as TResult
}
}
throw error
}
}
}
}
@@ -1,47 +0,0 @@
import { asValue } from "awilix"
import { createMedusaContainer } from "medusa-core-utils"
import path from "path"
import modelsLoader from "../models"
describe.skip("models loader", () => {
const container = createMedusaContainer()
container.register("db_entities", asValue([]))
let models
let error
beforeAll(async () => {
try {
models = await modelsLoader({
container,
isTest: true,
coreTestPathGlob: "../models/{product,product-variant}.ts",
rootDirectory: path.join(__dirname, "__fixtures__/customizations"),
extensionPathGlob: "models/{product,product-variant}.ts",
})
} catch (e) {
error = e
}
})
it("error should be falsy & register 2 models", () => {
expect(error).toBeFalsy()
expect(models).toHaveLength(2)
})
it("ensure that the product model is an extended model", () => {
const productModel = models.find((model) => model.name === "Product")
expect(new productModel().custom_attribute).toEqual("test")
})
it("ensure that the extended product model is registered in db_entities", () => {
const entities = container.resolve("db_entities_STORE")
const productModelResolver = entities.find(
(entity) => entity.resolve().name === "Product"
)
const productModel = productModelResolver.resolve()
expect(new productModel().custom_attribute).toEqual("test")
})
})
@@ -1,304 +0,0 @@
import {
asValue,
AwilixContainer,
ClassOrFunctionReturning,
Resolver,
} from "awilix"
import { mkdirSync, rmSync, writeFileSync } from "fs"
import { createMedusaContainer } from "medusa-core-utils"
import { resolve } from "path"
import { DataSource, EntityManager } from "typeorm"
import Logger from "../logger"
import {
MEDUSA_PROJECT_NAME,
registerServices,
registerStrategies,
} from "../plugins"
// ***** TEMPLATES *****
const buildServiceTemplate = (name: string): string => {
return `
import { BaseService } from "medusa-interfaces"
export default class ${name}Service extends BaseService {}
`
}
const buildTransactionBaseServiceServiceTemplate = (name: string) => {
return `
import { TransactionBaseService } from "${resolve(
__dirname,
"../../interfaces"
)}"
export default class ${name}Service extends TransactionBaseService {}
`
}
/*const buildBatchJobStrategyTemplate = (name: string, type: string): string => {
return `
import { AbstractBatchJobStrategy } from "../../../../interfaces/batch-job-strategy"
class ${name}BatchStrategy extends AbstractBatchJobStrategy {
static identifier = '${name}-identifier';
static batchType = '${type}';
manager_
transactionManager_
validateContext(context) {
throw new Error("Method not implemented.")
}
processJob(batchJobId) {
throw new Error("Method not implemented.")
}
completeJob(batchJobId) {
throw new Error("Method not implemented.")
}
validateFile(fileLocation) {
throw new Error("Method not implemented.")
}
async buildTemplate() {
throw new Error("Method not implemented.")
}
}
export default ${name}BatchStrategy
`
}
const buildPriceSelectionStrategyTemplate = (name: string): string => {
return `
import { AbstractPriceSelectionStrategy } from "../../../../interfaces/price-selection-strategy"
class ${name}PriceSelectionStrategy extends AbstractPriceSelectionStrategy {
withTransaction() {
throw new Error("Method not implemented.");
}
calculateVariantPrice(variant_id, context) {
throw new Error("Method not implemented.");
}
}
export default ${name}PriceSelectionStrategy
`
}
const buildTaxCalcStrategyTemplate = (name: string): string => {
return `
import { AbstractTaxCalculationStrategy } from "../../../../interfaces/tax-calculation-strategy"
class ${name}TaxCalculationStrategy extends AbstractTaxCalculationStrategy {
calculate(items, taxLines, calculationContext) {
throw new Error("Method not implemented.")
}
}
export default ${name}TaxCalculationStrategy
`
}*/
// ***** UTILS *****
const distTestTargetDirectorPath = resolve(__dirname, "__pluginsLoaderTest__")
const getFolderTestTargetDirectoryPath = (folderName: string): string => {
return resolve(distTestTargetDirectorPath, folderName)
}
function asArray(
resolvers: (ClassOrFunctionReturning<unknown> | Resolver<unknown>)[]
): { resolve: (container: AwilixContainer) => unknown[] } {
return {
resolve: (container: AwilixContainer): unknown[] =>
resolvers.map((resolver) => container.build(resolver)),
}
}
// ***** TESTS *****
describe.skip("plugins loader", () => {
const container = createMedusaContainer()
container.register("logger", asValue(Logger))
container.register("manager", asValue(new EntityManager({} as DataSource)))
const pluginsDetails = {
resolve: resolve(__dirname, "__pluginsLoaderTest__"),
name: MEDUSA_PROJECT_NAME,
id: "fakeId",
options: {},
version: '"fakeVersion',
}
let err
afterAll(() => {
rmSync(distTestTargetDirectorPath, { recursive: true, force: true })
jest.clearAllMocks()
})
describe("registerStrategies", function () {
beforeAll(async () => {
mkdirSync(getFolderTestTargetDirectoryPath("strategies"), {
mode: "777",
recursive: true,
})
/*writeFileSync(
resolve(
getFolderTestTargetDirectoryPath("strategies"),
"test-batch-1.js"
),
buildBatchJobStrategyTemplate("testBatch1", "type-1")
)
writeFileSync(
resolve(
getFolderTestTargetDirectoryPath("strategies"),
"test-price-selection.js"
),
buildPriceSelectionStrategyTemplate("test")
)
writeFileSync(
resolve(
getFolderTestTargetDirectoryPath("strategies"),
"test-batch-2.js"
),
buildBatchJobStrategyTemplate("testBatch2", "type-1")
)
writeFileSync(
resolve(
getFolderTestTargetDirectoryPath("strategies"),
"test-batch-3.js"
),
buildBatchJobStrategyTemplate("testBatch3", "type-2")
)
writeFileSync(
resolve(getFolderTestTargetDirectoryPath("strategies"), "test-tax.js"),
buildTaxCalcStrategyTemplate("test")
)*/
try {
await registerStrategies(pluginsDetails, container)
} catch (e) {
err = e
}
})
afterAll(() => {
jest.clearAllMocks()
})
it("err should be falsy", () => {
expect(err).toBeFalsy()
})
it.skip("registers price selection strategy", () => {
const priceSelectionStrategy = container.resolve(
"priceSelectionStrategy"
) as (...args: unknown[]) => any
expect(priceSelectionStrategy).toBeTruthy()
expect(priceSelectionStrategy.constructor.name).toBe(
"testPriceSelectionStrategy"
)
})
it.skip("registers tax calculation strategy", () => {
const taxCalculationStrategy = container.resolve(
"taxCalculationStrategy"
) as (...args: unknown[]) => any
expect(taxCalculationStrategy).toBeTruthy()
expect(taxCalculationStrategy.constructor.name).toBe(
"testTaxCalculationStrategy"
)
})
it.skip("registers batch job strategies as single array", () => {
const batchJobStrategies = container.resolve("batchJobStrategies") as (
...args: unknown[]
) => any
expect(batchJobStrategies).toBeTruthy()
expect(Array.isArray(batchJobStrategies)).toBeTruthy()
expect(batchJobStrategies.length).toBe(3)
})
it.skip("registers batch job strategies by type and only keep the last", () => {
const batchJobStrategy = container.resolve("batchType_type-1") as (
...args: unknown[]
) => any
expect(batchJobStrategy).toBeTruthy()
expect(batchJobStrategy.constructor.name).toBe("testBatch2BatchStrategy")
expect((batchJobStrategy.constructor as any).batchType).toBe("type-1")
expect((batchJobStrategy.constructor as any).identifier).toBe(
"testBatch2-identifier"
)
})
it.skip("registers batch job strategies by identifier", () => {
const batchJobStrategy = container.resolve(
"batch_testBatch3-identifier"
) as (...args: unknown[]) => any
expect(batchJobStrategy).toBeTruthy()
expect(Array.isArray(batchJobStrategy)).toBeFalsy()
expect(batchJobStrategy.constructor.name).toBe("testBatch3BatchStrategy")
})
})
describe("registerServices", function () {
beforeAll(() => {
container.register("logger", asValue(Logger))
mkdirSync(getFolderTestTargetDirectoryPath("services"), {
mode: "777",
recursive: true,
})
writeFileSync(
resolve(getFolderTestTargetDirectoryPath("services"), "test.js"),
buildServiceTemplate("test")
)
writeFileSync(
resolve(getFolderTestTargetDirectoryPath("services"), "test2.js"),
buildServiceTemplate("test2")
)
writeFileSync(
resolve(getFolderTestTargetDirectoryPath("services"), "test3.js"),
buildTransactionBaseServiceServiceTemplate("test3")
)
writeFileSync(
resolve(getFolderTestTargetDirectoryPath("services"), "test2.js.map"),
"map:file"
)
writeFileSync(
resolve(getFolderTestTargetDirectoryPath("services"), "test2.d.ts"),
"export interface Test {}"
)
})
afterAll(() => {
jest.clearAllMocks()
})
it("should load the services from the services directory but only js files", async () => {
let err
try {
await registerServices(pluginsDetails, container)
} catch (e) {
err = e
}
expect(err).toBeFalsy()
const testService: (...args: unknown[]) => any =
container.resolve("testService")
const test2Service: (...args: unknown[]) => any =
container.resolve("test2Service")
const test3Service: (...args: unknown[]) => any =
container.resolve("test3Service")
expect(testService).toBeTruthy()
expect(testService.constructor.name).toBe("testService")
expect(test2Service).toBeTruthy()
expect(test2Service.constructor.name).toBe("test2Service")
expect(test3Service).toBeTruthy()
expect(test3Service.constructor.name).toBe("test3Service")
})
})
})
@@ -1,36 +0,0 @@
import { asValue } from "awilix"
import { createMedusaContainer } from "medusa-core-utils"
import path from "path"
import { registerPluginModels } from "../plugins"
import configModule from './__fixtures__/customizations/medusa-config'
describe.skip("plugin models loader", () => {
const container = createMedusaContainer()
container.register("db_entities", asValue([]))
let models
let error
beforeAll(async () => {
try {
await registerPluginModels({
configModule: configModule,
container,
rootDirectory: path.join(__dirname, '__fixtures__/customizations'),
extensionDirectoryPath: './',
pathGlob: "/models/*.ts",
})
} catch (e) {
error = e
}
})
it("ensure that the product model is registered from the user's respository", () => {
const entities = container.resolve("db_entities_STORE")
const productModelResolver = entities.find(entity => entity.resolve().name === 'Product')
const productModel = productModelResolver.resolve()
expect((new productModel()).custom_attribute).toEqual("test")
})
})
@@ -1,11 +0,0 @@
import { ScheduledJobArgs } from "../../../../../types/scheduled-jobs"
export default async function ({ container, pluginOptions }: ScheduledJobArgs) {
// noop
return {}
}
export const config = {
name: "every-hour",
schedule: "0 * * * *",
}
@@ -1,11 +0,0 @@
import { ScheduledJobArgs } from "../../../../../types/scheduled-jobs"
export default async function ({ container, pluginOptions }: ScheduledJobArgs) {
// noop
return {}
}
export const config = {
name: "every-minute",
schedule: "* * * * *",
}
@@ -1,16 +0,0 @@
export const jobSchedulerServiceMock = {
create: jest.fn().mockImplementation((...args) => {
return Promise.resolve(args)
}),
}
export const containerMock = {
// mock .resolve method so if its called with "jobSchedulerService" it returns the mock
resolve: jest.fn().mockImplementation((name: string) => {
if (name === "jobSchedulerService") {
return jobSchedulerServiceMock
} else {
return {}
}
}),
}
@@ -1,49 +0,0 @@
import { MedusaContainer } from "@medusajs/types"
import { join } from "path"
import { containerMock, jobSchedulerServiceMock } from "../__mocks__"
import ScheduledJobsLoader from "../index"
describe("ScheduledJobsLoader", () => {
const rootDir = join(__dirname, "../__fixtures__", "jobs")
const pluginOptions = {
important_data: {
enabled: true,
},
}
beforeAll(async () => {
jest.clearAllMocks()
await new ScheduledJobsLoader(
rootDir,
containerMock as unknown as MedusaContainer,
pluginOptions
).load()
})
it("should register every job in '/jobs'", async () => {
// As '/jobs' contains 2 jobs, we expect the create method to be called twice
expect(jobSchedulerServiceMock.create).toHaveBeenCalledTimes(2)
})
it("should register every job with the correct props", async () => {
// Registering every-hour.ts
expect(jobSchedulerServiceMock.create).toHaveBeenCalledWith(
"every-hour",
undefined,
"0 * * * *",
expect.any(Function),
{ keepExisting: false }
)
// Registering every-minute.ts
expect(jobSchedulerServiceMock.create).toHaveBeenCalledWith(
"every-minute",
undefined,
"* * * * *",
expect.any(Function),
{ keepExisting: false }
)
})
})
@@ -1,174 +0,0 @@
import { MedusaContainer } from "@medusajs/types"
import { readdir } from "fs/promises"
import { join } from "path"
import JobSchedulerService from "../../../services/job-scheduler"
import {
ScheduledJobArgs,
ScheduledJobConfig,
} from "../../../types/scheduled-jobs"
import logger from "../../logger"
type ScheduledJobHandler = (args: ScheduledJobArgs) => Promise<void>
type ScheduledJobModule = {
config: ScheduledJobConfig
handler: ScheduledJobHandler
}
export default class ScheduledJobsLoader {
protected container_: MedusaContainer
protected pluginOptions_: Record<string, unknown>
protected rootDir_: string
protected excludes: RegExp[] = [
/\.DS_Store/,
/(\.ts\.map|\.js\.map|\.d\.ts)/,
/^_[^/\\]*(\.[^/\\]+)?$/,
]
protected jobDescriptors_: Map<string, ScheduledJobModule> = new Map()
constructor(
rootDir: string,
container: MedusaContainer,
options: Record<string, unknown> = {}
) {
this.rootDir_ = rootDir
this.pluginOptions_ = options
this.container_ = container
}
private validateJob(
job: any,
path: string
): job is {
default: ScheduledJobHandler
config: ScheduledJobConfig
} {
const handler = job.default
if (!handler || typeof handler !== "function") {
logger.warn(`The job in ${path} is not a function.`)
return false
}
const config = job.config
if (!config) {
logger.warn(`The job in ${path} is missing a config.`)
return false
}
if (!config.schedule) {
logger.warn(`The job in ${path} is missing a schedule.`)
return false
}
if (!config.name) {
logger.warn(`The job in ${path} is missing a name.`)
return false
}
if (config.data && typeof config.data !== "object") {
logger.warn(`The job data in ${path} is not an object.`)
return false
}
return true
}
private async createDescriptor(absolutePath: string, entry: string) {
return await import(absolutePath).then((module_) => {
const isValid = this.validateJob(module_, absolutePath)
if (!isValid) {
return
}
this.jobDescriptors_.set(absolutePath, {
config: module_.config,
handler: module_.default,
})
})
}
private async createMap(dirPath: string) {
await Promise.all(
await readdir(dirPath, { withFileTypes: true }).then(async (entries) => {
return entries
.filter((entry) => {
if (
this.excludes.length &&
this.excludes.some((exclude) => exclude.test(entry.name))
) {
return false
}
return true
})
.map(async (entry) => {
const fullPath = join(dirPath, entry.name)
if (entry.isDirectory()) {
return this.createMap(fullPath)
}
return await this.createDescriptor(fullPath, entry.name)
})
})
)
}
private async createScheduledJobs() {
const jobs = Array.from(this.jobDescriptors_.values())
if (!jobs.length) {
return
}
const jobSchedulerService: JobSchedulerService = this.container_.resolve(
"jobSchedulerService"
)
for (const job of jobs) {
try {
const { name, data, schedule } = job.config
const handler = async () => {
await job.handler({
container: this.container_,
data,
pluginOptions: this.pluginOptions_,
})
}
await jobSchedulerService.create(name, data, schedule, handler, {
keepExisting: false, // For now, we do not support changing this flag
})
} catch (err) {
logger.error(
`An error occurred while registering job ${job.config.name}`,
err
)
}
}
}
async load(): Promise<void> {
let hasJobsDir = false
try {
await readdir(this.rootDir_)
hasJobsDir = true
} catch (_err) {
hasJobsDir = false
}
if (!hasJobsDir) {
return
}
await this.createMap(this.rootDir_)
await this.createScheduledJobs()
}
}
@@ -4,8 +4,8 @@ import fs from "fs"
import { sync as existsSync } from "fs-exists-cached" import { sync as existsSync } from "fs-exists-cached"
import { createRequireFromPath } from "medusa-core-utils" import { createRequireFromPath } from "medusa-core-utils"
import path from "path" import path from "path"
import { MEDUSA_PROJECT_NAME } from "../plugins"
export const MEDUSA_PROJECT_NAME = "project-plugin"
function createPluginId(name: string): string { function createPluginId(name: string): string {
return name return name
} }
@@ -12,11 +12,7 @@ import querystring from "querystring"
import supertest from "supertest" import supertest from "supertest"
import apiLoader from "../../../../api" import apiLoader from "../../../../api"
import featureFlagLoader, { featureFlagRouter } from "../../../../feature-flags" import featureFlagLoader, { featureFlagRouter } from "../../../../feature-flags"
import modelsLoader from "../../../../models"
import passportLoader from "../../../../passport" import passportLoader from "../../../../passport"
import repositoriesLoader from "../../../../repositories"
import servicesLoader from "../../../../services"
import strategiesLoader from "../../../../strategies"
import RoutesLoader from "../.." import RoutesLoader from "../.."
import { config } from "../mocks" import { config } from "../mocks"
@@ -88,10 +84,6 @@ export const createServer = async (rootDir) => {
}) })
featureFlagLoader(config) featureFlagLoader(config)
modelsLoader({ container, isTest: true })
repositoriesLoader({ container, isTest: true })
servicesLoader({ container, configModule: config })
strategiesLoader({ container, configModule: config })
await passportLoader({ app: app, container, configModule: config }) await passportLoader({ app: app, container, configModule: config })
await moduleLoader({ container, moduleResolutions }) await moduleLoader({ container, moduleResolutions })
@@ -4,9 +4,9 @@ import { kebabCase } from "@medusajs/utils"
import { readdir } from "fs/promises" import { readdir } from "fs/promises"
import { extname, join, sep } from "path" import { extname, join, sep } from "path"
import { EventBusService } from "../../../services"
import { SubscriberArgs, SubscriberConfig } from "../../../types/subscribers" import { SubscriberArgs, SubscriberConfig } from "../../../types/subscribers"
import logger from "../../logger" import logger from "../../logger"
import { IEventBusModuleService } from "@medusajs/types"
type SubscriberHandler<T> = (args: SubscriberArgs<T>) => Promise<void> type SubscriberHandler<T> = (args: SubscriberArgs<T>) => Promise<void>
@@ -185,7 +185,7 @@ export class SubscriberLoader {
config: SubscriberConfig config: SubscriberConfig
handler: SubscriberHandler<T> handler: SubscriberHandler<T>
}) { }) {
const eventBusService: EventBusService = this.container_.resolve( const eventBusService: IEventBusModuleService = this.container_.resolve(
ModuleRegistrationName.EVENT_BUS ModuleRegistrationName.EVENT_BUS
) )
@@ -5,7 +5,6 @@ import { trackInstallation } from "medusa-telemetry"
import { EOL } from "os" import { EOL } from "os"
import path from "path" import path from "path"
import { ConfigModule, Logger, MedusaContainer } from "../types/global" import { ConfigModule, Logger, MedusaContainer } from "../types/global"
import ScheduledJobsLoader from "./helpers/jobs"
import { getResolvedPlugins } from "./helpers/resolve-plugins" import { getResolvedPlugins } from "./helpers/resolve-plugins"
import { RoutesLoader } from "./helpers/routing" import { RoutesLoader } from "./helpers/routing"
import { SubscriberLoader } from "./helpers/subscribers" import { SubscriberLoader } from "./helpers/subscribers"
@@ -65,7 +64,8 @@ export default async ({
if (configModule.projectConfig.redis_url) { if (configModule.projectConfig.redis_url) {
await Promise.all( await Promise.all(
resolved.map(async (pluginDetails) => { resolved.map(async (pluginDetails) => {
await registerScheduledJobs(pluginDetails, container) // await registerScheduledJobs(pluginDetails, container)
// TODO: Decide how scheduled jobs will be loaded and handled
}) })
) )
} else { } else {
@@ -101,17 +101,6 @@ async function runLoaders(
) )
} }
async function registerScheduledJobs(
pluginDetails: PluginDetails,
container: MedusaContainer
): Promise<void> {
await new ScheduledJobsLoader(
path.join(pluginDetails.resolve, "jobs"),
container,
pluginDetails.options
).load()
}
/** /**
* Registers the plugin's api routes. * Registers the plugin's api routes.
*/ */
@@ -16,7 +16,6 @@ import {
} from "@medusajs/types" } from "@medusajs/types"
import { import {
ContainerRegistrationKeys, ContainerRegistrationKeys,
FlagRouter,
isObject, isObject,
upperCaseFirst, upperCaseFirst,
} from "@medusajs/utils" } from "@medusajs/utils"
-87
View File
@@ -1,87 +0,0 @@
import {
formatRegistrationName,
formatRegistrationNameWithoutNamespace,
} from "../utils/format-registration-name"
import { getModelExtensionsMap } from "./helpers/get-model-extension-map"
import glob from "glob"
import path from "path"
import { ClassConstructor, MedusaContainer } from "../types/global"
import { EntitySchema } from "typeorm"
import { asClass, asValue } from "awilix"
type ModelLoaderParams = {
container: MedusaContainer
isTest?: boolean
rootDirectory?: string
corePathGlob?: string
coreTestPathGlob?: string
extensionPathGlob?: string
}
/**
* Registers all models in the model directory
*/
export default (
{
container,
isTest,
rootDirectory,
corePathGlob = "../models/*.js",
coreTestPathGlob = "../models/*.ts",
extensionPathGlob = "dist/models/*.js",
}: ModelLoaderParams,
config = { register: true }
) => {
const coreModelsGlob = isTest ? coreTestPathGlob : corePathGlob
const coreModelsFullGlob = path.join(__dirname, coreModelsGlob)
const models: (ClassConstructor<unknown> | EntitySchema)[] = []
const coreModels = glob.sync(coreModelsFullGlob, {
cwd: __dirname,
ignore: ["index.js", "index.ts", "index.js.map"],
})
const modelExtensionsMap = getModelExtensionsMap({
directory: rootDirectory,
pathGlob: extensionPathGlob,
config,
})
coreModels.forEach((modelPath) => {
const loaded = require(modelPath) as
| ClassConstructor<unknown>
| EntitySchema
if (loaded) {
Object.entries(loaded).map(
([, val]: [string, ClassConstructor<unknown> | EntitySchema]) => {
if (typeof val === "function" || val instanceof EntitySchema) {
if (config.register) {
const name = formatRegistrationName(modelPath)
const mappedExtensionModel = modelExtensionsMap.get(name)
// If an extension file is found, override it with that instead
if (mappedExtensionModel) {
const coreModel = require(modelPath)
const modelName =
formatRegistrationNameWithoutNamespace(modelPath)
coreModel[modelName] = mappedExtensionModel
val = mappedExtensionModel
}
container.register({
[name]: asClass(val as ClassConstructor<unknown>),
})
container.registerAdd("db_entities", asValue(val))
}
models.push(val)
}
}
)
}
})
return models
}
-705
View File
@@ -1,705 +0,0 @@
import {
AbstractSearchService,
promiseAll,
upperCaseFirst,
} from "@medusajs/utils"
import { aliasTo, asFunction, asValue, Lifetime } from "awilix"
import { Express } from "express"
import glob from "glob"
import { OauthService } from "medusa-interfaces"
import { trackInstallation } from "medusa-telemetry"
import { EOL } from "os"
import path from "path"
import { EntitySchema } from "typeorm"
import { MiddlewareService } from "../services"
import {
ClassConstructor,
ConfigModule,
Logger,
MedusaContainer,
} from "../types/global"
import {
formatRegistrationName,
formatRegistrationNameWithoutNamespace,
} from "../utils/format-registration-name"
import { getModelExtensionsMap } from "./helpers/get-model-extension-map"
import ScheduledJobsLoader from "./helpers/jobs"
import { getResolvedPlugins } from "./helpers/resolve-plugins"
import { RoutesLoader } from "./helpers/routing"
import { SubscriberLoader } from "./helpers/subscribers"
import logger from "./logger"
type Options = {
rootDirectory: string
container: MedusaContainer
configModule: ConfigModule
app: Express
activityId: string
}
type PluginDetails = {
resolve: string
name: string
id: string
options: Record<string, unknown>
version: string
}
export const isSearchEngineInstalledResolutionKey = "isSearchEngineInstalled"
export const MEDUSA_PROJECT_NAME = "project-plugin"
/**
* Registers all services in the services directory
*/
export default async ({
rootDirectory,
container,
app,
configModule,
activityId,
}: Options): Promise<void> => {
const resolved = getResolvedPlugins(rootDirectory, configModule) || []
await promiseAll(
resolved.map(
async (pluginDetails) => await runSetupFunctions(pluginDetails)
)
)
await promiseAll(
resolved.map(async (pluginDetails) => {
registerRepositories(pluginDetails, container)
await registerServices(pluginDetails, container)
await registerMedusaApi(pluginDetails, container)
await registerApi(
pluginDetails,
app,
rootDirectory,
container,
configModule,
activityId
)
registerCoreRouters(pluginDetails, container)
await registerSubscribers(pluginDetails, container, activityId)
await registerWorkflows(pluginDetails)
})
)
await promiseAll(
resolved.map(async (pluginDetails) => runLoaders(pluginDetails, container))
)
if (configModule.projectConfig.redis_url) {
await Promise.all(
resolved.map(async (pluginDetails) => {
await registerScheduledJobs(pluginDetails, container)
})
)
} else {
logger.warn(
"You don't have Redis configured. Scheduled jobs will not be enabled."
)
}
resolved.forEach((plugin) => trackInstallation(plugin.name, "plugin"))
}
export async function registerPluginModels({
rootDirectory,
container,
configModule,
extensionDirectoryPath = "dist",
pathGlob = "/models/*.js",
}: {
rootDirectory: string
container: MedusaContainer
configModule: ConfigModule
extensionDirectoryPath?: string
pathGlob?: string
}): Promise<void> {
const resolved =
getResolvedPlugins(rootDirectory, configModule, extensionDirectoryPath) ||
[]
await promiseAll(
resolved.map(async (pluginDetails) => {
registerModels(pluginDetails, container, rootDirectory, pathGlob)
})
)
}
async function runLoaders(
pluginDetails: PluginDetails,
container: MedusaContainer
): Promise<void> {
const loaderFiles = glob.sync(
`${pluginDetails.resolve}/loaders/[!__]*.js`,
{}
)
await promiseAll(
loaderFiles.map(async (loader) => {
try {
const module = require(loader).default
if (typeof module === "function") {
await module(container, pluginDetails.options)
}
} catch (err) {
const logger = container.resolve<Logger>("logger")
logger.warn(`Running loader failed: ${err.message}`)
return Promise.resolve()
}
})
)
}
async function registerScheduledJobs(
pluginDetails: PluginDetails,
container: MedusaContainer
): Promise<void> {
await new ScheduledJobsLoader(
path.join(pluginDetails.resolve, "jobs"),
container,
pluginDetails.options
).load()
}
async function registerMedusaApi(
pluginDetails: PluginDetails,
container: MedusaContainer
): Promise<void> {
registerMedusaMiddleware(pluginDetails, container)
registerStrategies(pluginDetails, container)
}
export function registerStrategies(
pluginDetails: PluginDetails,
container: MedusaContainer
): void {
const files = glob.sync(`${pluginDetails.resolve}/strategies/[!__]*.js`, {
ignore: ["**/__fixtures__/**", "**/index.js", "**/index.ts"],
})
const registeredServices = {}
files.map((file) => {
const module = require(file).default
switch (true) {
/* case AbstractTaxCalculationStrategy.isTaxCalculationStrategy(
module.prototype
): {
if (!("taxCalculationStrategy" in registeredServices)) {
container.register({
taxCalculationStrategy: asFunction(
(cradle) => new module(cradle, pluginDetails.options)
).singleton(),
})
registeredServices["taxCalculationStrategy"] = file
} else {
logger.warn(
`Cannot register ${file}. A tax calculation strategy is already registered`
)
}
break
}*/
/* case AbstractCartCompletionStrategy.isCartCompletionStrategy(
module.prototype
): {
if (!("cartCompletionStrategy" in registeredServices)) {
container.register({
cartCompletionStrategy: asFunction(
(cradle) => new module(cradle, pluginDetails.options)
).singleton(),
})
registeredServices["cartCompletionStrategy"] = file
} else {
logger.warn(
`Cannot register ${file}. A cart completion strategy is already registered`
)
}
break
}*/
/* case AbstractBatchJobStrategy.isBatchJobStrategy(module.prototype): {
container.registerAdd(
"batchJobStrategies",
asFunction((cradle) => new module(cradle, pluginDetails.options))
)
const name = formatRegistrationName(file)
container.register({
[name]: asFunction(
(cradle) => new module(cradle, pluginDetails.options)
).singleton(),
[`batch_${module.identifier}`]: aliasTo(name),
[`batchType_${module.batchType}`]: aliasTo(name),
})
break
}*/
/* case AbstractPriceSelectionStrategy.isPriceSelectionStrategy(
module.prototype
): {
if (!("priceSelectionStrategy" in registeredServices)) {
container.register({
priceSelectionStrategy: asFunction(
(cradle) => new module(cradle, pluginDetails.options)
).singleton(),
})
registeredServices["priceSelectionStrategy"] = file
} else {
logger.warn(
`Cannot register ${file}. A price selection strategy is already registered`
)
}
break
}*/
default:
logger.warn(
`${file} did not export a class that implements a strategy interface. Your Medusa server will still work, but if you have written custom strategy logic it will not be used. Make sure to implement the proper interface.`
)
}
})
}
function registerMedusaMiddleware(
pluginDetails: PluginDetails,
container: MedusaContainer
): void {
let module
try {
module = require(`${pluginDetails.resolve}/api/medusa-middleware`).default
} catch (err) {
return
}
const middlewareService =
container.resolve<MiddlewareService>("middlewareService")
if (module.postAuthentication) {
middlewareService.addPostAuthentication(
module.postAuthentication,
pluginDetails.options
)
}
if (module.preAuthentication) {
middlewareService.addPreAuthentication(
module.preAuthentication,
pluginDetails.options
)
}
if (module.preCartCreation) {
middlewareService.addPreCartCreation(module.preCartCreation)
}
}
function registerCoreRouters(
pluginDetails: PluginDetails,
container: MedusaContainer
): void {
const middlewareService =
container.resolve<MiddlewareService>("middlewareService")
const { resolve } = pluginDetails
const adminFiles = glob.sync(`${resolve}/api/admin/[!__]*.js`, {})
const storeFiles = glob.sync(`${resolve}/api/store/[!__]*.js`, {})
adminFiles.forEach((fn) => {
const descriptor = fn.split(".")[0]
const splat = descriptor.split("/")
const path = `${splat[splat.length - 2]}/${splat[splat.length - 1]}`
const loaded = require(fn).default
if (loaded && typeof loaded === "function") {
middlewareService.addRouter(path, loaded())
}
})
storeFiles.forEach((fn) => {
const descriptor = fn.split(".")[0]
const splat = descriptor.split("/")
const path = `${splat[splat.length - 2]}/${splat[splat.length - 1]}`
const loaded = require(fn).default
if (loaded && typeof loaded === "function") {
middlewareService.addRouter(path, loaded())
}
})
}
/**
* Registers the plugin's api routes.
*/
async function registerApi(
pluginDetails: PluginDetails,
app: Express,
rootDirectory = "",
container: MedusaContainer,
configmodule: ConfigModule,
activityId: string
): Promise<Express> {
const logger = container.resolve<Logger>("logger")
const projectName =
pluginDetails.name === MEDUSA_PROJECT_NAME
? "your Medusa project"
: `${pluginDetails.name}`
logger.progress(activityId, `Registering custom endpoints for ${projectName}`)
try {
/**
* Register the plugin's API routes using the file based routing.
*/
await new RoutesLoader({
app,
rootDir: path.join(pluginDetails.resolve, "api"),
activityId: activityId,
configModule: configmodule,
}).load()
} catch (err) {
logger.warn(
`An error occurred while registering API Routes in ${projectName}${
err.stack ? EOL + err.stack : ""
}`
)
}
try {
/**
* For backwards compatibility we also support loading routes from
* `/api/index` if the file exists.
*/
let apiFolderExists = true
try {
require.resolve(`${pluginDetails.resolve}/api`)
} catch (e) {
apiFolderExists = false
}
if (apiFolderExists) {
const routes = require(`${pluginDetails.resolve}/api`).default
if (routes) {
app.use("/", routes(rootDirectory, pluginDetails.options))
}
}
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") {
logger.warn(
`An error occurred while registering endpoints in ${projectName}`
)
if (err.stack) {
logger.warn(`${err.stack}`)
}
}
}
return app
}
/**
* Registers a service at the right location in our container.
* PaymentService instances are added to the paymentProviders array in the
* container. Names are camelCase formatted and namespaced by the folder i.e:
* services/example-payments -> examplePaymentsService
* @param {object} pluginDetails - the plugin details including plugin options,
* version, id, resolved path, etc. See resolvePlugin
* @param {object} container - the container where the services will be
* registered
* @return {void}
*/
export async function registerServices(
pluginDetails: PluginDetails,
container: MedusaContainer
): Promise<void> {
const files = glob.sync(`${pluginDetails.resolve}/services/[!__]*.js`, {})
await promiseAll(
files.map(async (fn) => {
const loaded = require(fn).default
const name = formatRegistrationName(fn)
if (typeof loaded !== "function") {
throw new Error(
`Cannot register ${name}. Make sure to default export a service class in ${fn}`
)
}
const context = { container, pluginDetails, registrationName: name }
if (OauthService.isOauthService(loaded.prototype)) {
const appDetails = loaded.getAppDetails(pluginDetails.options)
const oauthService =
container.resolve<typeof OauthService>("oauthService")
await oauthService.registerOauthApp(appDetails)
const name = appDetails.application_name
container.register({
[`${name}Oauth`]: asFunction(
(cradle) => new loaded(cradle, pluginDetails.options),
{
lifetime: loaded.LIFE_TIME || Lifetime.SINGLETON,
}
),
})
} /* else if (
AbstractNotificationService.isNotificationService(loaded.prototype)
) {
container.registerAdd(
"notificationProviders",
asFunction((cradle) => new loaded(cradle, pluginDetails.options), {
lifetime: loaded.LIFE_TIME || Lifetime.SINGLETON,
})
)
// Add the service directly to the container in order to make simple
// resolution if we already know which notification provider we need to use
container.register({
[name]: asFunction(
(cradle) => new loaded(cradle, pluginDetails.options),
{
lifetime: loaded.LIFE_TIME || Lifetime.SINGLETON,
}
),
[`noti_${loaded.identifier}`]: aliasTo(name),
})
}*/ /* else if (AbstractFileService.isFileService(loaded.prototype)) {
// Add the service directly to the container in order to make simple
// resolution if we already know which file storage provider we need to use
container.register({
[name]: asFunction(
(cradle) => new loaded(cradle, pluginDetails.options),
{
lifetime: loaded.LIFE_TIME || Lifetime.SINGLETON,
}
),
[`fileService`]: aliasTo(name),
})
}*/ else if (AbstractSearchService.isSearchService(loaded.prototype)) {
// Add the service directly to the container in order to make simple
// resolution if we already know which search provider we need to use
container.register({
[name]: asFunction(
(cradle) => new loaded(cradle, pluginDetails.options),
{
lifetime: loaded.LIFE_TIME || Lifetime.SINGLETON,
}
),
[`searchService`]: aliasTo(name),
})
container.register(isSearchEngineInstalledResolutionKey, asValue(true))
} /* else if (AbstractTaxService.isTaxService(loaded.prototype)) {
container.registerAdd(
"taxProviders",
asFunction((cradle) => new loaded(cradle, pluginDetails.options), {
lifetime: loaded.LIFE_TIME || Lifetime.SINGLETON,
})
)
container.register({
[name]: asFunction(
(cradle) => new loaded(cradle, pluginDetails.options),
{
lifetime: loaded.LIFE_TIME || Lifetime.SINGLETON,
}
),
[`tp_${loaded.identifier}`]: aliasTo(name),
})
}*/ else {
container.register({
[name]: asFunction(
(cradle) => new loaded(cradle, pluginDetails.options),
{
lifetime: loaded.LIFE_TIME || Lifetime.SCOPED,
}
),
})
}
})
)
}
/**
* Registers a plugin's subscribers at the right location in our container.
* Subscribers are registered directly in the container.
* @param {object} pluginDetails - the plugin details including plugin options,
* version, id, resolved path, etc. See resolvePlugin
* @param {object} container - the container where the services will be
* registered
* @return {void}
*/
async function registerSubscribers(
pluginDetails: PluginDetails,
container: MedusaContainer,
activityId: string
): Promise<void> {
const loadedFiles = await new SubscriberLoader(
path.join(pluginDetails.resolve, "subscribers"),
container,
pluginDetails.options,
activityId
).load()
/**
* Exclude any files that have already been loaded by the subscriber loader
*/
const normalizedLoadedFiles =
loadedFiles?.map((file) => file.replace(/\\/g, "/")) ?? []
const files = glob.sync(`${pluginDetails.resolve}/subscribers/*.js`, {})
files
.filter((file) => !normalizedLoadedFiles.includes(file))
.forEach((fn) => {
const loaded = require(fn).default
container.build(
asFunction(
(cradle) => new loaded(cradle, pluginDetails.options)
).singleton()
)
})
}
/**
* Registers a plugin's repositories at the right location in our container.
* repositories are registered directly in the container.
* @param {object} pluginDetails - the plugin details including plugin options,
* version, id, resolved path, etc. See resolvePlugin
* @param {object} container - the container where the services will be
* registered
* @return {void}
*/
function registerRepositories(
pluginDetails: PluginDetails,
container: MedusaContainer
): void {
const files = glob.sync(`${pluginDetails.resolve}/repositories/*.js`, {})
files.forEach((fn) => {
const loaded = require(fn)
Object.entries(loaded).map(([, val]: [string, any]) => {
if (typeof loaded === "object") {
const name = formatRegistrationName(fn)
container.register({
[name]: asValue(val),
})
}
})
})
}
/**
* import files from the workflows directory to run the registration of the wofklows
* @param pluginDetails
*/
async function registerWorkflows(pluginDetails: PluginDetails): Promise<void> {
const files = glob.sync(`${pluginDetails.resolve}/workflows/*.js`, {})
await Promise.all(files.map(async (file) => import(file)))
}
/**
* Registers a plugin's models at the right location in our container. Models
* must inherit from BaseModel. Models are registered directly in the container.
* Names are camelCase formatted and namespaced by the folder i.e:
* models/example-person -> examplePersonModel
* @param {object} pluginDetails - the plugin details including plugin options,
* version, id, resolved path, etc. See resolvePlugin
* @param {object} container - the container where the services will be
* registered
* @param rootDirectory
* @param pathGlob
* @return {void}
*/
function registerModels(
pluginDetails: PluginDetails,
container: MedusaContainer,
rootDirectory: string,
pathGlob = "/models/*.js"
): void {
const pluginFullPathGlob = path.join(pluginDetails.resolve, pathGlob)
const modelExtensionsMap = getModelExtensionsMap({
directory: pluginDetails.resolve,
pathGlob: pathGlob,
config: { register: true },
})
const pluginModels = glob.sync(pluginFullPathGlob, {
ignore: ["index.js", "index.js.map"],
})
const coreModelsFullGlob = path.join(__dirname, "../models/*.js")
const coreModels = glob.sync(coreModelsFullGlob, {
cwd: __dirname,
ignore: ["index.js", "index.ts", "index.js.map"],
})
// Apply the extended models to the core models first to ensure that
// when relationships are created, the extended models are used
coreModels.forEach((modelPath) => {
const loaded = require(modelPath) as
| ClassConstructor<unknown>
| EntitySchema
if (loaded) {
const name = formatRegistrationName(modelPath)
const mappedExtensionModel = modelExtensionsMap.get(name)
if (mappedExtensionModel) {
const modelName = upperCaseFirst(
formatRegistrationNameWithoutNamespace(modelPath)
)
loaded[modelName] = mappedExtensionModel
}
}
})
pluginModels.forEach((coreOrPluginModelPath) => {
const loaded = require(coreOrPluginModelPath) as
| ClassConstructor<unknown>
| EntitySchema
if (loaded) {
Object.entries(loaded).map(
([, val]: [string, ClassConstructor<unknown> | EntitySchema]) => {
if (typeof val === "function" || val instanceof EntitySchema) {
const name = formatRegistrationName(coreOrPluginModelPath)
container.register({
[name]: asValue(val),
})
container.registerAdd("db_entities", asValue(val))
}
}
)
}
})
}
/**
* Runs all setup functions in a plugin. Setup functions are run before anything from the plugin is
* registered to the container. This is useful for running custom build logic, fetching remote
* configurations, etc.
* @param pluginDetails The plugin details including plugin options, version, id, resolved path, etc.
*/
async function runSetupFunctions(pluginDetails: PluginDetails): Promise<void> {
const files = glob.sync(`${pluginDetails.resolve}/setup/*.js`, {})
await promiseAll(
files.map(async (fn) => {
const loaded = require(fn).default
try {
await loaded()
} catch (err) {
throw new Error(
`A setup function from ${pluginDetails.name} failed. ${err}`
)
}
})
)
}
@@ -1,32 +0,0 @@
import glob from "glob"
import path from "path"
import formatRegistrationName from "../utils/format-registration-name"
import { MedusaContainer } from "../types/global"
import { asValue } from "awilix"
/**
* Registers all models in the model directory
*/
export default ({
container,
isTest,
}: {
container: MedusaContainer
isTest?: boolean
}): void => {
const corePath = isTest ? "../repositories/*.ts" : "../repositories/*.js"
const coreFull = path.join(__dirname, corePath)
const core = glob.sync(coreFull, { cwd: __dirname })
core.forEach((fn) => {
const loaded = require(fn).default
if (typeof loaded === "object") {
const name = formatRegistrationName(fn)
container.register({
[name]: asValue(loaded),
})
}
})
}
@@ -1,35 +0,0 @@
import { EventBusService } from "../services"
import { Logger, MedusaContainer } from "../types/global"
export const SEARCH_INDEX_EVENT = "SEARCH_INDEX_EVENT"
async function loadProductsIntoSearchEngine(
container: MedusaContainer
): Promise<void> {
const logger: Logger = container.resolve<Logger>("logger")
const eventBusService: EventBusService = container.resolve("eventBusService")
void eventBusService.emit(SEARCH_INDEX_EVENT, {}).catch((err) => {
logger.error(err)
logger.error(
"Something went wrong while emitting the search indexing event."
)
})
}
export default async ({
container,
}: {
container: MedusaContainer
}): Promise<void> => {
// const searchService =
// container.resolve<AbstractSearchService>("searchService")
// const logger = container.resolve<Logger>("logger")
// if (searchService.isDefault) {
// logger.warn(
// "No search engine provider was found: make sure to include a search plugin to enable searching"
// )
// return
// }
await loadProductsIntoSearchEngine(container)
}
-35
View File
@@ -1,35 +0,0 @@
import { asFunction } from "awilix"
import glob from "glob"
import { isDefined } from "medusa-core-utils"
import path from "path"
import { ConfigModule, MedusaContainer } from "../types/global"
import formatRegistrationName from "../utils/format-registration-name"
type Options = {
container: MedusaContainer
configModule: ConfigModule
isTest?: boolean
}
/**
* Registers all services in the services directory
*/
export default ({ container, configModule, isTest }: Options): void => {
const useMock = isDefined(isTest) ? isTest : process.env.NODE_ENV === "test"
const corePath = useMock ? "../services/__mocks__/*.js" : "../services/*.js"
const coreFull = path.join(__dirname, corePath)
const core = glob.sync(coreFull, { cwd: __dirname })
core.forEach((fn) => {
const loaded = require(fn).default
if (loaded) {
const name = formatRegistrationName(fn)
container.register({
[name]: asFunction(
(cradle) => new loaded(cradle, configModule)
).singleton(),
})
}
})
}
-58
View File
@@ -1,58 +0,0 @@
import glob from "glob"
import path from "path"
import { aliasTo, asFunction } from "awilix"
import formatRegistrationName from "../utils/format-registration-name"
import { MedusaContainer } from "../types/global"
import { isDefined } from "medusa-core-utils"
/*import { AbstractBatchJobStrategy } from "../interfaces"*/
type LoaderOptions = {
container: MedusaContainer
configModule: object
isTest?: boolean
}
/**
* Registers all strategies in the strategies directory
* @returns void
*/
export default ({ container, configModule, isTest }: LoaderOptions): void => {
const useMock = isDefined(isTest) ? isTest : process.env.NODE_ENV === "test"
const corePath = useMock
? "../strategies/__mocks__/[!__]*.js"
: "../strategies/**/[!__]*.js"
const coreFull = path.join(__dirname, corePath)
const ignore = [
"**/__fixtures__/**",
"**/index.js",
"**/index.ts",
"**/utils.js",
"**/utils.ts",
"**/types.js",
"**/types.ts",
"**/types/**",
]
if (!useMock) {
ignore.push("**/__tests__/**", "**/__mocks__/**")
}
const core = glob.sync(coreFull, {
cwd: __dirname,
ignore,
})
core.forEach((fn) => {
const loaded = require(fn).default
const name = formatRegistrationName(fn)
container.register({
[name]: asFunction(
(cradle) => new loaded(cradle, configModule)
).singleton(),
})
})
}
@@ -1,382 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class initialSchema1611063162649 implements MigrationInterface {
name = 'initialSchema1611063162649'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "fulfillment_provider" ("id" character varying NOT NULL, "is_installed" boolean NOT NULL DEFAULT true, CONSTRAINT "PK_beb35a6de60a6c4f91d5ae57e44" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "fulfillment_item" ("fulfillment_id" character varying NOT NULL, "item_id" character varying NOT NULL, "quantity" integer NOT NULL, CONSTRAINT "PK_bc3e8a388de75db146a249922e0" PRIMARY KEY ("fulfillment_id", "item_id"))`);
await queryRunner.query(`CREATE TABLE "fulfillment" ("id" character varying NOT NULL, "swap_id" character varying, "order_id" character varying, "tracking_numbers" jsonb NOT NULL DEFAULT '[]', "data" jsonb NOT NULL, "shipped_at" TIMESTAMP WITH TIME ZONE, "canceled_at" TIMESTAMP WITH TIME ZONE, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, "idempotency_key" character varying, "provider_id" character varying, CONSTRAINT "PK_50c102da132afffae660585981f" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "return_item" ("return_id" character varying NOT NULL, "item_id" character varying NOT NULL, "quantity" integer NOT NULL, "is_requested" boolean NOT NULL DEFAULT true, "requested_quantity" integer, "received_quantity" integer, "metadata" jsonb, CONSTRAINT "PK_46409dc1dd5f38509b9000c3069" PRIMARY KEY ("return_id", "item_id"))`);
await queryRunner.query(`CREATE TABLE "currency" ("code" character varying NOT NULL, "symbol" character varying NOT NULL, "symbol_native" character varying NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_723472e41cae44beb0763f4039c" PRIMARY KEY ("code"))`);
await queryRunner.query(`CREATE TABLE "country" ("id" SERIAL NOT NULL, "iso_2" character varying NOT NULL, "iso_3" character varying NOT NULL, "num_code" integer NOT NULL, "name" character varying NOT NULL, "display_name" character varying NOT NULL, "region_id" character varying, CONSTRAINT "PK_bf6e37c231c4f4ea56dcd887269" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_e78901b1131eaf8203d9b1cb5f" ON "country" ("iso_2") `);
await queryRunner.query(`CREATE TABLE "payment_provider" ("id" character varying NOT NULL, "is_installed" boolean NOT NULL DEFAULT true, CONSTRAINT "PK_ea94f42b6c88e9191c3649d7522" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "region" ("id" character varying NOT NULL, "name" character varying NOT NULL, "currency_code" character varying NOT NULL, "tax_rate" numeric NOT NULL, "tax_code" character varying, "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_5f48ffc3af96bc486f5f3f3a6da" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "image" ("id" character varying NOT NULL, "url" character varying NOT NULL, "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_d6db1ab4ee9ad9dbe86c64e4cc3" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "money_amount" ("id" character varying NOT NULL, "currency_code" character varying NOT NULL, "amount" integer NOT NULL, "sale_amount" integer DEFAULT null, "variant_id" character varying, "region_id" character varying, "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, CONSTRAINT "PK_022e49a7e21a8dfb820f788778a" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "product_variant" ("id" character varying NOT NULL, "title" character varying NOT NULL, "product_id" character varying NOT NULL, "sku" character varying, "barcode" character varying, "ean" character varying, "upc" character varying, "inventory_quantity" integer NOT NULL, "allow_backorder" boolean NOT NULL DEFAULT false, "manage_inventory" boolean NOT NULL DEFAULT true, "hs_code" character varying, "origin_country" character varying, "mid_code" character varying, "material" character varying, "weight" integer, "length" integer, "height" integer, "width" integer, "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_1ab69c9935c61f7c70791ae0a9f" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f4dc2c0888b66d547c175f090e" ON "product_variant" ("sku") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_9db95c4b71f632fc93ecbc3d8b" ON "product_variant" ("barcode") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_7124082c8846a06a857cca386c" ON "product_variant" ("ean") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a0a3f124dc5b167622217fee02" ON "product_variant" ("upc") `);
await queryRunner.query(`CREATE TABLE "product_option_value" ("id" character varying NOT NULL, "value" character varying NOT NULL, "option_id" character varying NOT NULL, "variant_id" character varying NOT NULL, "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_2ab71ed3b21be5800905c621535" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE INDEX "IDX_cdf4388f294b30a25c627d69fe" ON "product_option_value" ("option_id") `);
await queryRunner.query(`CREATE TABLE "product_option" ("id" character varying NOT NULL, "title" character varying NOT NULL, "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, "product_id" character varying, CONSTRAINT "PK_4cf3c467e9bc764bdd32c4cd938" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TYPE "shipping_option_requirement_type_enum" AS ENUM('min_subtotal', 'max_subtotal')`);
await queryRunner.query(`CREATE TABLE "shipping_option_requirement" ("id" character varying NOT NULL, "shipping_option_id" character varying NOT NULL, "type" "shipping_option_requirement_type_enum" NOT NULL, "amount" integer NOT NULL, CONSTRAINT "PK_a0ff15442606d9f783602cb23a7" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TYPE "shipping_option_price_type_enum" AS ENUM('flat_rate', 'calculated')`);
await queryRunner.query(`CREATE TABLE "shipping_option" ("id" character varying NOT NULL, "name" character varying NOT NULL, "region_id" character varying NOT NULL, "profile_id" character varying NOT NULL, "provider_id" character varying NOT NULL, "price_type" "shipping_option_price_type_enum" NOT NULL, "amount" integer, "is_return" boolean NOT NULL DEFAULT false, "data" jsonb NOT NULL, "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 "CHK_7a367f5901ae0a5b0df75aee38" CHECK ("amount" >= 0), CONSTRAINT "PK_2e56fddaa65f3a26d402e5d786e" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TYPE "shipping_profile_type_enum" AS ENUM('default', 'gift_card', 'custom')`);
await queryRunner.query(`CREATE TABLE "shipping_profile" ("id" character varying NOT NULL, "name" character varying NOT NULL, "type" "shipping_profile_type_enum" NOT NULL, "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_c8120e4543a5a3a121f2968a1ec" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "product" ("id" character varying NOT NULL, "title" character varying NOT NULL, "subtitle" character varying, "description" character varying, "tags" character varying, "handle" character varying, "is_giftcard" boolean NOT NULL DEFAULT false, "thumbnail" character varying, "profile_id" character varying NOT NULL, "weight" integer, "length" integer, "height" integer, "width" integer, "hs_code" character varying, "origin_country" character varying, "mid_code" character varying, "material" character varying, "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_bebc9158e480b949565b4dc7a82" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_db7355f7bd36c547c8a4f539e5" ON "product" ("handle") `);
await queryRunner.query(`CREATE TYPE "discount_rule_type_enum" AS ENUM('fixed', 'percentage', 'free_shipping')`);
await queryRunner.query(`CREATE TYPE "discount_rule_allocation_enum" AS ENUM('total', 'item')`);
await queryRunner.query(`CREATE TABLE "discount_rule" ("id" character varying NOT NULL, "description" character varying NOT NULL, "type" "discount_rule_type_enum" NOT NULL, "value" integer NOT NULL, "allocation" "discount_rule_allocation_enum", "usage_limit" integer, "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_ac2c280de3701b2d66f6817f760" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "discount" ("id" character varying NOT NULL, "code" character varying NOT NULL, "is_dynamic" boolean NOT NULL, "rule_id" character varying, "is_disabled" boolean NOT NULL, "parent_discount_id" character varying, "starts_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, "ends_at" TIMESTAMP WITH TIME ZONE, "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_d05d8712e429673e459e7f1cddb" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_087926f6fec32903be3c8eedfa" ON "discount" ("code") `);
await queryRunner.query(`CREATE TYPE "payment_session_status_enum" AS ENUM('authorized', 'pending', 'requires_more', 'error', 'canceled')`);
await queryRunner.query(`CREATE TABLE "payment_session" ("id" character varying NOT NULL, "cart_id" character varying NOT NULL, "provider_id" character varying NOT NULL, "is_selected" boolean, "status" "payment_session_status_enum" NOT NULL, "data" jsonb NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "idempotency_key" character varying, CONSTRAINT "OneSelected" UNIQUE ("cart_id", "is_selected"), CONSTRAINT "PK_a1a91b20f7f3b1e5afb5485cbcd" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "payment" ("id" character varying NOT NULL, "swap_id" character varying, "cart_id" character varying, "order_id" character varying, "amount" integer NOT NULL, "currency_code" character varying NOT NULL, "amount_refunded" integer NOT NULL DEFAULT '0', "provider_id" character varying NOT NULL, "data" jsonb NOT NULL, "captured_at" TIMESTAMP WITH TIME ZONE, "canceled_at" TIMESTAMP WITH TIME ZONE, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, "idempotency_key" character varying, CONSTRAINT "REL_c17aff091441b7c25ec3d68d36" UNIQUE ("swap_id"), CONSTRAINT "REL_4665f17abc1e81dd58330e5854" UNIQUE ("cart_id"), CONSTRAINT "PK_fcaec7df5adf9cac408c686b2ab" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "gift_card" ("id" character varying NOT NULL, "code" character varying NOT NULL, "value" integer NOT NULL, "balance" integer NOT NULL, "region_id" character varying NOT NULL, "order_id" character varying, "is_disabled" boolean NOT NULL DEFAULT false, "ends_at" TIMESTAMP WITH TIME ZONE, "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 "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id"), CONSTRAINT "PK_af4e338d2d41035042843ad641f" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_53cb5605fa42e82b4d47b47bda" ON "gift_card" ("code") `);
await queryRunner.query(`CREATE TYPE "cart_type_enum" AS ENUM('default', 'swap', 'payment_link')`);
await queryRunner.query(`CREATE TABLE "cart" ("id" character varying NOT NULL, "email" character varying, "billing_address_id" character varying, "shipping_address_id" character varying, "region_id" character varying NOT NULL, "customer_id" character varying, "payment_id" character varying, "type" "cart_type_enum" NOT NULL DEFAULT 'default', "completed_at" TIMESTAMP WITH TIME ZONE, "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, "idempotency_key" character varying, CONSTRAINT "REL_9d1a161434c610aae7c3df2dc7" UNIQUE ("payment_id"), CONSTRAINT "PK_c524ec48751b9b5bcfbf6e59be7" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "shipping_method" ("id" character varying NOT NULL, "shipping_option_id" character varying NOT NULL, "order_id" character varying, "cart_id" character varying, "swap_id" character varying, "return_id" character varying, "price" integer NOT NULL, "data" jsonb NOT NULL, CONSTRAINT "REL_1d9ad62038998c3a85c77a53cf" UNIQUE ("return_id"), CONSTRAINT "CHK_64c6812fe7815be30d688df513" CHECK ("price" >= 0), CONSTRAINT "CHK_3c00b878c1426d119cd70aa065" CHECK ("order_id" IS NOT NULL OR "cart_id" IS NOT NULL OR "swap_id" IS NOT NULL OR "return_id" IS NOT NULL), CONSTRAINT "PK_b9b0adfad3c6b99229c1e7d4865" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE INDEX "IDX_fc963e94854bff2714ca84cd19" ON "shipping_method" ("shipping_option_id") `);
await queryRunner.query(`CREATE INDEX "IDX_5267705a43d547e232535b656c" ON "shipping_method" ("order_id") `);
await queryRunner.query(`CREATE INDEX "IDX_d92993a7d554d84571f4eea1d1" ON "shipping_method" ("cart_id") `);
await queryRunner.query(`CREATE INDEX "IDX_fb94fa8d5ca940daa2a58139f8" ON "shipping_method" ("swap_id") `);
await queryRunner.query(`CREATE INDEX "IDX_1d9ad62038998c3a85c77a53cf" ON "shipping_method" ("return_id") `);
await queryRunner.query(`CREATE TYPE "return_status_enum" AS ENUM('requested', 'received', 'requires_action')`);
await queryRunner.query(`CREATE TABLE "return" ("id" character varying NOT NULL, "status" "return_status_enum" NOT NULL DEFAULT 'requested', "swap_id" character varying, "order_id" character varying, "shipping_data" jsonb, "refund_amount" integer NOT NULL, "received_at" TIMESTAMP WITH TIME ZONE, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, "idempotency_key" character varying, CONSTRAINT "REL_bad82d7bff2b08b87094bfac3d" UNIQUE ("swap_id"), CONSTRAINT "PK_c8ad68d13e76d75d803b5aeebc4" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TYPE "swap_fulfillment_status_enum" AS ENUM('not_fulfilled', 'fulfilled', 'shipped', 'canceled', 'requires_action')`);
await queryRunner.query(`CREATE TYPE "swap_payment_status_enum" AS ENUM('not_paid', 'awaiting', 'captured', 'canceled', 'difference_refunded', 'partially_refunded', 'refunded', 'requires_action')`);
await queryRunner.query(`CREATE TABLE "swap" ("id" character varying NOT NULL, "fulfillment_status" "swap_fulfillment_status_enum" NOT NULL, "payment_status" "swap_payment_status_enum" NOT NULL, "order_id" character varying NOT NULL, "difference_due" integer, "shipping_address_id" character varying, "cart_id" character varying, "confirmed_at" TIMESTAMP WITH TIME ZONE, "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, "idempotency_key" character varying, CONSTRAINT "REL_402e8182bc553e082f6380020b" UNIQUE ("cart_id"), CONSTRAINT "PK_4a10d0f359339acef77e7f986d9" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "line_item" ("id" character varying NOT NULL, "cart_id" character varying, "order_id" character varying, "swap_id" character varying, "title" character varying NOT NULL, "description" character varying, "thumbnail" character varying, "is_giftcard" boolean NOT NULL DEFAULT false, "should_merge" boolean NOT NULL DEFAULT true, "allow_discounts" boolean NOT NULL DEFAULT true, "has_shipping" boolean, "unit_price" integer NOT NULL, "variant_id" character varying, "quantity" integer NOT NULL, "fulfilled_quantity" integer, "returned_quantity" integer, "shipped_quantity" integer, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "CHK_64eef00a5064887634f1680866" CHECK ("quantity" > 0), CONSTRAINT "CHK_91f40396d847f6ecfd9f752bf8" CHECK ("returned_quantity" <= "quantity"), CONSTRAINT "CHK_0cd85e15610d11b553d5e8fda6" CHECK ("shipped_quantity" <= "fulfilled_quantity"), CONSTRAINT "CHK_c61716c68f5ad5de2834c827d3" CHECK ("fulfilled_quantity" <= "quantity"), CONSTRAINT "PK_cce6b13e67fa506d1d9618ac68b" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE INDEX "IDX_27283ee631862266d0f1c68064" ON "line_item" ("cart_id") `);
await queryRunner.query(`CREATE INDEX "IDX_43a2b24495fe1d9fc2a9c835bc" ON "line_item" ("order_id") `);
await queryRunner.query(`CREATE INDEX "IDX_3fa354d8d1233ff81097b2fcb6" ON "line_item" ("swap_id") `);
await queryRunner.query(`CREATE INDEX "IDX_5371cbaa3be5200f373d24e3d5" ON "line_item" ("variant_id") `);
await queryRunner.query(`CREATE TABLE "gift_card_transaction" ("id" character varying NOT NULL, "gift_card_id" character varying NOT NULL, "order_id" character varying NOT NULL, "amount" integer NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), CONSTRAINT "gcuniq" UNIQUE ("gift_card_id", "order_id"), CONSTRAINT "PK_cfb5b4ba5447a507aef87d73fe7" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TYPE "refund_reason_enum" AS ENUM('discount', 'return', 'swap', 'other')`);
await queryRunner.query(`CREATE TABLE "refund" ("id" character varying NOT NULL, "order_id" character varying NOT NULL, "amount" integer NOT NULL, "note" character varying, "reason" "refund_reason_enum" NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, "idempotency_key" character varying, CONSTRAINT "PK_f1cefa2e60d99b206c46c1116e5" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TYPE "order_status_enum" AS ENUM('pending', 'completed', 'archived', 'canceled', 'requires_action')`);
await queryRunner.query(`CREATE TYPE "order_fulfillment_status_enum" AS ENUM('not_fulfilled', 'partially_fulfilled', 'fulfilled', 'partially_shipped', 'shipped', 'partially_returned', 'returned', 'canceled', 'requires_action')`);
await queryRunner.query(`CREATE TYPE "order_payment_status_enum" AS ENUM('not_paid', 'awaiting', 'captured', 'partially_refunded', 'refunded', 'canceled', 'requires_action')`);
await queryRunner.query(`CREATE TABLE "order" ("id" character varying NOT NULL, "status" "order_status_enum" NOT NULL DEFAULT 'pending', "fulfillment_status" "order_fulfillment_status_enum" NOT NULL DEFAULT 'not_fulfilled', "payment_status" "order_payment_status_enum" NOT NULL DEFAULT 'not_paid', "display_id" SERIAL NOT NULL, "cart_id" character varying, "customer_id" character varying NOT NULL, "email" character varying NOT NULL, "billing_address_id" character varying, "shipping_address_id" character varying, "region_id" character varying NOT NULL, "currency_code" character varying NOT NULL, "tax_rate" integer NOT NULL, "canceled_at" TIMESTAMP WITH TIME ZONE, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, "idempotency_key" character varying, CONSTRAINT "REL_c99a206eb11ad45f6b7f04f2dc" UNIQUE ("cart_id"), CONSTRAINT "PK_1031171c13130102495201e3e20" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "customer" ("id" character varying NOT NULL, "email" character varying NOT NULL, "first_name" character varying, "last_name" character varying, "billing_address_id" character varying, "password_hash" character varying, "phone" character varying, "has_account" 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 "REL_8abe81b9aac151ae60bf507ad1" UNIQUE ("billing_address_id"), CONSTRAINT "PK_a7a13f4cacb744524e44dfdad32" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_fdb2f3ad8115da4c7718109a6e" ON "customer" ("email") `);
await queryRunner.query(`CREATE TABLE "address" ("id" character varying NOT NULL, "customer_id" character varying, "company" character varying, "first_name" character varying, "last_name" character varying, "address_1" character varying, "address_2" character varying, "city" character varying, "country_code" character varying, "province" character varying, "postal_code" character varying, "phone" character varying, "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_d92de1f82754668b5f5f5dd4fd5" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "idempotency_key" ("id" character varying NOT NULL, "idempotency_key" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "locked_at" TIMESTAMP WITH TIME ZONE, "request_method" character varying, "request_params" jsonb, "request_path" character varying, "response_code" integer, "response_body" jsonb, "recovery_point" character varying NOT NULL DEFAULT 'started', CONSTRAINT "PK_213f125e14469be304f9ff1d452" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a421bf4588d0004a9b0c0fe84f" ON "idempotency_key" ("idempotency_key") `);
await queryRunner.query(`CREATE TABLE "oauth" ("id" character varying NOT NULL, "display_name" character varying NOT NULL, "application_name" character varying NOT NULL, "install_url" character varying, "uninstall_url" character varying, "data" jsonb, CONSTRAINT "PK_a957b894e50eb16b969c0640a8d" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_c49c061b1a686843c5d673506f" ON "oauth" ("application_name") `);
await queryRunner.query(`CREATE TABLE "staged_job" ("id" character varying NOT NULL, "event_name" character varying NOT NULL, "data" jsonb NOT NULL, CONSTRAINT "PK_9a28fb48c46c5509faf43ac8c8d" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "store" ("id" character varying NOT NULL, "name" character varying NOT NULL DEFAULT 'Medusa Store', "default_currency_code" character varying NOT NULL DEFAULT 'usd', "swap_link_template" character varying, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_f3172007d4de5ae8e7692759d79" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "user" ("id" character varying NOT NULL, "email" character varying NOT NULL, "first_name" character varying, "last_name" character varying, "password_hash" character varying NOT NULL, "api_token" character varying, "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_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_e12875dfb3b1d92d7d7c5377e2" ON "user" ("email") `);
await queryRunner.query(`CREATE TABLE "region_payment_providers" ("region_id" character varying NOT NULL, "provider_id" character varying NOT NULL, CONSTRAINT "PK_9fa1e69914d3dd752de6b1da407" PRIMARY KEY ("region_id", "provider_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_8aaa78ba90d3802edac317df86" ON "region_payment_providers" ("region_id") `);
await queryRunner.query(`CREATE INDEX "IDX_3a6947180aeec283cd92c59ebb" ON "region_payment_providers" ("provider_id") `);
await queryRunner.query(`CREATE TABLE "region_fulfillment_providers" ("region_id" character varying NOT NULL, "provider_id" character varying NOT NULL, CONSTRAINT "PK_5b7d928a1fb50d6803868cfab3a" PRIMARY KEY ("region_id", "provider_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_c556e14eff4d6f03db593df955" ON "region_fulfillment_providers" ("region_id") `);
await queryRunner.query(`CREATE INDEX "IDX_37f361c38a18d12a3fa3158d0c" ON "region_fulfillment_providers" ("provider_id") `);
await queryRunner.query(`CREATE TABLE "product_images" ("product_id" character varying NOT NULL, "image_id" character varying NOT NULL, CONSTRAINT "PK_10de97980da2e939c4c0e8423f2" PRIMARY KEY ("product_id", "image_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_4f166bb8c2bfcef2498d97b406" ON "product_images" ("product_id") `);
await queryRunner.query(`CREATE INDEX "IDX_2212515ba306c79f42c46a99db" ON "product_images" ("image_id") `);
await queryRunner.query(`CREATE TABLE "discount_rule_products" ("discount_rule_id" character varying NOT NULL, "product_id" character varying NOT NULL, CONSTRAINT "PK_351c8c92f5d27283c445cd022ee" PRIMARY KEY ("discount_rule_id", "product_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_4e0739e5f0244c08d41174ca08" ON "discount_rule_products" ("discount_rule_id") `);
await queryRunner.query(`CREATE INDEX "IDX_be66106a673b88a81c603abe7e" ON "discount_rule_products" ("product_id") `);
await queryRunner.query(`CREATE TABLE "discount_regions" ("discount_id" character varying NOT NULL, "region_id" character varying NOT NULL, CONSTRAINT "PK_15974566a8b6e04a7c754e85b75" PRIMARY KEY ("discount_id", "region_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_f4194aa81073f3fab8aa86906f" ON "discount_regions" ("discount_id") `);
await queryRunner.query(`CREATE INDEX "IDX_a21a7ffbe420d492eb46c305fe" ON "discount_regions" ("region_id") `);
await queryRunner.query(`CREATE TABLE "cart_discounts" ("cart_id" character varying NOT NULL, "discount_id" character varying NOT NULL, CONSTRAINT "PK_10bd412c9071ccc0cf555afd9bb" PRIMARY KEY ("cart_id", "discount_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_6680319ebe1f46d18f106191d5" ON "cart_discounts" ("cart_id") `);
await queryRunner.query(`CREATE INDEX "IDX_8df75ef4f35f217768dc113545" ON "cart_discounts" ("discount_id") `);
await queryRunner.query(`CREATE TABLE "cart_gift_cards" ("cart_id" character varying NOT NULL, "gift_card_id" character varying NOT NULL, CONSTRAINT "PK_2389be82bf0ef3635e2014c9ef1" PRIMARY KEY ("cart_id", "gift_card_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_d38047a90f3d42f0be7909e8ae" ON "cart_gift_cards" ("cart_id") `);
await queryRunner.query(`CREATE INDEX "IDX_0fb38b6d167793192bc126d835" ON "cart_gift_cards" ("gift_card_id") `);
await queryRunner.query(`CREATE TABLE "order_discounts" ("order_id" character varying NOT NULL, "discount_id" character varying NOT NULL, CONSTRAINT "PK_a7418714ffceebc125bf6d8fcfe" PRIMARY KEY ("order_id", "discount_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_e7b488cebe333f449398769b2c" ON "order_discounts" ("order_id") `);
await queryRunner.query(`CREATE INDEX "IDX_0fc1ec4e3db9001ad60c19daf1" ON "order_discounts" ("discount_id") `);
await queryRunner.query(`CREATE TABLE "order_gift_cards" ("order_id" character varying NOT NULL, "gift_card_id" character varying NOT NULL, CONSTRAINT "PK_49a8ec66a6625d7c2e3526e05b4" PRIMARY KEY ("order_id", "gift_card_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_e62ff11e4730bb3adfead979ee" ON "order_gift_cards" ("order_id") `);
await queryRunner.query(`CREATE INDEX "IDX_f2bb9f71e95b315eb24b2b84cb" ON "order_gift_cards" ("gift_card_id") `);
await queryRunner.query(`CREATE TABLE "store_currencies" ("store_id" character varying NOT NULL, "currency_code" character varying NOT NULL, CONSTRAINT "PK_0f2bff3bccc785c320a4df836de" PRIMARY KEY ("store_id", "currency_code"))`);
await queryRunner.query(`CREATE INDEX "IDX_b4f4b63d1736689b7008980394" ON "store_currencies" ("store_id") `);
await queryRunner.query(`CREATE INDEX "IDX_82a6bbb0b527c20a0002ddcbd6" ON "store_currencies" ("currency_code") `);
await queryRunner.query(`ALTER TABLE "fulfillment_item" ADD CONSTRAINT "FK_a033f83cc6bd7701a5687ab4b38" FOREIGN KEY ("fulfillment_id") REFERENCES "fulfillment"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "fulfillment_item" ADD CONSTRAINT "FK_e13ff60e74206b747a1896212d1" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "fulfillment" ADD CONSTRAINT "FK_a52e234f729db789cf473297a5c" FOREIGN KEY ("swap_id") REFERENCES "swap"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "fulfillment" ADD CONSTRAINT "FK_f129acc85e346a10eed12b86fca" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "fulfillment" ADD CONSTRAINT "FK_beb35a6de60a6c4f91d5ae57e44" FOREIGN KEY ("provider_id") REFERENCES "fulfillment_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "return_item" ADD CONSTRAINT "FK_7edab75b4fc88ea6d4f2574f087" FOREIGN KEY ("return_id") REFERENCES "return"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "return_item" ADD CONSTRAINT "FK_87774591f44564effd8039d7162" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "country" ADD CONSTRAINT "FK_b1aac8314662fa6b25569a575bb" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "region" ADD CONSTRAINT "FK_3bdd5896ec93be2f1c62a3309a5" FOREIGN KEY ("currency_code") REFERENCES "currency"("code") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD CONSTRAINT "FK_e15811f81339e4bd8c440aebe1c" FOREIGN KEY ("currency_code") REFERENCES "currency"("code") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD CONSTRAINT "FK_17a06d728e4cfbc5bd2ddb70af0" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD CONSTRAINT "FK_b433e27b7a83e6d12ab26b15b03" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "product_variant" ADD CONSTRAINT "FK_ca67dd080aac5ecf99609960cd2" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "product_option_value" ADD CONSTRAINT "FK_cdf4388f294b30a25c627d69fe9" FOREIGN KEY ("option_id") REFERENCES "product_option"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "product_option_value" ADD CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "product_option" ADD CONSTRAINT "FK_e634fca34f6b594b87fdbee95f6" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_option_requirement" ADD CONSTRAINT "FK_012a62ba743e427b5ebe9dee18e" FOREIGN KEY ("shipping_option_id") REFERENCES "shipping_option"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_option" ADD CONSTRAINT "FK_5c58105f1752fca0f4ce69f4663" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_option" ADD CONSTRAINT "FK_c951439af4c98bf2bd7fb8726cd" FOREIGN KEY ("profile_id") REFERENCES "shipping_profile"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_option" ADD CONSTRAINT "FK_a0e206bfaed3cb63c1860917347" FOREIGN KEY ("provider_id") REFERENCES "fulfillment_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "product" ADD CONSTRAINT "FK_80823b7ae866dc5acae2dac6d2c" FOREIGN KEY ("profile_id") REFERENCES "shipping_profile"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "discount" ADD CONSTRAINT "FK_ac2c280de3701b2d66f6817f760" FOREIGN KEY ("rule_id") REFERENCES "discount_rule"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "discount" ADD CONSTRAINT "FK_2250c5d9e975987ab212f61a663" FOREIGN KEY ("parent_discount_id") REFERENCES "discount"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "payment_session" ADD CONSTRAINT "FK_d25ba0787e1510ddc5d442ebcfa" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "payment" ADD CONSTRAINT "FK_c17aff091441b7c25ec3d68d36c" FOREIGN KEY ("swap_id") REFERENCES "swap"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "payment" ADD CONSTRAINT "FK_4665f17abc1e81dd58330e58542" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "payment" ADD CONSTRAINT "FK_f5221735ace059250daac9d9803" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "payment" ADD CONSTRAINT "FK_f41553459a4b1491c9893ebc921" FOREIGN KEY ("currency_code") REFERENCES "currency"("code") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_b6bcf8c3903097b84e85154eed3" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart" ADD CONSTRAINT "FK_6b9c66b5e36f7c827dfaa092f94" FOREIGN KEY ("billing_address_id") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart" ADD CONSTRAINT "FK_ced15a9a695d2b5db9dabce763d" FOREIGN KEY ("shipping_address_id") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart" ADD CONSTRAINT "FK_484c329f4783be4e18e5e2ff090" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart" ADD CONSTRAINT "FK_242205c81c1152fab1b6e848470" FOREIGN KEY ("customer_id") REFERENCES "customer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart" ADD CONSTRAINT "FK_9d1a161434c610aae7c3df2dc7e" FOREIGN KEY ("payment_id") REFERENCES "payment"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_method" ADD CONSTRAINT "FK_5267705a43d547e232535b656c2" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_method" ADD CONSTRAINT "FK_d92993a7d554d84571f4eea1d13" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_method" ADD CONSTRAINT "FK_fb94fa8d5ca940daa2a58139f86" FOREIGN KEY ("swap_id") REFERENCES "swap"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_method" ADD CONSTRAINT "FK_1d9ad62038998c3a85c77a53cfb" FOREIGN KEY ("return_id") REFERENCES "return"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "shipping_method" ADD CONSTRAINT "FK_fc963e94854bff2714ca84cd193" FOREIGN KEY ("shipping_option_id") REFERENCES "shipping_option"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "return" ADD CONSTRAINT "FK_bad82d7bff2b08b87094bfac3d6" FOREIGN KEY ("swap_id") REFERENCES "swap"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "return" ADD CONSTRAINT "FK_d4bd17f918fc6c332b74a368c36" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "swap" ADD CONSTRAINT "FK_52dd74e8c989aa5665ad2852b8b" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "swap" ADD CONSTRAINT "FK_f5189d38b3d3bd496618bf54c57" FOREIGN KEY ("shipping_address_id") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "swap" ADD CONSTRAINT "FK_402e8182bc553e082f6380020b4" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "line_item" ADD CONSTRAINT "FK_27283ee631862266d0f1c680646" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "line_item" ADD CONSTRAINT "FK_43a2b24495fe1d9fc2a9c835bc7" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "line_item" ADD CONSTRAINT "FK_3fa354d8d1233ff81097b2fcb6b" FOREIGN KEY ("swap_id") REFERENCES "swap"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "line_item" ADD CONSTRAINT "FK_5371cbaa3be5200f373d24e3d5b" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "gift_card_transaction" ADD CONSTRAINT "FK_3ff5597f1d7e02bba41541846f4" FOREIGN KEY ("gift_card_id") REFERENCES "gift_card"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "gift_card_transaction" ADD CONSTRAINT "FK_d7d441b81012f87d4265fa57d24" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "refund" ADD CONSTRAINT "FK_eec9d9af4ca098e19ea6b499eaa" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "FK_c99a206eb11ad45f6b7f04f2dcc" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "FK_cd7812c96209c5bdd48a6b858b0" FOREIGN KEY ("customer_id") REFERENCES "customer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "FK_5568d3b9ce9f7abeeb37511ecf2" FOREIGN KEY ("billing_address_id") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "FK_19b0c6293443d1b464f604c3316" FOREIGN KEY ("shipping_address_id") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "FK_e1fcce2b18dbcdbe0a5ba9a68b8" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "FK_717a141f96b76d794d409f38129" FOREIGN KEY ("currency_code") REFERENCES "currency"("code") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "customer" ADD CONSTRAINT "FK_8abe81b9aac151ae60bf507ad15" FOREIGN KEY ("billing_address_id") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "address" ADD CONSTRAINT "FK_9c9614b2f9d01665800ea8dbff7" FOREIGN KEY ("customer_id") REFERENCES "customer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "address" ADD CONSTRAINT "FK_6df8c6bf969a51d24c1980c4ff4" FOREIGN KEY ("country_code") REFERENCES "country"("iso_2") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "store" ADD CONSTRAINT "FK_55beebaa09e947cccca554af222" FOREIGN KEY ("default_currency_code") REFERENCES "currency"("code") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "region_payment_providers" ADD CONSTRAINT "FK_8aaa78ba90d3802edac317df869" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "region_payment_providers" ADD CONSTRAINT "FK_3a6947180aeec283cd92c59ebb0" FOREIGN KEY ("provider_id") REFERENCES "payment_provider"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" ADD CONSTRAINT "FK_c556e14eff4d6f03db593df955e" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" ADD CONSTRAINT "FK_37f361c38a18d12a3fa3158d0cf" FOREIGN KEY ("provider_id") REFERENCES "fulfillment_provider"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "product_images" ADD CONSTRAINT "FK_4f166bb8c2bfcef2498d97b4068" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "product_images" ADD CONSTRAINT "FK_2212515ba306c79f42c46a99db7" FOREIGN KEY ("image_id") REFERENCES "image"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "discount_rule_products" ADD CONSTRAINT "FK_4e0739e5f0244c08d41174ca08a" FOREIGN KEY ("discount_rule_id") REFERENCES "discount_rule"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "discount_rule_products" ADD CONSTRAINT "FK_be66106a673b88a81c603abe7eb" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "discount_regions" ADD CONSTRAINT "FK_f4194aa81073f3fab8aa86906ff" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "discount_regions" ADD CONSTRAINT "FK_a21a7ffbe420d492eb46c305fec" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart_discounts" ADD CONSTRAINT "FK_6680319ebe1f46d18f106191d59" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart_discounts" ADD CONSTRAINT "FK_8df75ef4f35f217768dc1135458" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart_gift_cards" ADD CONSTRAINT "FK_d38047a90f3d42f0be7909e8aea" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "cart_gift_cards" ADD CONSTRAINT "FK_0fb38b6d167793192bc126d835e" FOREIGN KEY ("gift_card_id") REFERENCES "gift_card"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order_discounts" ADD CONSTRAINT "FK_e7b488cebe333f449398769b2cc" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order_discounts" ADD CONSTRAINT "FK_0fc1ec4e3db9001ad60c19daf16" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order_gift_cards" ADD CONSTRAINT "FK_e62ff11e4730bb3adfead979ee2" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order_gift_cards" ADD CONSTRAINT "FK_f2bb9f71e95b315eb24b2b84cb3" FOREIGN KEY ("gift_card_id") REFERENCES "gift_card"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "store_currencies" ADD CONSTRAINT "FK_b4f4b63d1736689b7008980394c" FOREIGN KEY ("store_id") REFERENCES "store"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "store_currencies" ADD CONSTRAINT "FK_82a6bbb0b527c20a0002ddcbd60" FOREIGN KEY ("currency_code") REFERENCES "currency"("code") ON DELETE CASCADE ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "store_currencies" DROP CONSTRAINT "FK_82a6bbb0b527c20a0002ddcbd60"`);
await queryRunner.query(`ALTER TABLE "store_currencies" DROP CONSTRAINT "FK_b4f4b63d1736689b7008980394c"`);
await queryRunner.query(`ALTER TABLE "order_gift_cards" DROP CONSTRAINT "FK_f2bb9f71e95b315eb24b2b84cb3"`);
await queryRunner.query(`ALTER TABLE "order_gift_cards" DROP CONSTRAINT "FK_e62ff11e4730bb3adfead979ee2"`);
await queryRunner.query(`ALTER TABLE "order_discounts" DROP CONSTRAINT "FK_0fc1ec4e3db9001ad60c19daf16"`);
await queryRunner.query(`ALTER TABLE "order_discounts" DROP CONSTRAINT "FK_e7b488cebe333f449398769b2cc"`);
await queryRunner.query(`ALTER TABLE "cart_gift_cards" DROP CONSTRAINT "FK_0fb38b6d167793192bc126d835e"`);
await queryRunner.query(`ALTER TABLE "cart_gift_cards" DROP CONSTRAINT "FK_d38047a90f3d42f0be7909e8aea"`);
await queryRunner.query(`ALTER TABLE "cart_discounts" DROP CONSTRAINT "FK_8df75ef4f35f217768dc1135458"`);
await queryRunner.query(`ALTER TABLE "cart_discounts" DROP CONSTRAINT "FK_6680319ebe1f46d18f106191d59"`);
await queryRunner.query(`ALTER TABLE "discount_regions" DROP CONSTRAINT "FK_a21a7ffbe420d492eb46c305fec"`);
await queryRunner.query(`ALTER TABLE "discount_regions" DROP CONSTRAINT "FK_f4194aa81073f3fab8aa86906ff"`);
await queryRunner.query(`ALTER TABLE "discount_rule_products" DROP CONSTRAINT "FK_be66106a673b88a81c603abe7eb"`);
await queryRunner.query(`ALTER TABLE "discount_rule_products" DROP CONSTRAINT "FK_4e0739e5f0244c08d41174ca08a"`);
await queryRunner.query(`ALTER TABLE "product_images" DROP CONSTRAINT "FK_2212515ba306c79f42c46a99db7"`);
await queryRunner.query(`ALTER TABLE "product_images" DROP CONSTRAINT "FK_4f166bb8c2bfcef2498d97b4068"`);
await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" DROP CONSTRAINT "FK_37f361c38a18d12a3fa3158d0cf"`);
await queryRunner.query(`ALTER TABLE "region_fulfillment_providers" DROP CONSTRAINT "FK_c556e14eff4d6f03db593df955e"`);
await queryRunner.query(`ALTER TABLE "region_payment_providers" DROP CONSTRAINT "FK_3a6947180aeec283cd92c59ebb0"`);
await queryRunner.query(`ALTER TABLE "region_payment_providers" DROP CONSTRAINT "FK_8aaa78ba90d3802edac317df869"`);
await queryRunner.query(`ALTER TABLE "store" DROP CONSTRAINT "FK_55beebaa09e947cccca554af222"`);
await queryRunner.query(`ALTER TABLE "address" DROP CONSTRAINT "FK_6df8c6bf969a51d24c1980c4ff4"`);
await queryRunner.query(`ALTER TABLE "address" DROP CONSTRAINT "FK_9c9614b2f9d01665800ea8dbff7"`);
await queryRunner.query(`ALTER TABLE "customer" DROP CONSTRAINT "FK_8abe81b9aac151ae60bf507ad15"`);
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "FK_717a141f96b76d794d409f38129"`);
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "FK_e1fcce2b18dbcdbe0a5ba9a68b8"`);
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "FK_19b0c6293443d1b464f604c3316"`);
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "FK_5568d3b9ce9f7abeeb37511ecf2"`);
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "FK_cd7812c96209c5bdd48a6b858b0"`);
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "FK_c99a206eb11ad45f6b7f04f2dcc"`);
await queryRunner.query(`ALTER TABLE "refund" DROP CONSTRAINT "FK_eec9d9af4ca098e19ea6b499eaa"`);
await queryRunner.query(`ALTER TABLE "gift_card_transaction" DROP CONSTRAINT "FK_d7d441b81012f87d4265fa57d24"`);
await queryRunner.query(`ALTER TABLE "gift_card_transaction" DROP CONSTRAINT "FK_3ff5597f1d7e02bba41541846f4"`);
await queryRunner.query(`ALTER TABLE "line_item" DROP CONSTRAINT "FK_5371cbaa3be5200f373d24e3d5b"`);
await queryRunner.query(`ALTER TABLE "line_item" DROP CONSTRAINT "FK_3fa354d8d1233ff81097b2fcb6b"`);
await queryRunner.query(`ALTER TABLE "line_item" DROP CONSTRAINT "FK_43a2b24495fe1d9fc2a9c835bc7"`);
await queryRunner.query(`ALTER TABLE "line_item" DROP CONSTRAINT "FK_27283ee631862266d0f1c680646"`);
await queryRunner.query(`ALTER TABLE "swap" DROP CONSTRAINT "FK_402e8182bc553e082f6380020b4"`);
await queryRunner.query(`ALTER TABLE "swap" DROP CONSTRAINT "FK_f5189d38b3d3bd496618bf54c57"`);
await queryRunner.query(`ALTER TABLE "swap" DROP CONSTRAINT "FK_52dd74e8c989aa5665ad2852b8b"`);
await queryRunner.query(`ALTER TABLE "return" DROP CONSTRAINT "FK_d4bd17f918fc6c332b74a368c36"`);
await queryRunner.query(`ALTER TABLE "return" DROP CONSTRAINT "FK_bad82d7bff2b08b87094bfac3d6"`);
await queryRunner.query(`ALTER TABLE "shipping_method" DROP CONSTRAINT "FK_fc963e94854bff2714ca84cd193"`);
await queryRunner.query(`ALTER TABLE "shipping_method" DROP CONSTRAINT "FK_1d9ad62038998c3a85c77a53cfb"`);
await queryRunner.query(`ALTER TABLE "shipping_method" DROP CONSTRAINT "FK_fb94fa8d5ca940daa2a58139f86"`);
await queryRunner.query(`ALTER TABLE "shipping_method" DROP CONSTRAINT "FK_d92993a7d554d84571f4eea1d13"`);
await queryRunner.query(`ALTER TABLE "shipping_method" DROP CONSTRAINT "FK_5267705a43d547e232535b656c2"`);
await queryRunner.query(`ALTER TABLE "cart" DROP CONSTRAINT "FK_9d1a161434c610aae7c3df2dc7e"`);
await queryRunner.query(`ALTER TABLE "cart" DROP CONSTRAINT "FK_242205c81c1152fab1b6e848470"`);
await queryRunner.query(`ALTER TABLE "cart" DROP CONSTRAINT "FK_484c329f4783be4e18e5e2ff090"`);
await queryRunner.query(`ALTER TABLE "cart" DROP CONSTRAINT "FK_ced15a9a695d2b5db9dabce763d"`);
await queryRunner.query(`ALTER TABLE "cart" DROP CONSTRAINT "FK_6b9c66b5e36f7c827dfaa092f94"`);
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`);
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_b6bcf8c3903097b84e85154eed3"`);
await queryRunner.query(`ALTER TABLE "payment" DROP CONSTRAINT "FK_f41553459a4b1491c9893ebc921"`);
await queryRunner.query(`ALTER TABLE "payment" DROP CONSTRAINT "FK_f5221735ace059250daac9d9803"`);
await queryRunner.query(`ALTER TABLE "payment" DROP CONSTRAINT "FK_4665f17abc1e81dd58330e58542"`);
await queryRunner.query(`ALTER TABLE "payment" DROP CONSTRAINT "FK_c17aff091441b7c25ec3d68d36c"`);
await queryRunner.query(`ALTER TABLE "payment_session" DROP CONSTRAINT "FK_d25ba0787e1510ddc5d442ebcfa"`);
await queryRunner.query(`ALTER TABLE "discount" DROP CONSTRAINT "FK_2250c5d9e975987ab212f61a663"`);
await queryRunner.query(`ALTER TABLE "discount" DROP CONSTRAINT "FK_ac2c280de3701b2d66f6817f760"`);
await queryRunner.query(`ALTER TABLE "product" DROP CONSTRAINT "FK_80823b7ae866dc5acae2dac6d2c"`);
await queryRunner.query(`ALTER TABLE "shipping_option" DROP CONSTRAINT "FK_a0e206bfaed3cb63c1860917347"`);
await queryRunner.query(`ALTER TABLE "shipping_option" DROP CONSTRAINT "FK_c951439af4c98bf2bd7fb8726cd"`);
await queryRunner.query(`ALTER TABLE "shipping_option" DROP CONSTRAINT "FK_5c58105f1752fca0f4ce69f4663"`);
await queryRunner.query(`ALTER TABLE "shipping_option_requirement" DROP CONSTRAINT "FK_012a62ba743e427b5ebe9dee18e"`);
await queryRunner.query(`ALTER TABLE "product_option" DROP CONSTRAINT "FK_e634fca34f6b594b87fdbee95f6"`);
await queryRunner.query(`ALTER TABLE "product_option_value" DROP CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01"`);
await queryRunner.query(`ALTER TABLE "product_option_value" DROP CONSTRAINT "FK_cdf4388f294b30a25c627d69fe9"`);
await queryRunner.query(`ALTER TABLE "product_variant" DROP CONSTRAINT "FK_ca67dd080aac5ecf99609960cd2"`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP CONSTRAINT "FK_b433e27b7a83e6d12ab26b15b03"`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP CONSTRAINT "FK_17a06d728e4cfbc5bd2ddb70af0"`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP CONSTRAINT "FK_e15811f81339e4bd8c440aebe1c"`);
await queryRunner.query(`ALTER TABLE "region" DROP CONSTRAINT "FK_3bdd5896ec93be2f1c62a3309a5"`);
await queryRunner.query(`ALTER TABLE "country" DROP CONSTRAINT "FK_b1aac8314662fa6b25569a575bb"`);
await queryRunner.query(`ALTER TABLE "return_item" DROP CONSTRAINT "FK_87774591f44564effd8039d7162"`);
await queryRunner.query(`ALTER TABLE "return_item" DROP CONSTRAINT "FK_7edab75b4fc88ea6d4f2574f087"`);
await queryRunner.query(`ALTER TABLE "fulfillment" DROP CONSTRAINT "FK_beb35a6de60a6c4f91d5ae57e44"`);
await queryRunner.query(`ALTER TABLE "fulfillment" DROP CONSTRAINT "FK_f129acc85e346a10eed12b86fca"`);
await queryRunner.query(`ALTER TABLE "fulfillment" DROP CONSTRAINT "FK_a52e234f729db789cf473297a5c"`);
await queryRunner.query(`ALTER TABLE "fulfillment_item" DROP CONSTRAINT "FK_e13ff60e74206b747a1896212d1"`);
await queryRunner.query(`ALTER TABLE "fulfillment_item" DROP CONSTRAINT "FK_a033f83cc6bd7701a5687ab4b38"`);
await queryRunner.query(`DROP INDEX "IDX_82a6bbb0b527c20a0002ddcbd6"`);
await queryRunner.query(`DROP INDEX "IDX_b4f4b63d1736689b7008980394"`);
await queryRunner.query(`DROP TABLE "store_currencies"`);
await queryRunner.query(`DROP INDEX "IDX_f2bb9f71e95b315eb24b2b84cb"`);
await queryRunner.query(`DROP INDEX "IDX_e62ff11e4730bb3adfead979ee"`);
await queryRunner.query(`DROP TABLE "order_gift_cards"`);
await queryRunner.query(`DROP INDEX "IDX_0fc1ec4e3db9001ad60c19daf1"`);
await queryRunner.query(`DROP INDEX "IDX_e7b488cebe333f449398769b2c"`);
await queryRunner.query(`DROP TABLE "order_discounts"`);
await queryRunner.query(`DROP INDEX "IDX_0fb38b6d167793192bc126d835"`);
await queryRunner.query(`DROP INDEX "IDX_d38047a90f3d42f0be7909e8ae"`);
await queryRunner.query(`DROP TABLE "cart_gift_cards"`);
await queryRunner.query(`DROP INDEX "IDX_8df75ef4f35f217768dc113545"`);
await queryRunner.query(`DROP INDEX "IDX_6680319ebe1f46d18f106191d5"`);
await queryRunner.query(`DROP TABLE "cart_discounts"`);
await queryRunner.query(`DROP INDEX "IDX_a21a7ffbe420d492eb46c305fe"`);
await queryRunner.query(`DROP INDEX "IDX_f4194aa81073f3fab8aa86906f"`);
await queryRunner.query(`DROP TABLE "discount_regions"`);
await queryRunner.query(`DROP INDEX "IDX_be66106a673b88a81c603abe7e"`);
await queryRunner.query(`DROP INDEX "IDX_4e0739e5f0244c08d41174ca08"`);
await queryRunner.query(`DROP TABLE "discount_rule_products"`);
await queryRunner.query(`DROP INDEX "IDX_2212515ba306c79f42c46a99db"`);
await queryRunner.query(`DROP INDEX "IDX_4f166bb8c2bfcef2498d97b406"`);
await queryRunner.query(`DROP TABLE "product_images"`);
await queryRunner.query(`DROP INDEX "IDX_37f361c38a18d12a3fa3158d0c"`);
await queryRunner.query(`DROP INDEX "IDX_c556e14eff4d6f03db593df955"`);
await queryRunner.query(`DROP TABLE "region_fulfillment_providers"`);
await queryRunner.query(`DROP INDEX "IDX_3a6947180aeec283cd92c59ebb"`);
await queryRunner.query(`DROP INDEX "IDX_8aaa78ba90d3802edac317df86"`);
await queryRunner.query(`DROP TABLE "region_payment_providers"`);
await queryRunner.query(`DROP INDEX "IDX_e12875dfb3b1d92d7d7c5377e2"`);
await queryRunner.query(`DROP TABLE "user"`);
await queryRunner.query(`DROP TABLE "store"`);
await queryRunner.query(`DROP TABLE "staged_job"`);
await queryRunner.query(`DROP INDEX "IDX_c49c061b1a686843c5d673506f"`);
await queryRunner.query(`DROP TABLE "oauth"`);
await queryRunner.query(`DROP INDEX "IDX_a421bf4588d0004a9b0c0fe84f"`);
await queryRunner.query(`DROP TABLE "idempotency_key"`);
await queryRunner.query(`DROP TABLE "address"`);
await queryRunner.query(`DROP INDEX "IDX_fdb2f3ad8115da4c7718109a6e"`);
await queryRunner.query(`DROP TABLE "customer"`);
await queryRunner.query(`DROP TABLE "order"`);
await queryRunner.query(`DROP TYPE "order_payment_status_enum"`);
await queryRunner.query(`DROP TYPE "order_fulfillment_status_enum"`);
await queryRunner.query(`DROP TYPE "order_status_enum"`);
await queryRunner.query(`DROP TABLE "refund"`);
await queryRunner.query(`DROP TYPE "refund_reason_enum"`);
await queryRunner.query(`DROP TABLE "gift_card_transaction"`);
await queryRunner.query(`DROP INDEX "IDX_5371cbaa3be5200f373d24e3d5"`);
await queryRunner.query(`DROP INDEX "IDX_3fa354d8d1233ff81097b2fcb6"`);
await queryRunner.query(`DROP INDEX "IDX_43a2b24495fe1d9fc2a9c835bc"`);
await queryRunner.query(`DROP INDEX "IDX_27283ee631862266d0f1c68064"`);
await queryRunner.query(`DROP TABLE "line_item"`);
await queryRunner.query(`DROP TABLE "swap"`);
await queryRunner.query(`DROP TYPE "swap_payment_status_enum"`);
await queryRunner.query(`DROP TYPE "swap_fulfillment_status_enum"`);
await queryRunner.query(`DROP TABLE "return"`);
await queryRunner.query(`DROP TYPE "return_status_enum"`);
await queryRunner.query(`DROP INDEX "IDX_1d9ad62038998c3a85c77a53cf"`);
await queryRunner.query(`DROP INDEX "IDX_fb94fa8d5ca940daa2a58139f8"`);
await queryRunner.query(`DROP INDEX "IDX_d92993a7d554d84571f4eea1d1"`);
await queryRunner.query(`DROP INDEX "IDX_5267705a43d547e232535b656c"`);
await queryRunner.query(`DROP INDEX "IDX_fc963e94854bff2714ca84cd19"`);
await queryRunner.query(`DROP TABLE "shipping_method"`);
await queryRunner.query(`DROP TABLE "cart"`);
await queryRunner.query(`DROP TYPE "cart_type_enum"`);
await queryRunner.query(`DROP INDEX "IDX_53cb5605fa42e82b4d47b47bda"`);
await queryRunner.query(`DROP TABLE "gift_card"`);
await queryRunner.query(`DROP TABLE "payment"`);
await queryRunner.query(`DROP TABLE "payment_session"`);
await queryRunner.query(`DROP TYPE "payment_session_status_enum"`);
await queryRunner.query(`DROP INDEX "IDX_087926f6fec32903be3c8eedfa"`);
await queryRunner.query(`DROP TABLE "discount"`);
await queryRunner.query(`DROP TABLE "discount_rule"`);
await queryRunner.query(`DROP TYPE "discount_rule_allocation_enum"`);
await queryRunner.query(`DROP TYPE "discount_rule_type_enum"`);
await queryRunner.query(`DROP INDEX "IDX_db7355f7bd36c547c8a4f539e5"`);
await queryRunner.query(`DROP TABLE "product"`);
await queryRunner.query(`DROP TABLE "shipping_profile"`);
await queryRunner.query(`DROP TYPE "shipping_profile_type_enum"`);
await queryRunner.query(`DROP TABLE "shipping_option"`);
await queryRunner.query(`DROP TYPE "shipping_option_price_type_enum"`);
await queryRunner.query(`DROP TABLE "shipping_option_requirement"`);
await queryRunner.query(`DROP TYPE "shipping_option_requirement_type_enum"`);
await queryRunner.query(`DROP TABLE "product_option"`);
await queryRunner.query(`DROP INDEX "IDX_cdf4388f294b30a25c627d69fe"`);
await queryRunner.query(`DROP TABLE "product_option_value"`);
await queryRunner.query(`DROP INDEX "IDX_a0a3f124dc5b167622217fee02"`);
await queryRunner.query(`DROP INDEX "IDX_7124082c8846a06a857cca386c"`);
await queryRunner.query(`DROP INDEX "IDX_9db95c4b71f632fc93ecbc3d8b"`);
await queryRunner.query(`DROP INDEX "IDX_f4dc2c0888b66d547c175f090e"`);
await queryRunner.query(`DROP TABLE "product_variant"`);
await queryRunner.query(`DROP TABLE "money_amount"`);
await queryRunner.query(`DROP TABLE "image"`);
await queryRunner.query(`DROP TABLE "region"`);
await queryRunner.query(`DROP TABLE "payment_provider"`);
await queryRunner.query(`DROP INDEX "IDX_e78901b1131eaf8203d9b1cb5f"`);
await queryRunner.query(`DROP TABLE "country"`);
await queryRunner.query(`DROP TABLE "currency"`);
await queryRunner.query(`DROP TABLE "return_item"`);
await queryRunner.query(`DROP TABLE "fulfillment"`);
await queryRunner.query(`DROP TABLE "fulfillment_item"`);
await queryRunner.query(`DROP TABLE "fulfillment_provider"`);
}
}
@@ -1,44 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { countries } from "../utils/countries"
import { currencies } from "../utils/currencies"
export class countriesCurrencies1611063174563 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
for (const c of countries) {
const query = `INSERT INTO "country" ("iso_2", "iso_3", "num_code", "name", "display_name") VALUES ($1, $2, $3, $4, $5)`
const iso2 = c.alpha2.toLowerCase()
const iso3 = c.alpha3.toLowerCase()
const numeric = c.numeric
const name = c.name.toUpperCase()
const display = c.name
await queryRunner.query(query, [iso2, iso3, numeric, name, display])
}
for (const [_, c] of Object.entries(currencies)) {
const query = `INSERT INTO "currency" ("code", "symbol", "symbol_native", "name") VALUES ($1, $2, $3, $4)`
const code = c.code.toLowerCase()
const sym = c.symbol
const nat = c.symbol_native
const name = c.name
await queryRunner.query(query, [code, sym, nat, name])
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
for (const c of countries) {
await queryRunner.query(
`DELETE FROM "country" WHERE iso_2 = '${c.alpha2}'`
)
}
for (const [_, c] of Object.entries(currencies)) {
await queryRunner.query(
`DELETE FROM "currency" WHERE code = '${c.code.toLowerCase()}'`
)
}
}
}
@@ -1,213 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class claims1612284947120 implements MigrationInterface {
name = "claims1612284947120"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "shipping_method" DROP CONSTRAINT "CHK_3c00b878c1426d119cd70aa065"`
)
await queryRunner.query(
`CREATE TABLE "claim_image" ("id" character varying NOT NULL, "claim_item_id" character varying NOT NULL, "url" character varying NOT NULL, "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_7c49e44bfe8840ca7d917890101" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "claim_tag" ("id" character varying NOT NULL, "value" character varying NOT NULL, "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_7761180541142a5926501018d34" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_ec10c54769877840c132260e4a" ON "claim_tag" ("value") `
)
await queryRunner.query(
`CREATE TYPE "claim_item_reason_enum" AS ENUM('missing_item', 'wrong_item', 'production_failure', 'other')`
)
await queryRunner.query(
`CREATE TABLE "claim_item" ("id" character varying NOT NULL, "claim_order_id" character varying NOT NULL, "item_id" character varying NOT NULL, "variant_id" character varying NOT NULL, "reason" "claim_item_reason_enum" NOT NULL, "note" character varying, "quantity" integer NOT NULL, "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_5679662039bc4c7c6bc7fa1be2d" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_900a9c3834257304396b2b0fe7" ON "claim_item" ("claim_order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_6e0cad0daef76bb642675910b9" ON "claim_item" ("item_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_64980511ca32c8e92b417644af" ON "claim_item" ("variant_id") `
)
await queryRunner.query(
`CREATE TYPE "claim_order_payment_status_enum" AS ENUM('na', 'not_refunded', 'refunded')`
)
await queryRunner.query(
`CREATE TYPE "claim_order_fulfillment_status_enum" AS ENUM('not_fulfilled', 'partially_fulfilled', 'fulfilled', 'partially_shipped', 'shipped', 'partially_returned', 'returned', 'canceled', 'requires_action')`
)
await queryRunner.query(
`CREATE TYPE "claim_order_type_enum" AS ENUM('refund', 'replace')`
)
await queryRunner.query(
`CREATE TABLE "claim_order" ("id" character varying NOT NULL, "payment_status" "claim_order_payment_status_enum" NOT NULL DEFAULT 'na', "fulfillment_status" "claim_order_fulfillment_status_enum" NOT NULL DEFAULT 'not_fulfilled', "type" "claim_order_type_enum" NOT NULL, "order_id" character varying NOT NULL, "shipping_address_id" character varying, "refund_amount" integer, "canceled_at" TIMESTAMP WITH TIME ZONE, "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, "idempotency_key" character varying, CONSTRAINT "PK_8981f5595a4424021466aa4c7a4" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "claim_item_tags" ("item_id" character varying NOT NULL, "tag_id" character varying NOT NULL, CONSTRAINT "PK_54ab8ce0f7e99167068188fbd81" PRIMARY KEY ("item_id", "tag_id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_c2c0f3edf39515bd15432afe6e" ON "claim_item_tags" ("item_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_dc9bbf9fcb9ba458d25d512811" ON "claim_item_tags" ("tag_id") `
)
await queryRunner.query(
`ALTER TABLE "shipping_method" ADD "claim_order_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "return" ADD "claim_order_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "return" ADD CONSTRAINT "UQ_71773d56eb2bacb922bc3283398" UNIQUE ("claim_order_id")`
)
await queryRunner.query(
`ALTER TABLE "fulfillment" ADD "claim_order_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "line_item" ADD "claim_order_id" character varying`
)
await queryRunner.query(
`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')`
)
await queryRunner.query(
`ALTER TABLE "refund" ALTER COLUMN "reason" TYPE "refund_reason_enum" USING "reason"::"text"::"refund_reason_enum"`
)
await queryRunner.query(`DROP TYPE "refund_reason_enum_old"`)
await queryRunner.query(`COMMENT ON COLUMN "refund"."reason" IS NULL`)
await queryRunner.query(
`CREATE INDEX "IDX_d783a66d1c91c0858752c933e6" ON "shipping_method" ("claim_order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_118e3c48f09a7728f41023c94e" ON "line_item" ("claim_order_id") `
)
await queryRunner.query(
`ALTER TABLE "shipping_method" ADD CONSTRAINT "CHK_a7020b08665bbd64d84a6641cf" CHECK ("claim_order_id" IS NOT NULL OR "order_id" IS NOT NULL OR "cart_id" IS NOT NULL OR "swap_id" IS NOT NULL OR "return_id" IS NOT NULL)`
)
await queryRunner.query(
`ALTER TABLE "claim_image" ADD CONSTRAINT "FK_21cbfedd83d736d86f4c6f4ce56" FOREIGN KEY ("claim_item_id") REFERENCES "claim_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "claim_item" ADD CONSTRAINT "FK_900a9c3834257304396b2b0fe7c" FOREIGN KEY ("claim_order_id") REFERENCES "claim_order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "claim_item" ADD CONSTRAINT "FK_6e0cad0daef76bb642675910b9d" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "claim_item" ADD CONSTRAINT "FK_64980511ca32c8e92b417644afa" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "shipping_method" ADD CONSTRAINT "FK_d783a66d1c91c0858752c933e68" FOREIGN KEY ("claim_order_id") REFERENCES "claim_order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "return" ADD CONSTRAINT "FK_71773d56eb2bacb922bc3283398" FOREIGN KEY ("claim_order_id") REFERENCES "claim_order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "claim_order" ADD CONSTRAINT "FK_f49e3974465d3c3a33d449d3f31" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "claim_order" ADD CONSTRAINT "FK_017d58bf8260c6e1a2588d258e2" FOREIGN KEY ("shipping_address_id") REFERENCES "address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "fulfillment" ADD CONSTRAINT "FK_d73e55964e0ff2db8f03807d52e" FOREIGN KEY ("claim_order_id") REFERENCES "claim_order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "line_item" ADD CONSTRAINT "FK_118e3c48f09a7728f41023c94ef" FOREIGN KEY ("claim_order_id") REFERENCES "claim_order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "claim_item_tags" ADD CONSTRAINT "FK_c2c0f3edf39515bd15432afe6e5" FOREIGN KEY ("item_id") REFERENCES "claim_item"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "claim_item_tags" ADD CONSTRAINT "FK_dc9bbf9fcb9ba458d25d512811b" FOREIGN KEY ("tag_id") REFERENCES "claim_tag"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "claim_item_tags" DROP CONSTRAINT "FK_dc9bbf9fcb9ba458d25d512811b"`
)
await queryRunner.query(
`ALTER TABLE "claim_item_tags" DROP CONSTRAINT "FK_c2c0f3edf39515bd15432afe6e5"`
)
await queryRunner.query(
`ALTER TABLE "line_item" DROP CONSTRAINT "FK_118e3c48f09a7728f41023c94ef"`
)
await queryRunner.query(
`ALTER TABLE "fulfillment" DROP CONSTRAINT "FK_d73e55964e0ff2db8f03807d52e"`
)
await queryRunner.query(
`ALTER TABLE "claim_order" DROP CONSTRAINT "FK_017d58bf8260c6e1a2588d258e2"`
)
await queryRunner.query(
`ALTER TABLE "claim_order" DROP CONSTRAINT "FK_f49e3974465d3c3a33d449d3f31"`
)
await queryRunner.query(
`ALTER TABLE "return" DROP CONSTRAINT "FK_71773d56eb2bacb922bc3283398"`
)
await queryRunner.query(
`ALTER TABLE "shipping_method" DROP CONSTRAINT "FK_d783a66d1c91c0858752c933e68"`
)
await queryRunner.query(
`ALTER TABLE "claim_item" DROP CONSTRAINT "FK_64980511ca32c8e92b417644afa"`
)
await queryRunner.query(
`ALTER TABLE "claim_item" DROP CONSTRAINT "FK_6e0cad0daef76bb642675910b9d"`
)
await queryRunner.query(
`ALTER TABLE "claim_item" DROP CONSTRAINT "FK_900a9c3834257304396b2b0fe7c"`
)
await queryRunner.query(
`ALTER TABLE "claim_image" DROP CONSTRAINT "FK_21cbfedd83d736d86f4c6f4ce56"`
)
await queryRunner.query(
`ALTER TABLE "shipping_method" DROP CONSTRAINT "CHK_a7020b08665bbd64d84a6641cf"`
)
await queryRunner.query(`DROP INDEX "IDX_118e3c48f09a7728f41023c94e"`)
await queryRunner.query(`DROP INDEX "IDX_d783a66d1c91c0858752c933e6"`)
await queryRunner.query(`COMMENT ON COLUMN "refund"."reason" IS NULL`)
await queryRunner.query(
`CREATE TYPE "refund_reason_enum_old" AS ENUM('discount', 'return', 'swap', 'other')`
)
await queryRunner.query(
`ALTER TABLE "refund" ALTER COLUMN "reason" TYPE "refund_reason_enum_old" USING "reason"::"text"::"refund_reason_enum_old"`
)
await queryRunner.query(`DROP TYPE "refund_reason_enum"`)
await queryRunner.query(
`ALTER TYPE "refund_reason_enum_old" RENAME TO "refund_reason_enum"`
)
await queryRunner.query(
`ALTER TABLE "line_item" DROP COLUMN "claim_order_id"`
)
await queryRunner.query(
`ALTER TABLE "fulfillment" DROP COLUMN "claim_order_id"`
)
await queryRunner.query(
`ALTER TABLE "return" DROP CONSTRAINT "UQ_71773d56eb2bacb922bc3283398"`
)
await queryRunner.query(`ALTER TABLE "return" DROP COLUMN "claim_order_id"`)
await queryRunner.query(
`ALTER TABLE "shipping_method" DROP COLUMN "claim_order_id"`
)
await queryRunner.query(`DROP INDEX "IDX_dc9bbf9fcb9ba458d25d512811"`)
await queryRunner.query(`DROP INDEX "IDX_c2c0f3edf39515bd15432afe6e"`)
await queryRunner.query(`DROP TABLE "claim_item_tags"`)
await queryRunner.query(`DROP TABLE "claim_order"`)
await queryRunner.query(`DROP TYPE "claim_order_type_enum"`)
await queryRunner.query(`DROP TYPE "claim_order_fulfillment_status_enum"`)
await queryRunner.query(`DROP TYPE "claim_order_payment_status_enum"`)
await queryRunner.query(`DROP INDEX "IDX_64980511ca32c8e92b417644af"`)
await queryRunner.query(`DROP INDEX "IDX_6e0cad0daef76bb642675910b9"`)
await queryRunner.query(`DROP INDEX "IDX_900a9c3834257304396b2b0fe7"`)
await queryRunner.query(`DROP TABLE "claim_item"`)
await queryRunner.query(`DROP TYPE "claim_item_reason_enum"`)
await queryRunner.query(`DROP INDEX "IDX_ec10c54769877840c132260e4a"`)
await queryRunner.query(`DROP TABLE "claim_tag"`)
await queryRunner.query(`DROP TABLE "claim_image"`)
await queryRunner.query(
`ALTER TABLE "shipping_method" ADD CONSTRAINT "CHK_3c00b878c1426d119cd70aa065" CHECK (((order_id IS NOT NULL) OR (cart_id IS NOT NULL) OR (swap_id IS NOT NULL) OR (return_id IS NOT NULL)))`
)
}
}
@@ -1,191 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class indexes1612353094577 implements MigrationInterface {
name = "indexes1612353094577"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE INDEX "IDX_21cbfedd83d736d86f4c6f4ce5" ON "claim_image" ("claim_item_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_7234ed737ff4eb1b6ae6e6d7b0" ON "product_option_value" ("variant_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_b1aac8314662fa6b25569a575b" ON "country" ("region_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_012a62ba743e427b5ebe9dee18" ON "shipping_option_requirement" ("shipping_option_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_5c58105f1752fca0f4ce69f466" ON "shipping_option" ("region_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_c951439af4c98bf2bd7fb8726c" ON "shipping_option" ("profile_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_a0e206bfaed3cb63c186091734" ON "shipping_option" ("provider_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_80823b7ae866dc5acae2dac6d2" ON "product" ("profile_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_17a06d728e4cfbc5bd2ddb70af" ON "money_amount" ("variant_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_b433e27b7a83e6d12ab26b15b0" ON "money_amount" ("region_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_ca67dd080aac5ecf99609960cd" ON "product_variant" ("product_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_ac2c280de3701b2d66f6817f76" ON "discount" ("rule_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_d25ba0787e1510ddc5d442ebcf" ON "payment_session" ("cart_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_d18ad72f2fb7c87f075825b6f8" ON "payment_session" ("provider_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_c17aff091441b7c25ec3d68d36" ON "payment" ("swap_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_4665f17abc1e81dd58330e5854" ON "payment" ("cart_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_f5221735ace059250daac9d980" ON "payment" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_ea94f42b6c88e9191c3649d752" ON "payment" ("provider_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_b6bcf8c3903097b84e85154eed" ON "gift_card" ("region_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_dfc1f02bb0552e79076aa58dbb" ON "gift_card" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_6b9c66b5e36f7c827dfaa092f9" ON "cart" ("billing_address_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_ced15a9a695d2b5db9dabce763" ON "cart" ("shipping_address_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_484c329f4783be4e18e5e2ff09" ON "cart" ("region_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_242205c81c1152fab1b6e84847" ON "cart" ("customer_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_9d1a161434c610aae7c3df2dc7" ON "cart" ("payment_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_bad82d7bff2b08b87094bfac3d" ON "return" ("swap_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_71773d56eb2bacb922bc328339" ON "return" ("claim_order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_d4bd17f918fc6c332b74a368c3" ON "return" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_f49e3974465d3c3a33d449d3f3" ON "claim_order" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_017d58bf8260c6e1a2588d258e" ON "claim_order" ("shipping_address_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_d73e55964e0ff2db8f03807d52" ON "fulfillment" ("claim_order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_a52e234f729db789cf473297a5" ON "fulfillment" ("swap_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_f129acc85e346a10eed12b86fc" ON "fulfillment" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_beb35a6de60a6c4f91d5ae57e4" ON "fulfillment" ("provider_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_52dd74e8c989aa5665ad2852b8" ON "swap" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_d7d441b81012f87d4265fa57d2" ON "gift_card_transaction" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_eec9d9af4ca098e19ea6b499ea" ON "refund" ("order_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_579e01fb94f4f58db480857e05" ON "order" ("display_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_c99a206eb11ad45f6b7f04f2dc" ON "order" ("cart_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_cd7812c96209c5bdd48a6b858b" ON "order" ("customer_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_5568d3b9ce9f7abeeb37511ecf" ON "order" ("billing_address_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_19b0c6293443d1b464f604c331" ON "order" ("shipping_address_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_e1fcce2b18dbcdbe0a5ba9a68b" ON "order" ("region_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_8abe81b9aac151ae60bf507ad1" ON "customer" ("billing_address_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_9c9614b2f9d01665800ea8dbff" ON "address" ("customer_id") `
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_9c9614b2f9d01665800ea8dbff"`)
await queryRunner.query(`DROP INDEX "IDX_8abe81b9aac151ae60bf507ad1"`)
await queryRunner.query(`DROP INDEX "IDX_e1fcce2b18dbcdbe0a5ba9a68b"`)
await queryRunner.query(`DROP INDEX "IDX_19b0c6293443d1b464f604c331"`)
await queryRunner.query(`DROP INDEX "IDX_5568d3b9ce9f7abeeb37511ecf"`)
await queryRunner.query(`DROP INDEX "IDX_cd7812c96209c5bdd48a6b858b"`)
await queryRunner.query(`DROP INDEX "IDX_c99a206eb11ad45f6b7f04f2dc"`)
await queryRunner.query(`DROP INDEX "IDX_579e01fb94f4f58db480857e05"`)
await queryRunner.query(`DROP INDEX "IDX_eec9d9af4ca098e19ea6b499ea"`)
await queryRunner.query(`DROP INDEX "IDX_d7d441b81012f87d4265fa57d2"`)
await queryRunner.query(`DROP INDEX "IDX_52dd74e8c989aa5665ad2852b8"`)
await queryRunner.query(`DROP INDEX "IDX_beb35a6de60a6c4f91d5ae57e4"`)
await queryRunner.query(`DROP INDEX "IDX_f129acc85e346a10eed12b86fc"`)
await queryRunner.query(`DROP INDEX "IDX_a52e234f729db789cf473297a5"`)
await queryRunner.query(`DROP INDEX "IDX_d73e55964e0ff2db8f03807d52"`)
await queryRunner.query(`DROP INDEX "IDX_017d58bf8260c6e1a2588d258e"`)
await queryRunner.query(`DROP INDEX "IDX_f49e3974465d3c3a33d449d3f3"`)
await queryRunner.query(`DROP INDEX "IDX_d4bd17f918fc6c332b74a368c3"`)
await queryRunner.query(`DROP INDEX "IDX_71773d56eb2bacb922bc328339"`)
await queryRunner.query(`DROP INDEX "IDX_bad82d7bff2b08b87094bfac3d"`)
await queryRunner.query(`DROP INDEX "IDX_9d1a161434c610aae7c3df2dc7"`)
await queryRunner.query(`DROP INDEX "IDX_242205c81c1152fab1b6e84847"`)
await queryRunner.query(`DROP INDEX "IDX_484c329f4783be4e18e5e2ff09"`)
await queryRunner.query(`DROP INDEX "IDX_ced15a9a695d2b5db9dabce763"`)
await queryRunner.query(`DROP INDEX "IDX_6b9c66b5e36f7c827dfaa092f9"`)
await queryRunner.query(`DROP INDEX "IDX_dfc1f02bb0552e79076aa58dbb"`)
await queryRunner.query(`DROP INDEX "IDX_b6bcf8c3903097b84e85154eed"`)
await queryRunner.query(`DROP INDEX "IDX_ea94f42b6c88e9191c3649d752"`)
await queryRunner.query(`DROP INDEX "IDX_f5221735ace059250daac9d980"`)
await queryRunner.query(`DROP INDEX "IDX_4665f17abc1e81dd58330e5854"`)
await queryRunner.query(`DROP INDEX "IDX_c17aff091441b7c25ec3d68d36"`)
await queryRunner.query(`DROP INDEX "IDX_d18ad72f2fb7c87f075825b6f8"`)
await queryRunner.query(`DROP INDEX "IDX_d25ba0787e1510ddc5d442ebcf"`)
await queryRunner.query(`DROP INDEX "IDX_ac2c280de3701b2d66f6817f76"`)
await queryRunner.query(`DROP INDEX "IDX_ca67dd080aac5ecf99609960cd"`)
await queryRunner.query(`DROP INDEX "IDX_b433e27b7a83e6d12ab26b15b0"`)
await queryRunner.query(`DROP INDEX "IDX_17a06d728e4cfbc5bd2ddb70af"`)
await queryRunner.query(`DROP INDEX "IDX_80823b7ae866dc5acae2dac6d2"`)
await queryRunner.query(`DROP INDEX "IDX_a0e206bfaed3cb63c186091734"`)
await queryRunner.query(`DROP INDEX "IDX_c951439af4c98bf2bd7fb8726c"`)
await queryRunner.query(`DROP INDEX "IDX_5c58105f1752fca0f4ce69f466"`)
await queryRunner.query(`DROP INDEX "IDX_012a62ba743e427b5ebe9dee18"`)
await queryRunner.query(`DROP INDEX "IDX_b1aac8314662fa6b25569a575b"`)
await queryRunner.query(`DROP INDEX "IDX_7234ed737ff4eb1b6ae6e6d7b0"`)
await queryRunner.query(`DROP INDEX "IDX_21cbfedd83d736d86f4c6f4ce5"`)
}
}
@@ -1,49 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class notifications1613146953072 implements MigrationInterface {
name = "notifications1613146953072"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "notification_provider" ("id" character varying NOT NULL, "is_installed" boolean NOT NULL DEFAULT true, CONSTRAINT "PK_0425c2423e2ce9fdfd5c23761d9" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "notification" ("id" character varying NOT NULL, "event_name" character varying, "resource_type" character varying NOT NULL, "resource_id" character varying NOT NULL, "customer_id" character varying, "to" character varying NOT NULL, "data" jsonb NOT NULL, "parent_id" character varying, "provider_id" character varying, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), CONSTRAINT "PK_705b6c7cdf9b2c2ff7ac7872cb7" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_df1494d263740fcfb1d09a98fc" ON "notification" ("resource_type") `
)
await queryRunner.query(
`CREATE INDEX "IDX_ea6a358d9ce41c16499aae55f9" ON "notification" ("resource_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_b5df0f53a74b9d0c0a2b652c88" ON "notification" ("customer_id") `
)
await queryRunner.query(
`ALTER TABLE "notification" ADD CONSTRAINT "FK_b5df0f53a74b9d0c0a2b652c88d" FOREIGN KEY ("customer_id") REFERENCES "customer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "notification" ADD CONSTRAINT "FK_371db513192c083f48ba63c33be" FOREIGN KEY ("parent_id") REFERENCES "notification"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "notification" ADD CONSTRAINT "FK_0425c2423e2ce9fdfd5c23761d9" FOREIGN KEY ("provider_id") REFERENCES "notification_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "notification" DROP CONSTRAINT "FK_0425c2423e2ce9fdfd5c23761d9"`
)
await queryRunner.query(
`ALTER TABLE "notification" DROP CONSTRAINT "FK_371db513192c083f48ba63c33be"`
)
await queryRunner.query(
`ALTER TABLE "notification" DROP CONSTRAINT "FK_b5df0f53a74b9d0c0a2b652c88d"`
)
await queryRunner.query(`DROP INDEX "IDX_b5df0f53a74b9d0c0a2b652c88"`)
await queryRunner.query(`DROP INDEX "IDX_ea6a358d9ce41c16499aae55f9"`)
await queryRunner.query(`DROP INDEX "IDX_df1494d263740fcfb1d09a98fc"`)
await queryRunner.query(`DROP TABLE "notification"`)
await queryRunner.query(`DROP TABLE "notification_provider"`)
}
}
@@ -1,76 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class productTypeCategoryTags1613146953073
implements MigrationInterface {
name = "productTypeCategoryTags1613146953073"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "product_collection" ("id" character varying NOT NULL, "title" character varying NOT NULL, "handle" character varying, "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_49d419fc77d3aed46c835c558ac" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_6910923cb678fd6e99011a21cc" ON "product_collection" ("handle") `
)
await queryRunner.query(
`CREATE TABLE "product_tag" ("id" character varying NOT NULL, "value" character varying NOT NULL, "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_1439455c6528caa94fcc8564fda" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "product_type" ("id" character varying NOT NULL, "value" character varying NOT NULL, "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_e0843930fbb8854fe36ca39dae1" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "product_tags" ("product_id" character varying NOT NULL, "product_tag_id" character varying NOT NULL, CONSTRAINT "PK_1cf5c9537e7198df494b71b993f" PRIMARY KEY ("product_id", "product_tag_id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_5b0c6fc53c574299ecc7f9ee22" ON "product_tags" ("product_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_21683a063fe82dafdf681ecc9c" ON "product_tags" ("product_tag_id") `
)
await queryRunner.query(`ALTER TABLE "product" DROP COLUMN "tags"`)
await queryRunner.query(
`ALTER TABLE "product" ADD "collection_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "product" ADD "type_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "product" ADD CONSTRAINT "FK_49d419fc77d3aed46c835c558ac" FOREIGN KEY ("collection_id") REFERENCES "product_collection"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product_tags" ADD CONSTRAINT "FK_5b0c6fc53c574299ecc7f9ee22e" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product_tags" ADD CONSTRAINT "FK_21683a063fe82dafdf681ecc9c4" FOREIGN KEY ("product_tag_id") REFERENCES "product_tag"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product" ADD CONSTRAINT "FK_e0843930fbb8854fe36ca39dae1" FOREIGN KEY ("type_id") REFERENCES "product_type"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "product_tags" DROP CONSTRAINT "FK_21683a063fe82dafdf681ecc9c4"`
)
await queryRunner.query(
`ALTER TABLE "product_tags" DROP CONSTRAINT "FK_5b0c6fc53c574299ecc7f9ee22e"`
)
await queryRunner.query(
`ALTER TABLE "product" DROP CONSTRAINT "FK_49d419fc77d3aed46c835c558ac"`
)
await queryRunner.query(`ALTER TABLE "product" DROP COLUMN "type_id"`)
await queryRunner.query(`ALTER TABLE "product" DROP COLUMN "collection_id"`)
await queryRunner.query(
`ALTER TABLE "product" DROP CONSTRAINT "FK_e0843930fbb8854fe36ca39dae1"`
)
await queryRunner.query(
`ALTER TABLE "product" ADD "tags" character varying`
)
await queryRunner.query(`DROP INDEX "IDX_21683a063fe82dafdf681ecc9c"`)
await queryRunner.query(`DROP INDEX "IDX_5b0c6fc53c574299ecc7f9ee22"`)
await queryRunner.query(`DROP TABLE "product_tags"`)
await queryRunner.query(`DROP TABLE "product_type"`)
await queryRunner.query(`DROP TABLE "product_tag"`)
await queryRunner.query(`DROP INDEX "IDX_6910923cb678fd6e99011a21cc"`)
await queryRunner.query(`DROP TABLE "product_collection"`)
}
}
@@ -1,50 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class draftOrders1613384784316 implements MigrationInterface {
name = 'draftOrders1613384784316'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TYPE "draft_order_status_enum" AS ENUM('open', 'completed')`);
await queryRunner.query(`CREATE TABLE "draft_order" ("id" character varying NOT NULL, "status" "draft_order_status_enum" NOT NULL DEFAULT 'open', "display_id" SERIAL NOT NULL, "cart_id" character varying, "order_id" character varying, "canceled_at" TIMESTAMP WITH TIME ZONE, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "completed_at" TIMESTAMP WITH TIME ZONE, "metadata" jsonb, "idempotency_key" character varying, CONSTRAINT "REL_5bd11d0e2a9628128e2c26fd0a" UNIQUE ("cart_id"), CONSTRAINT "REL_8f6dd6c49202f1466ebf21e77d" UNIQUE ("order_id"), CONSTRAINT "PK_f478946c183d98f8d88a94cfcd7" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE INDEX "IDX_e87cc617a22ef4edce5601edab" ON "draft_order" ("display_id") `);
await queryRunner.query(`CREATE INDEX "IDX_5bd11d0e2a9628128e2c26fd0a" ON "draft_order" ("cart_id") `);
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 "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"`);
await queryRunner.query(`ALTER TABLE "cart" ALTER COLUMN "type" SET DEFAULT 'default'`);
await queryRunner.query(`DROP TYPE "cart_type_enum_old"`);
await queryRunner.query(`COMMENT ON COLUMN "cart"."type" IS NULL`);
await queryRunner.query(`ALTER TABLE "draft_order" ADD CONSTRAINT "FK_5bd11d0e2a9628128e2c26fd0a6" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "draft_order" ADD CONSTRAINT "FK_8f6dd6c49202f1466ebf21e77da" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "order" ADD CONSTRAINT "FK_727b872f86c7378474a8fa46147" FOREIGN KEY ("draft_order_id") REFERENCES "draft_order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "store" ADD "payment_link_template" character varying`);
await queryRunner.query(`ALTER TABLE "shipping_option" ADD "admin_only" boolean NOT NULL DEFAULT false`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "FK_727b872f86c7378474a8fa46147"`);
await queryRunner.query(`ALTER TABLE "draft_order" DROP CONSTRAINT "FK_8f6dd6c49202f1466ebf21e77da"`);
await queryRunner.query(`ALTER TABLE "draft_order" DROP CONSTRAINT "FK_5bd11d0e2a9628128e2c26fd0a6"`);
await queryRunner.query(`COMMENT ON COLUMN "cart"."type" IS NULL`);
await queryRunner.query(`CREATE TYPE "cart_type_enum_old" AS ENUM('default', 'swap', '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_old" USING "type"::"text"::"cart_type_enum_old"`);
await queryRunner.query(`ALTER TABLE "cart" ALTER COLUMN "type" SET DEFAULT 'default'`);
await queryRunner.query(`DROP TYPE "cart_type_enum"`);
await queryRunner.query(`ALTER TYPE "cart_type_enum_old" RENAME TO "cart_type_enum"`);
await queryRunner.query(`ALTER TABLE "order" DROP CONSTRAINT "UQ_727b872f86c7378474a8fa46147"`);
await queryRunner.query(`ALTER TABLE "order" DROP COLUMN "draft_order_id"`);
await queryRunner.query(`DROP INDEX "IDX_8f6dd6c49202f1466ebf21e77d"`);
await queryRunner.query(`DROP INDEX "IDX_5bd11d0e2a9628128e2c26fd0a"`);
await queryRunner.query(`DROP INDEX "IDX_e87cc617a22ef4edce5601edab"`);
await queryRunner.query(`DROP TABLE "draft_order"`);
await queryRunner.query(`DROP TYPE "draft_order_status_enum"`);
await queryRunner.query(`ALTER TABLE "store" DROP COLUMN "payment_link_template"`);
await queryRunner.query(`ALTER TABLE "shipping_option" DROP COLUMN "admin_only"`)
}
}
@@ -1,16 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class trackingLinks1613656135167 implements MigrationInterface {
name = 'trackingLinks1613656135167'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "tracking_link" ("id" character varying NOT NULL, "url" character varying, "tracking_number" character varying NOT NULL, "fulfillment_id" character varying NOT NULL, "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, "idempotency_key" character varying, CONSTRAINT "PK_fcfd77feb9012ec2126d7c0bfb6" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "tracking_link" ADD CONSTRAINT "FK_471e9e4c96e02ba209a307db32b" FOREIGN KEY ("fulfillment_id") REFERENCES "fulfillment"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "tracking_link" DROP CONSTRAINT "FK_471e9e4c96e02ba209a307db32b"`);
await queryRunner.query(`DROP TABLE "tracking_link"`);
}
}
@@ -1,13 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class cartContext1614684597235 implements MigrationInterface {
name = "cartContext1614684597235"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "cart" ADD "context" jsonb`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "cart" DROP COLUMN "context"`)
}
}
@@ -1,33 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class returnReason1615891636559 implements MigrationInterface {
name = "returnReason1615891636559"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "return_reason" ("id" character varying NOT NULL, "value" character varying NOT NULL, "label" character varying NOT NULL, "description" character varying, "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_95fd1172973165790903e65660a" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_00605f9d662c06b81c1b60ce24" ON "return_reason" ("value") `
)
await queryRunner.query(
`ALTER TABLE "return_item" ADD "reason_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "return_item" ADD "note" character varying`
)
await queryRunner.query(
`ALTER TABLE "return_item" ADD CONSTRAINT "FK_d742532378a65022e7ceb328828" FOREIGN KEY ("reason_id") REFERENCES "return_reason"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "return_item" DROP CONSTRAINT "FK_d742532378a65022e7ceb328828"`
)
await queryRunner.query(`ALTER TABLE "return_item" DROP COLUMN "note"`)
await queryRunner.query(`ALTER TABLE "return_item" DROP COLUMN "reason_id"`)
await queryRunner.query(`DROP INDEX "IDX_00605f9d662c06b81c1b60ce24"`)
await queryRunner.query(`DROP TABLE "return_reason"`)
}
}
@@ -1,17 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class discountUsageCount1615970124120 implements MigrationInterface {
name = "discountUsageCount1615970124120"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "discount_rule" ADD "usage_count" integer NOT NULL DEFAULT '0'`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "discount_rule" DROP COLUMN "usage_count"`
)
}
}
@@ -1,41 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class discountUsage1617002207608 implements MigrationInterface {
name = "discountUsage1617002207608"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "discount_rule" DROP COLUMN "usage_limit"`
)
await queryRunner.query(
`ALTER TABLE "discount_rule" DROP COLUMN "usage_count"`
)
await queryRunner.query(`ALTER TABLE "discount" ADD "usage_limit" integer`)
await queryRunner.query(
`ALTER TABLE "discount" ADD "usage_count" integer NOT NULL DEFAULT '0'`
)
await queryRunner.query(
`ALTER TABLE "discount_rule" ALTER COLUMN "description" DROP NOT NULL`
)
await queryRunner.query(
`COMMENT ON COLUMN "discount_rule"."description" IS NULL`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "discount" DROP COLUMN "usage_count"`)
await queryRunner.query(`ALTER TABLE "discount" DROP COLUMN "usage_limit"`)
await queryRunner.query(
`ALTER TABLE "discount_rule" ADD "usage_count" integer NOT NULL DEFAULT '0'`
)
await queryRunner.query(
`ALTER TABLE "discount_rule" ADD "usage_limit" integer`
)
await queryRunner.query(
`COMMENT ON COLUMN "discount_rule"."description" IS NULL`
)
await queryRunner.query(
`ALTER TABLE "discount_rule" ALTER COLUMN "description" SET NOT NULL`
)
}
}
@@ -1,15 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class nullablePassword1619108646647 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "user" ALTER COLUMN "password_hash" DROP NOT NULL`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "user" ALTER COLUMN "password_hash" TYPE character varying, ALTER COLUMN "password_hash" NOT NULL`
)
}
}
@@ -1,25 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class noNotification1623231564533 implements MigrationInterface {
name = 'noNotification1623231564533'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "return" ADD "no_notification" boolean`);
await queryRunner.query(`ALTER TABLE "claim_order" ADD "no_notification" boolean`);
await queryRunner.query(`ALTER TABLE "swap" ADD "no_notification" boolean`);
await queryRunner.query(`ALTER TABLE "order" ADD "no_notification" boolean`);
await queryRunner.query(`ALTER TABLE "draft_order" ADD "no_notification_order" boolean`);
await queryRunner.query(`ALTER TABLE "fulfillment" ADD "no_notification" boolean`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "fulfillment" DROP COLUMN "no_notification"`);
await queryRunner.query(`ALTER TABLE "draft_order" DROP COLUMN "no_notification_order"`);
await queryRunner.query(`ALTER TABLE "order" DROP COLUMN "no_notification"`);
await queryRunner.query(`ALTER TABLE "swap" DROP COLUMN "no_notification"`);
await queryRunner.query(`ALTER TABLE "claim_order" DROP COLUMN "no_notification"`);
await queryRunner.query(`ALTER TABLE "return" DROP COLUMN "no_notification"`);
}
}
@@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface {
name = "gcRemoveUniqueOrder1624287602631"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`)
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`)
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`)
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
await queryRunner.query(`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
}
}
@@ -1,42 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class softDeletingUniqueConstraints1624610325746 implements MigrationInterface {
name = 'softDeletingUniqueConstraints1624610325746'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_6910923cb678fd6e99011a21cc"`);
await queryRunner.query(`DROP INDEX "IDX_db7355f7bd36c547c8a4f539e5"`);
await queryRunner.query(`DROP INDEX "IDX_087926f6fec32903be3c8eedfa"`);
await queryRunner.query(`DROP INDEX "IDX_f4dc2c0888b66d547c175f090e"`);
await queryRunner.query(`DROP INDEX "IDX_9db95c4b71f632fc93ecbc3d8b"`);
await queryRunner.query(`DROP INDEX "IDX_7124082c8846a06a857cca386c"`);
await queryRunner.query(`DROP INDEX "IDX_a0a3f124dc5b167622217fee02"`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_e08af711f3493df1e921c4c9ef" ON "product_collection" ("handle") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_77c4073c30ea7793f484750529" ON "product" ("handle") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ae3e22c67d7c7a969a363533c0" ON "discount" ("code") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0683952543d7d3f4fffc427034" ON "product_variant" ("sku") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_410649600ce31c10c4b667ca10" ON "product_variant" ("barcode") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_5248fda27b9f16ef818604bb6f" ON "product_variant" ("ean") WHERE deleted_at IS NOT NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_832f86daf8103491d634a967da" ON "product_variant" ("upc") WHERE deleted_at IS NOT NULL`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_ae3e22c67d7c7a969a363533c0"`);
await queryRunner.query(`DROP INDEX "IDX_77c4073c30ea7793f484750529"`);
await queryRunner.query(`DROP INDEX "IDX_e08af711f3493df1e921c4c9ef"`);
await queryRunner.query(`DROP INDEX "IDX_832f86daf8103491d634a967da"`);
await queryRunner.query(`DROP INDEX "IDX_5248fda27b9f16ef818604bb6f"`);
await queryRunner.query(`DROP INDEX "IDX_410649600ce31c10c4b667ca10"`);
await queryRunner.query(`DROP INDEX "IDX_0683952543d7d3f4fffc427034"`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_087926f6fec32903be3c8eedfa" ON "discount" ("code") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_db7355f7bd36c547c8a4f539e5" ON "product" ("handle") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_6910923cb678fd6e99011a21cc" ON "product_collection" ("handle") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a0a3f124dc5b167622217fee02" ON "product_variant" ("upc") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_7124082c8846a06a857cca386c" ON "product_variant" ("ean") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_9db95c4b71f632fc93ecbc3d8b" ON "product_variant" ("barcode") `);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f4dc2c0888b66d547c175f090e" ON "product_variant" ("sku") `);
}
}
@@ -1,48 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class ensureCancellationFieldsExist1625560513367
implements MigrationInterface {
name = "ensureCancellationFieldsExist1625560513367"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "swap" ADD "canceled_at" TIMESTAMP WITH TIME ZONE`
)
await queryRunner.query(
`ALTER TYPE "return_status_enum" RENAME TO "return_status_enum_old"`
)
await queryRunner.query(
`CREATE TYPE "return_status_enum" AS ENUM('requested', 'received', 'requires_action', 'canceled')`
)
await queryRunner.query(
`ALTER TABLE "return" ALTER COLUMN "status" DROP DEFAULT`
)
await queryRunner.query(
`ALTER TABLE "return" ALTER COLUMN "status" TYPE "return_status_enum" USING "status"::"text"::"return_status_enum"`
)
await queryRunner.query(
`ALTER TABLE "return" ALTER COLUMN "status" SET DEFAULT 'requested'`
)
await queryRunner.query(`DROP TYPE "return_status_enum_old"`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "return_status_enum_old" AS ENUM('requested', 'received', 'requires_action')`
)
await queryRunner.query(
`ALTER TABLE "return" ALTER COLUMN "status" DROP DEFAULT`
)
await queryRunner.query(
`ALTER TABLE "return" ALTER COLUMN "status" TYPE "return_status_enum_old" USING "status"::"text"::"return_status_enum_old"`
)
await queryRunner.query(
`ALTER TABLE "return" ALTER COLUMN "status" SET DEFAULT 'requested'`
)
await queryRunner.query(`DROP TYPE "return_status_enum"`)
await queryRunner.query(
`ALTER TYPE "return_status_enum_old" RENAME TO "return_status_enum"`
)
await queryRunner.query(`ALTER TABLE "swap" DROP COLUMN "canceled_at"`)
}
}
@@ -1,14 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class addDiscountableToProduct1627995307200 implements MigrationInterface {
name = 'addDiscountableToProduct1627995307200'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "product" ADD "discountable" boolean NOT NULL DEFAULT true`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "product" DROP COLUMN "discountable"`);
}
}
@@ -1,24 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class allowBackorderSwaps1630505790603 implements MigrationInterface {
name = 'allowBackorderSwaps1630505790603'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "swap" ADD "allow_backorder" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`ALTER TABLE "cart" ADD "payment_authorized_at" TIMESTAMP WITH TIME ZONE`);
await queryRunner.query(`ALTER TYPE "swap_payment_status_enum" RENAME TO "swap_payment_status_enum_old"`);
await queryRunner.query(`CREATE TYPE "swap_payment_status_enum" AS ENUM('not_paid', 'awaiting', 'captured', 'confirmed', 'canceled', 'difference_refunded', 'partially_refunded', 'refunded', 'requires_action')`);
await queryRunner.query(`ALTER TABLE "swap" ALTER COLUMN "payment_status" TYPE "swap_payment_status_enum" USING "payment_status"::"text"::"swap_payment_status_enum"`);
await queryRunner.query(`DROP TYPE "swap_payment_status_enum_old"`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TYPE "swap_payment_status_enum_old" AS ENUM('not_paid', 'awaiting', 'captured', 'canceled', 'difference_refunded', 'partially_refunded', 'refunded', 'requires_action')`);
await queryRunner.query(`ALTER TABLE "swap" ALTER COLUMN "payment_status" TYPE "swap_payment_status_enum_old" USING "payment_status"::"text"::"swap_payment_status_enum_old"`);
await queryRunner.query(`DROP TYPE "swap_payment_status_enum"`);
await queryRunner.query(`ALTER TYPE "swap_payment_status_enum_old" RENAME TO "swap_payment_status_enum"`);
await queryRunner.query(`ALTER TABLE "cart" DROP COLUMN "payment_authorized_at"`);
await queryRunner.query(`ALTER TABLE "swap" DROP COLUMN "allow_backorder"`);
}
}
@@ -1,23 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class RankColumnWithDefaultValue1631104895519 implements MigrationInterface {
name = 'RankColumnWithDefaultValue1631104895519'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "product_variant" ADD "variant_rank" integer DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE "product_option_value" DROP CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01"`);
await queryRunner.query(`ALTER TABLE "product_option_value" ADD CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE cascade ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP CONSTRAINT "FK_17a06d728e4cfbc5bd2ddb70af0"`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD CONSTRAINT "FK_17a06d728e4cfbc5bd2ddb70af0" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE cascade ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "product_variant" DROP COLUMN "variant_rank"`);
await queryRunner.query(`ALTER TABLE "product_option_value" DROP CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01"`);
await queryRunner.query(`ALTER TABLE "product_option_value" ADD CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP CONSTRAINT "FK_17a06d728e4cfbc5bd2ddb70af0"`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD CONSTRAINT "FK_17a06d728e4cfbc5bd2ddb70af0" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}
@@ -1,41 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class enforceUniqueness1631261634964 implements MigrationInterface {
name = 'enforceUniqueness1631261634964'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_e08af711f3493df1e921c4c9ef"`);
await queryRunner.query(`DROP INDEX "IDX_77c4073c30ea7793f484750529"`);
await queryRunner.query(`DROP INDEX "IDX_0683952543d7d3f4fffc427034"`);
await queryRunner.query(`DROP INDEX "IDX_410649600ce31c10c4b667ca10"`);
await queryRunner.query(`DROP INDEX "IDX_5248fda27b9f16ef818604bb6f"`);
await queryRunner.query(`DROP INDEX "IDX_832f86daf8103491d634a967da"`);
await queryRunner.query(`DROP INDEX "IDX_ae3e22c67d7c7a969a363533c0"`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_6f234f058bbbea810dce1d04d0" ON "product_collection" ("handle") WHERE deleted_at IS NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_cf9cc6c3f2e6414b992223fff1" ON "product" ("handle") WHERE deleted_at IS NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_2ca8cfbdafb998ecfd6d340389" ON "product_variant" ("sku") WHERE deleted_at IS NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_045d4a149c09f4704e0bc08dd4" ON "product_variant" ("barcode") WHERE deleted_at IS NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_b5b6225539ee8501082fbc0714" ON "product_variant" ("ean") WHERE deleted_at IS NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_aa16f61348be02dd07ce3fc54e" ON "product_variant" ("upc") WHERE deleted_at IS NULL`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_f65bf52e2239ace276ece2b2f4" ON "discount" ("code") WHERE deleted_at IS NULL`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_f65bf52e2239ace276ece2b2f4"`);
await queryRunner.query(`DROP INDEX "IDX_aa16f61348be02dd07ce3fc54e"`);
await queryRunner.query(`DROP INDEX "IDX_b5b6225539ee8501082fbc0714"`);
await queryRunner.query(`DROP INDEX "IDX_045d4a149c09f4704e0bc08dd4"`);
await queryRunner.query(`DROP INDEX "IDX_2ca8cfbdafb998ecfd6d340389"`);
await queryRunner.query(`DROP INDEX "IDX_cf9cc6c3f2e6414b992223fff1"`);
await queryRunner.query(`DROP INDEX "IDX_6f234f058bbbea810dce1d04d0"`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_ae3e22c67d7c7a969a363533c0" ON "discount" ("code") WHERE (deleted_at IS NOT NULL)`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_832f86daf8103491d634a967da" ON "product_variant" ("upc") WHERE (deleted_at IS NOT NULL)`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_5248fda27b9f16ef818604bb6f" ON "product_variant" ("ean") WHERE (deleted_at IS NOT NULL)`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_410649600ce31c10c4b667ca10" ON "product_variant" ("barcode") WHERE (deleted_at IS NOT NULL)`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0683952543d7d3f4fffc427034" ON "product_variant" ("sku") WHERE (deleted_at IS NOT NULL)`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_77c4073c30ea7793f484750529" ON "product" ("handle") WHERE (deleted_at IS NOT NULL)`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_e08af711f3493df1e921c4c9ef" ON "product_collection" ("handle") WHERE (deleted_at IS NOT NULL)`);
}
}
@@ -1,14 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class validDurationForDiscount1631696624528 implements MigrationInterface {
name = 'validDurationForDiscount1631696624528'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "discount" ADD "valid_duration" character varying`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "discount" DROP COLUMN "valid_duration"`);
}
}
@@ -1,20 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class nestedReturnReasons1631800727788 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "return_reason" ADD "parent_return_reason_id" character varying`
)
await queryRunner.query(`ALTER TABLE "return_reason" ADD CONSTRAINT "FK_2250c5d9e975987ab212f61a657" FOREIGN KEY ("parent_return_reason_id") REFERENCES "return_reason"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "return_reason" DROP COLUMN "parent_return_reason_id"`
)
}
}
@@ -1,28 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class statusOnProduct1631864388026 implements MigrationInterface {
name = "statusOnProduct1631864388026"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "product_status_enum" AS ENUM('draft', 'proposed', 'published', 'rejected')`
)
await queryRunner.query(
`ALTER TABLE "product" ADD "status" "product_status_enum" `
)
await queryRunner.query(
`UPDATE "product" SET "status" = 'published' WHERE "status" IS NULL`
)
await queryRunner.query(
`ALTER TABLE "product" ALTER COLUMN "status" SET NOT NULL`
)
await queryRunner.query(
`ALTER TABLE "product" ALTER COLUMN "status" SET DEFAULT 'draft'`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "product" DROP COLUMN "status"`)
await queryRunner.query(`DROP TYPE "product_status_enum"`)
}
}
@@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class addNotes1632220294687 implements MigrationInterface {
name = "addNotes1632220294687"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "note" ("id" character varying NOT NULL, "value" character varying NOT NULL, "resource_type" character varying NOT NULL, "resource_id" character varying NOT NULL, "author_id" character varying, "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_96d0c172a4fba276b1bbed43058" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_f74980b411cf94af523a72af7d" ON "note" ("resource_type") `
)
await queryRunner.query(
`CREATE INDEX "IDX_3287f98befad26c3a7dab088cf" ON "note" ("resource_id") `
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_3287f98befad26c3a7dab088cf"`)
await queryRunner.query(`DROP INDEX "IDX_f74980b411cf94af523a72af7d"`)
await queryRunner.query(`DROP TABLE "note"`)
}
}
@@ -1,18 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class deleteDateOnShippingOptionRequirements1632828114899
implements MigrationInterface {
name = "deleteDateOnShippingOptionRequirements1632828114899"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "shipping_option_requirement" ADD "deleted_at" TIMESTAMP WITH TIME ZONE`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "shipping_option_requirement" DROP COLUMN "deleted_at"`
)
}
}
@@ -1,58 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class extendedUserApi1633512755401 implements MigrationInterface {
name = "extendedUserApi1633512755401"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "invite_role_enum" AS ENUM('admin', 'member', 'developer')`
)
await queryRunner.query(
`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 "invite" ADD "token" character varying NOT NULL`
)
await queryRunner.query(
`ALTER TABLE "invite" ADD "expires_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`CREATE TYPE "user_role_enum" AS ENUM('admin', 'member', 'developer')`
)
await queryRunner.query(
`ALTER TABLE "user" ADD "role" "user_role_enum" DEFAULT 'member'`
)
await queryRunner.query(
`ALTER TABLE "store" ADD "invite_link_template" character varying`
)
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_6b0ce4b4bcfd24491510bf19d1" ON "invite" ("user_email")`
)
await queryRunner.query(`DROP INDEX "IDX_e12875dfb3b1d92d7d7c5377e2"`)
await queryRunner.query(
`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 "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 "invite" DROP COLUMN "expires_at"`
)
await queryRunner.query(`ALTER TABLE "invite" DROP COLUMN "token"`)
await queryRunner.query(`DROP TABLE "invite"`)
await queryRunner.query(`DROP TYPE "invite_role_enum"`)
await queryRunner.query(
`ALTER TABLE "store" DROP COLUMN "invite_link_template"`
)
}
}
@@ -1,34 +0,0 @@
import {MigrationInterface, QueryRunner} from "typeorm";
export class addCustomShippingOptions1633614437919 implements MigrationInterface {
name = 'addCustomShippingOptions1633614437919'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "custom_shipping_option" ("id" character varying NOT NULL, "price" integer NOT NULL, "shipping_option_id" character varying NOT NULL, "cart_id" character varying, "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 "UQ_0f838b122a9a01d921aa1cdb669" UNIQUE ("shipping_option_id", "cart_id"), CONSTRAINT "PK_8dfcb5c1172c29eec4a728420cc" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE INDEX "IDX_44090cb11b06174cbcc667e91c" ON "custom_shipping_option" ("shipping_option_id") `);
await queryRunner.query(`CREATE INDEX "IDX_93caeb1bb70d37c1d36d6701a7" ON "custom_shipping_option" ("cart_id") `);
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', 'claim')`);
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"`);
await queryRunner.query(`ALTER TABLE "cart" ALTER COLUMN "type" SET DEFAULT 'default'`);
await queryRunner.query(`DROP TYPE "cart_type_enum_old"`);
await queryRunner.query(`ALTER TABLE "custom_shipping_option" ADD CONSTRAINT "FK_44090cb11b06174cbcc667e91ca" FOREIGN KEY ("shipping_option_id") REFERENCES "shipping_option"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "custom_shipping_option" ADD CONSTRAINT "FK_93caeb1bb70d37c1d36d6701a7a" FOREIGN KEY ("cart_id") REFERENCES "cart"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "custom_shipping_option" DROP CONSTRAINT "FK_93caeb1bb70d37c1d36d6701a7a"`);
await queryRunner.query(`ALTER TABLE "custom_shipping_option" DROP CONSTRAINT "FK_44090cb11b06174cbcc667e91ca"`);
await queryRunner.query(`CREATE TYPE "cart_type_enum_old" 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_old" USING "type"::"text"::"cart_type_enum_old"`);
await queryRunner.query(`ALTER TABLE "cart" ALTER COLUMN "type" SET DEFAULT 'default'`);
await queryRunner.query(`DROP TYPE "cart_type_enum"`);
await queryRunner.query(`ALTER TYPE "cart_type_enum_old" RENAME TO "cart_type_enum"`);
await queryRunner.query(`DROP INDEX "IDX_93caeb1bb70d37c1d36d6701a7"`);
await queryRunner.query(`DROP INDEX "IDX_44090cb11b06174cbcc667e91c"`);
await queryRunner.query(`DROP TABLE "custom_shipping_option"`);
}
}
@@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class orderTaxRateToRealType1638543550000 implements MigrationInterface {
name = "orderTaxRateToRealType1638543550000"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "order" ALTER COLUMN "tax_rate" TYPE REAL`
)
await queryRunner.query(
`ALTER TABLE "region" ALTER COLUMN "tax_rate" TYPE REAL`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "order" ALTER COLUMN "tax_rate" TYPE INTEGER`
)
await queryRunner.query(
`ALTER TABLE "region" ALTER COLUMN "tax_rate" TYPE NUMERIC`
)
}
}
@@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class externalIdOrder1638952072999 implements MigrationInterface {
name = "externalIdOrder1638952072999"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "order" ADD "external_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "product" ADD "external_id" character varying`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "product" DROP COLUMN "external_id"`)
await queryRunner.query(`ALTER TABLE "order" DROP COLUMN "external_id"`)
}
}
@@ -1,178 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class newTaxSystem1641636508055 implements MigrationInterface {
name = "newTaxSystem1641636508055"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "tax_rate" ("id" character varying NOT NULL, "rate" real, "code" character varying, "name" character varying NOT NULL, "region_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_23b71b53f650c0b39e99ccef4fd" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "tax_provider" ("id" character varying NOT NULL, "is_installed" boolean NOT NULL DEFAULT true, CONSTRAINT "PK_b198bf82ba6a317c11763d99b99" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "line_item_tax_line" ("id" character varying NOT NULL, "rate" real NOT NULL, "name" character varying NOT NULL, "code" character varying, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, "item_id" character varying NOT NULL, CONSTRAINT "PK_4a0f4322fcd5ce4af85727f89a8" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_5077fa54b0d037e984385dfe8a" ON "line_item_tax_line" ("item_id") `
)
await queryRunner.query(
`CREATE TABLE "shipping_method_tax_line" ("id" character varying NOT NULL, "rate" real NOT NULL, "name" character varying NOT NULL, "code" character varying, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, "shipping_method_id" character varying NOT NULL, CONSTRAINT "PK_54c94f5908aacbd51cf0a73edb1" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_926ca9f29014af8091722dede0" ON "shipping_method_tax_line" ("shipping_method_id") `
)
await queryRunner.query(
`CREATE TABLE "product_tax_rate" ("product_id" character varying NOT NULL, "rate_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_326257ce468df46cd5c8c5922e9" PRIMARY KEY ("product_id", "rate_id"))`
)
await queryRunner.query(
`CREATE TABLE "product_type_tax_rate" ("product_type_id" character varying NOT NULL, "rate_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_ddc9242de1d99bc7674969289f0" PRIMARY KEY ("product_type_id", "rate_id"))`
)
await queryRunner.query(
`CREATE TABLE "shipping_tax_rate" ("shipping_option_id" character varying NOT NULL, "rate_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_bcd93b14d7e2695365d383f5eae" PRIMARY KEY ("shipping_option_id", "rate_id"))`
)
await queryRunner.query(
`ALTER TABLE "region" ADD "gift_cards_taxable" boolean NOT NULL DEFAULT true`
)
await queryRunner.query(
`ALTER TABLE "region" ADD "automatic_taxes" boolean NOT NULL DEFAULT true`
)
await queryRunner.query(
`ALTER TABLE "region" ADD "tax_provider_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "line_item" ADD "is_return" boolean NOT NULL DEFAULT false`
)
await queryRunner.query(
`UPDATE "line_item" SET "is_return" = true WHERE "id" IN (SELECT "id" from "line_item" WHERE "metadata"->>'is_return_line' = 'true')`
)
await queryRunner.query(
`ALTER TABLE "order" ALTER COLUMN "tax_rate" DROP NOT NULL`
)
await queryRunner.query(
`CREATE INDEX "IDX_2484cf14c437a04586b07e7ddd" ON "product_tax_rate" ("rate_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_1d04aebeabb6a89f87e536a124" ON "product_tax_rate" ("product_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_ece65a774192b34253abc4cd67" ON "product_type_tax_rate" ("rate_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_25a3138bb236f63d9bb6c8ff11" ON "product_type_tax_rate" ("product_type_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_346e0016cf045b998074774764" ON "shipping_tax_rate" ("rate_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_f672727ab020df6c50fb64c1a7" ON "shipping_tax_rate" ("shipping_option_id") `
)
await queryRunner.query(
`ALTER TABLE "tax_rate" ADD CONSTRAINT "FK_b95a1e03b051993d208366cb960" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "region" ADD CONSTRAINT "FK_91f88052197680f9790272aaf5b" FOREIGN KEY ("tax_provider_id") REFERENCES "tax_provider"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" ADD CONSTRAINT "FK_5077fa54b0d037e984385dfe8ad" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "shipping_method_tax_line" ADD CONSTRAINT "FK_926ca9f29014af8091722dede08" FOREIGN KEY ("shipping_method_id") REFERENCES "shipping_method"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product_tax_rate" ADD CONSTRAINT "FK_1d04aebeabb6a89f87e536a124d" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product_tax_rate" ADD CONSTRAINT "FK_2484cf14c437a04586b07e7dddb" FOREIGN KEY ("rate_id") REFERENCES "tax_rate"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product_type_tax_rate" ADD CONSTRAINT "FK_25a3138bb236f63d9bb6c8ff111" FOREIGN KEY ("product_type_id") REFERENCES "product_type"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product_type_tax_rate" ADD CONSTRAINT "FK_ece65a774192b34253abc4cd672" FOREIGN KEY ("rate_id") REFERENCES "tax_rate"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "shipping_tax_rate" ADD CONSTRAINT "FK_f672727ab020df6c50fb64c1a70" FOREIGN KEY ("shipping_option_id") REFERENCES "shipping_option"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "shipping_tax_rate" ADD CONSTRAINT "FK_346e0016cf045b9980747747645" FOREIGN KEY ("rate_id") REFERENCES "tax_rate"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "shipping_tax_rate" DROP CONSTRAINT "FK_346e0016cf045b9980747747645"`
)
await queryRunner.query(
`ALTER TABLE "shipping_tax_rate" DROP CONSTRAINT "FK_f672727ab020df6c50fb64c1a70"`
)
await queryRunner.query(
`ALTER TABLE "product_type_tax_rate" DROP CONSTRAINT "FK_ece65a774192b34253abc4cd672"`
)
await queryRunner.query(
`ALTER TABLE "product_type_tax_rate" DROP CONSTRAINT "FK_25a3138bb236f63d9bb6c8ff111"`
)
await queryRunner.query(
`ALTER TABLE "product_tax_rate" DROP CONSTRAINT "FK_2484cf14c437a04586b07e7dddb"`
)
await queryRunner.query(
`ALTER TABLE "product_tax_rate" DROP CONSTRAINT "FK_1d04aebeabb6a89f87e536a124d"`
)
await queryRunner.query(
`ALTER TABLE "shipping_method_tax_line" DROP CONSTRAINT "FK_926ca9f29014af8091722dede08"`
)
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" DROP CONSTRAINT "FK_5077fa54b0d037e984385dfe8ad"`
)
await queryRunner.query(
`ALTER TABLE "region" DROP CONSTRAINT "FK_91f88052197680f9790272aaf5b"`
)
await queryRunner.query(
`ALTER TABLE "tax_rate" DROP CONSTRAINT "FK_b95a1e03b051993d208366cb960"`
)
await queryRunner.query(
`DROP INDEX "IDX_f672727ab020df6c50fb64c1a7"`
)
await queryRunner.query(
`DROP INDEX "IDX_346e0016cf045b998074774764"`
)
await queryRunner.query(
`DROP INDEX "IDX_25a3138bb236f63d9bb6c8ff11"`
)
await queryRunner.query(
`DROP INDEX "IDX_ece65a774192b34253abc4cd67"`
)
await queryRunner.query(
`DROP INDEX "IDX_1d04aebeabb6a89f87e536a124"`
)
await queryRunner.query(
`DROP INDEX "IDX_2484cf14c437a04586b07e7ddd"`
)
await queryRunner.query(
`ALTER TABLE "order" ALTER COLUMN "tax_rate" SET NOT NULL`
)
await queryRunner.query(`ALTER TABLE "line_item" DROP COLUMN "is_return"`)
await queryRunner.query(
`ALTER TABLE "region" DROP COLUMN "tax_provider_id"`
)
await queryRunner.query(
`ALTER TABLE "region" DROP COLUMN "automatic_taxes"`
)
await queryRunner.query(
`ALTER TABLE "region" DROP COLUMN "gift_cards_taxable"`
)
await queryRunner.query(`DROP TABLE "shipping_tax_rate"`)
await queryRunner.query(`DROP TABLE "product_type_tax_rate"`)
await queryRunner.query(`DROP TABLE "product_tax_rate"`)
await queryRunner.query(
`DROP INDEX "IDX_926ca9f29014af8091722dede0"`
)
await queryRunner.query(`DROP TABLE "shipping_method_tax_line"`)
await queryRunner.query(
`DROP INDEX "IDX_5077fa54b0d037e984385dfe8a"`
)
await queryRunner.query(`DROP TABLE "line_item_tax_line"`)
await queryRunner.query(`DROP TABLE "tax_provider"`)
await queryRunner.query(`DROP TABLE "tax_rate"`)
}
}
@@ -1,44 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class customerGroups1644943746861 implements MigrationInterface {
name = "customerGroups1644943746861"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "customer_group" ("id" character varying NOT NULL, "name" character varying NOT NULL, "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_88e7da3ff7262d9e0a35aa3664e" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_c4c3a5225a7a1f0af782c40abc" ON "customer_group" ("name") WHERE deleted_at IS NULL`
)
await queryRunner.query(
`CREATE TABLE "customer_group_customers" ("customer_group_id" character varying NOT NULL, "customer_id" character varying NOT NULL, CONSTRAINT "PK_e28a55e34ad1e2d3df9a0ac86d3" PRIMARY KEY ("customer_group_id", "customer_id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_620330964db8d2999e67b0dbe3" ON "customer_group_customers" ("customer_group_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_3c6412d076292f439269abe1a2" ON "customer_group_customers" ("customer_id") `
)
await queryRunner.query(
`ALTER TABLE "customer_group_customers" ADD CONSTRAINT "FK_620330964db8d2999e67b0dbe3e" FOREIGN KEY ("customer_group_id") REFERENCES "customer_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "customer_group_customers" ADD CONSTRAINT "FK_3c6412d076292f439269abe1a23" FOREIGN KEY ("customer_id") REFERENCES "customer"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "customer_group_customers" DROP CONSTRAINT "FK_3c6412d076292f439269abe1a23"`
)
await queryRunner.query(
`ALTER TABLE "customer_group_customers" DROP CONSTRAINT "FK_620330964db8d2999e67b0dbe3e"`
)
await queryRunner.query(`DROP INDEX "IDX_3c6412d076292f439269abe1a2"`)
await queryRunner.query(`DROP INDEX "IDX_620330964db8d2999e67b0dbe3"`)
await queryRunner.query(`DROP TABLE "customer_group_customers"`)
await queryRunner.query(`DROP INDEX "IDX_c4c3a5225a7a1f0af782c40abc"`)
await queryRunner.query(`DROP TABLE "customer_group"`)
}
}
@@ -1,245 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class discountConditions1646324713514 implements MigrationInterface {
name = "discountConditions1646324713514"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "discount_condition_type_enum" AS ENUM('products', 'product_types', 'product_collections', 'product_tags', 'customer_groups')`
)
await queryRunner.query(
`CREATE TYPE "discount_condition_operator_enum" AS ENUM('in', 'not_in')`
)
await queryRunner.query(
`CREATE TABLE "discount_condition" ("id" character varying NOT NULL, "type" "discount_condition_type_enum" NOT NULL, "operator" "discount_condition_operator_enum" NOT NULL, "discount_rule_id" character varying NOT NULL, "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_e6b81d83133ddc21a2baf2e2204" PRIMARY KEY ("id"), CONSTRAINT "dctypeuniq" UNIQUE ("type", "operator", "discount_rule_id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_efff700651718e452ca9580a62" ON "discount_condition" ("discount_rule_id") `
)
await queryRunner.query(
`CREATE TABLE "discount_condition_customer_group" ("customer_group_id" character varying NOT NULL, "condition_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_cdc8b2277169a16b8b7d4c73e0e" PRIMARY KEY ("customer_group_id", "condition_id"))`
)
await queryRunner.query(
`CREATE TABLE "discount_condition_product_collection" ("product_collection_id" character varying NOT NULL, "condition_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_b3508fc787aa4a38705866cbb6d" PRIMARY KEY ("product_collection_id", "condition_id"))`
)
await queryRunner.query(
`CREATE TABLE "discount_condition_product_tag" ("product_tag_id" character varying NOT NULL, "condition_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_a95382c1e62205b121aa058682b" PRIMARY KEY ("product_tag_id", "condition_id"))`
)
await queryRunner.query(
`CREATE TABLE "discount_condition_product_type" ("product_type_id" character varying NOT NULL, "condition_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_35d538a5a24399d0df978df12ed" PRIMARY KEY ("product_type_id", "condition_id"))`
)
await queryRunner.query(
`CREATE TABLE "discount_condition_product" ("product_id" character varying NOT NULL, "condition_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "metadata" jsonb, CONSTRAINT "PK_994eb4529fdbf14450d64ec17e8" PRIMARY KEY ("product_id", "condition_id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_f05132301e95bdab4ba1cf29a2" ON "discount_condition_product" ("condition_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_c759f53b2e48e8cfb50638fe4e" ON "discount_condition_product" ("product_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_6ef23ce0b1d9cf9b5b833e52b9" ON "discount_condition_product_type" ("condition_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_e706deb68f52ab2756119b9e70" ON "discount_condition_product_type" ("product_type_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_fbb2499551ed074526f3ee3624" ON "discount_condition_product_tag" ("condition_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_01486cc9dc6b36bf658685535f" ON "discount_condition_product_tag" ("product_tag_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_a1c4f9cfb599ad1f0db39cadd5" ON "discount_condition_product_collection" ("condition_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_a0b05dc4257abe639cb75f8eae" ON "discount_condition_product_collection" ("product_collection_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_8486ee16e69013c645d0b8716b" ON "discount_condition_customer_group" ("condition_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_4d5f98645a67545d8dea42e2eb" ON "discount_condition_customer_group" ("customer_group_id") `
)
await queryRunner.query(
`ALTER TABLE "discount_condition" ADD CONSTRAINT "FK_efff700651718e452ca9580a624" FOREIGN KEY ("discount_rule_id") REFERENCES "discount_rule"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" ADD CONSTRAINT "FK_4d5f98645a67545d8dea42e2eb8" FOREIGN KEY ("customer_group_id") REFERENCES "customer_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" ADD CONSTRAINT "FK_8486ee16e69013c645d0b8716b6" FOREIGN KEY ("condition_id") REFERENCES "discount_condition"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" ADD CONSTRAINT "FK_a0b05dc4257abe639cb75f8eae2" FOREIGN KEY ("product_collection_id") REFERENCES "product_collection"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" ADD CONSTRAINT "FK_a1c4f9cfb599ad1f0db39cadd5f" FOREIGN KEY ("condition_id") REFERENCES "discount_condition"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" ADD CONSTRAINT "FK_01486cc9dc6b36bf658685535f6" FOREIGN KEY ("product_tag_id") REFERENCES "product_tag"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" ADD CONSTRAINT "FK_fbb2499551ed074526f3ee36241" FOREIGN KEY ("condition_id") REFERENCES "discount_condition"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" ADD CONSTRAINT "FK_e706deb68f52ab2756119b9e704" FOREIGN KEY ("product_type_id") REFERENCES "product_type"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" ADD CONSTRAINT "FK_6ef23ce0b1d9cf9b5b833e52b9d" FOREIGN KEY ("condition_id") REFERENCES "discount_condition"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" ADD CONSTRAINT "FK_c759f53b2e48e8cfb50638fe4e0" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" ADD CONSTRAINT "FK_f05132301e95bdab4ba1cf29a24" FOREIGN KEY ("condition_id") REFERENCES "discount_condition"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "discount_condition_product" DROP CONSTRAINT "FK_f05132301e95bdab4ba1cf29a24"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" DROP CONSTRAINT "FK_c759f53b2e48e8cfb50638fe4e0"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" DROP CONSTRAINT "FK_6ef23ce0b1d9cf9b5b833e52b9d"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" DROP CONSTRAINT "FK_e706deb68f52ab2756119b9e704"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" DROP CONSTRAINT "FK_fbb2499551ed074526f3ee36241"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" DROP CONSTRAINT "FK_01486cc9dc6b36bf658685535f6"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" DROP CONSTRAINT "FK_a1c4f9cfb599ad1f0db39cadd5f"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" DROP CONSTRAINT "FK_a0b05dc4257abe639cb75f8eae2"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" DROP CONSTRAINT "FK_8486ee16e69013c645d0b8716b6"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" DROP CONSTRAINT "FK_4d5f98645a67545d8dea42e2eb8"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition" DROP CONSTRAINT "FK_efff700651718e452ca9580a624"`
)
await queryRunner.query(`DROP INDEX "IDX_4d5f98645a67545d8dea42e2eb"`)
await queryRunner.query(`DROP INDEX "IDX_8486ee16e69013c645d0b8716b"`)
await queryRunner.query(`DROP INDEX "IDX_a0b05dc4257abe639cb75f8eae"`)
await queryRunner.query(`DROP INDEX "IDX_a1c4f9cfb599ad1f0db39cadd5"`)
await queryRunner.query(`DROP INDEX "IDX_01486cc9dc6b36bf658685535f"`)
await queryRunner.query(`DROP INDEX "IDX_fbb2499551ed074526f3ee3624"`)
await queryRunner.query(`DROP INDEX "IDX_e706deb68f52ab2756119b9e70"`)
await queryRunner.query(`DROP INDEX "IDX_6ef23ce0b1d9cf9b5b833e52b9"`)
await queryRunner.query(`DROP INDEX "IDX_c759f53b2e48e8cfb50638fe4e"`)
await queryRunner.query(`DROP INDEX "IDX_f05132301e95bdab4ba1cf29a2"`)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" DROP COLUMN "metadata"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" DROP COLUMN "updated_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" DROP COLUMN "created_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" DROP COLUMN "metadata"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" DROP COLUMN "updated_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" DROP COLUMN "created_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" DROP COLUMN "metadata"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" DROP COLUMN "updated_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" DROP COLUMN "created_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" DROP COLUMN "metadata"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" DROP COLUMN "updated_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" DROP COLUMN "created_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" DROP COLUMN "metadata"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" DROP COLUMN "updated_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" DROP COLUMN "created_at"`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" ADD "metadata" jsonb`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" ADD "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_customer_group" ADD "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" ADD "metadata" jsonb`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" ADD "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_collection" ADD "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" ADD "metadata" jsonb`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" ADD "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_tag" ADD "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" ADD "metadata" jsonb`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" ADD "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product_type" ADD "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" ADD "metadata" jsonb`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" ADD "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(
`ALTER TABLE "discount_condition_product" ADD "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`
)
await queryRunner.query(`DROP TABLE "discount_condition_product"`)
await queryRunner.query(`DROP TABLE "discount_condition_product_type"`)
await queryRunner.query(`DROP TABLE "discount_condition_product_tag"`)
await queryRunner.query(
`DROP TABLE "discount_condition_product_collection"`
)
await queryRunner.query(`DROP TABLE "discount_condition_customer_group"`)
await queryRunner.query(`DROP INDEX "IDX_efff700651718e452ca9580a62"`)
await queryRunner.query(`DROP TABLE "discount_condition"`)
await queryRunner.query(`DROP TYPE "discount_condition_operator_enum"`)
await queryRunner.query(`DROP TYPE "discount_condition_type_enum"`)
}
}
@@ -1,38 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class updateMoneyAmountAddPriceList1646915480108 implements MigrationInterface {
name = 'updateMoneyAmountAddPriceList1646915480108'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TYPE "price_list_type_enum" AS ENUM('sale', 'override')`);
await queryRunner.query(`CREATE TYPE "price_list_status_enum" AS ENUM('active', 'draft')`);
await queryRunner.query(`CREATE TABLE "price_list" ("id" character varying NOT NULL, "name" character varying NOT NULL, "description" character varying NOT NULL, "type" "price_list_type_enum" NOT NULL DEFAULT 'sale', "status" "price_list_status_enum" NOT NULL DEFAULT 'draft', "starts_at" TIMESTAMP WITH TIME ZONE, "ends_at" TIMESTAMP WITH TIME ZONE, "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, CONSTRAINT "PK_52ea7826468b1c889cb2c28df03" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "price_list_customer_groups" ("price_list_id" character varying NOT NULL, "customer_group_id" character varying NOT NULL, CONSTRAINT "PK_1afcbe15cc8782dc80c05707df9" PRIMARY KEY ("price_list_id", "customer_group_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_52875734e9dd69064f0041f4d9" ON "price_list_customer_groups" ("price_list_id") `);
await queryRunner.query(`CREATE INDEX "IDX_c5516f550433c9b1c2630d787a" ON "price_list_customer_groups" ("customer_group_id") `);
await queryRunner.query(`ALTER TABLE "money_amount" DROP COLUMN "sale_amount"`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD "min_quantity" integer`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD "max_quantity" integer`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD "price_list_id" character varying`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD CONSTRAINT "FK_f249976b079375499662eb80c40" FOREIGN KEY ("price_list_id") REFERENCES "price_list"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "price_list_customer_groups" ADD CONSTRAINT "FK_52875734e9dd69064f0041f4d92" FOREIGN KEY ("price_list_id") REFERENCES "price_list"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE "price_list_customer_groups" ADD CONSTRAINT "FK_c5516f550433c9b1c2630d787a7" FOREIGN KEY ("customer_group_id") REFERENCES "customer_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "price_list_customer_groups" DROP CONSTRAINT "FK_c5516f550433c9b1c2630d787a7"`);
await queryRunner.query(`ALTER TABLE "price_list_customer_groups" DROP CONSTRAINT "FK_52875734e9dd69064f0041f4d92"`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP CONSTRAINT "FK_f249976b079375499662eb80c40"`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP COLUMN "price_list_id"`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP COLUMN "max_quantity"`);
await queryRunner.query(`ALTER TABLE "money_amount" DROP COLUMN "min_quantity"`);
await queryRunner.query(`ALTER TABLE "money_amount" ADD "sale_amount" integer`);
await queryRunner.query(`DROP INDEX "IDX_c5516f550433c9b1c2630d787a"`);
await queryRunner.query(`DROP INDEX "IDX_52875734e9dd69064f0041f4d9"`);
await queryRunner.query(`DROP TABLE "price_list_customer_groups"`);
await queryRunner.query(`DROP TABLE "price_list"`);
await queryRunner.query(`DROP TYPE "price_list_status_enum"`);
await queryRunner.query(`DROP TYPE "price_list_type_enum"`);
}
}
@@ -1,39 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class addLineItemAdjustments1648600574750 implements MigrationInterface {
name = "addLineItemAdjustments1648600574750"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "line_item_adjustment" ("id" character varying NOT NULL, "item_id" character varying NOT NULL, "description" character varying NOT NULL, "discount_id" character varying, "amount" integer NOT NULL, "metadata" jsonb, CONSTRAINT "PK_2b1360103753df2dc8257c2c8c3" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_be9aea2ccf3567007b6227da4d" ON "line_item_adjustment" ("item_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_2f41b20a71f30e60471d7e3769" ON "line_item_adjustment" ("discount_id") `
)
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_bf701b88d2041392a288785ada" ON "line_item_adjustment" ("discount_id", "item_id") WHERE "discount_id" IS NOT NULL`
)
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" ADD CONSTRAINT "FK_be9aea2ccf3567007b6227da4d2" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" ADD CONSTRAINT "FK_2f41b20a71f30e60471d7e3769c" FOREIGN KEY ("discount_id") REFERENCES "discount"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" DROP CONSTRAINT "FK_2f41b20a71f30e60471d7e3769c"`
)
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" DROP CONSTRAINT "FK_be9aea2ccf3567007b6227da4d2"`
)
await queryRunner.query(`DROP INDEX "IDX_bf701b88d2041392a288785ada"`)
await queryRunner.query(`DROP INDEX "IDX_2f41b20a71f30e60471d7e3769"`)
await queryRunner.query(`DROP INDEX "IDX_be9aea2ccf3567007b6227da4d"`)
await queryRunner.query(`DROP TABLE "line_item_adjustment"`)
}
}
@@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class taxLineConstraints1648641130007 implements MigrationInterface {
name = "taxLineConstraints1648641130007"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" ADD CONSTRAINT "UQ_3c2af51043ed7243e7d9775a2ad" UNIQUE ("item_id", "code")`
)
await queryRunner.query(
`ALTER TABLE "shipping_method_tax_line" ADD CONSTRAINT "UQ_cd147fca71e50bc954139fa3104" UNIQUE ("shipping_method_id", "code")`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "shipping_method_tax_line" DROP CONSTRAINT "UQ_cd147fca71e50bc954139fa3104"`
)
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" DROP CONSTRAINT "UQ_3c2af51043ed7243e7d9775a2ad"`
)
}
}
@@ -1,42 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class addBatchJobModel1649775522087 implements MigrationInterface {
name = "addBatchJobModel1649775522087"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "batch_job"
(
"id" character varying NOT NULL,
"type" text NOT NULL,
"created_by" character varying,
"context" jsonb,
"result" jsonb,
"dry_run" boolean NOT NULL DEFAULT FALSE,
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
"pre_processed_at" TIMESTAMP WITH TIME ZONE,
"confirmed_at" TIMESTAMP WITH TIME ZONE,
"processing_at" TIMESTAMP WITH TIME ZONE,
"completed_at" TIMESTAMP WITH TIME ZONE,
"failed_at" TIMESTAMP WITH TIME ZONE,
"canceled_at" TIMESTAMP WITH TIME ZONE,
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
"deleted_at" TIMESTAMP WITH TIME ZONE,
CONSTRAINT "PK_e57f84d485145d5be96bc6d871e" PRIMARY KEY ("id")
)`
)
await queryRunner.query(
`ALTER TABLE "batch_job"
ADD CONSTRAINT "FK_fa53ca4f5fd90605b532802a626" FOREIGN KEY ("created_by") REFERENCES "user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "batch_job"
DROP CONSTRAINT "FK_fa53ca4f5fd90605b532802a626"`
)
await queryRunner.query(`DROP TABLE "batch_job"`)
}
}
@@ -1,74 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
export const featureFlag = SalesChannelFeatureFlag.key
export class salesChannel1656949291839 implements MigrationInterface {
name = "salesChannel1656949291839"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "sales_channel" ("id" character varying NOT NULL, "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, "name" character varying NOT NULL, "description" character varying, "is_disabled" boolean NOT NULL DEFAULT false, CONSTRAINT "PK_d1eb0b923ea5a0eb1e0916191f1" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "product_sales_channel" ("product_id" character varying NOT NULL, "sales_channel_id" character varying NOT NULL, CONSTRAINT "PK_fd29b6a8bd641052628dee19583" PRIMARY KEY ("product_id", "sales_channel_id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_5a4d5e1e60f97633547821ec8d" ON "product_sales_channel" ("product_id") `
)
await queryRunner.query(
`CREATE INDEX "IDX_37341bad297fe5cca91f921032" ON "product_sales_channel" ("sales_channel_id") `
)
await queryRunner.query(
`ALTER TABLE "cart" ADD "sales_channel_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "order" ADD "sales_channel_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "store" ADD "default_sales_channel_id" character varying`
)
await queryRunner.query(
`ALTER TABLE "store" ADD CONSTRAINT "UQ_61b0f48cccbb5f41c750bac7286" UNIQUE ("default_sales_channel_id")`
)
await queryRunner.query(
`ALTER TABLE "cart" ADD CONSTRAINT "FK_a2bd3c26f42e754b9249ba78fd6" FOREIGN KEY ("sales_channel_id") REFERENCES "sales_channel"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "order" ADD CONSTRAINT "FK_6ff7e874f01b478c115fdd462eb" FOREIGN KEY ("sales_channel_id") REFERENCES "sales_channel"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "store" ADD CONSTRAINT "FK_61b0f48cccbb5f41c750bac7286" FOREIGN KEY ("default_sales_channel_id") REFERENCES "sales_channel"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "product_sales_channel" ADD CONSTRAINT "FK_5a4d5e1e60f97633547821ec8d6" FOREIGN KEY ("product_id") REFERENCES "product"("id") ON DELETE CASCADE ON UPDATE CASCADE`
)
await queryRunner.query(
`ALTER TABLE "product_sales_channel" ADD CONSTRAINT "FK_37341bad297fe5cca91f921032b" FOREIGN KEY ("sales_channel_id") REFERENCES "sales_channel"("id") ON DELETE CASCADE ON UPDATE CASCADE`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "product_sales_channel" DROP CONSTRAINT "FK_37341bad297fe5cca91f921032b"`
)
await queryRunner.query(
`ALTER TABLE "product_sales_channel" DROP CONSTRAINT "FK_5a4d5e1e60f97633547821ec8d6"`
)
await queryRunner.query(
`ALTER TABLE "store" DROP COLUMN "default_sales_channel_id"`
)
await queryRunner.query(
`ALTER TABLE "order" DROP COLUMN "sales_channel_id"`
)
await queryRunner.query(`ALTER TABLE "cart" DROP COLUMN "sales_channel_id"`)
await queryRunner.query(`DROP TABLE "product_sales_channel"`)
await queryRunner.query(`DROP TABLE "sales_channel"`)
}
}
@@ -1,25 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class taxedGiftCardTransactions1657098186554
implements MigrationInterface
{
name = "taxedGiftCardTransactions1657098186554"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "gift_card_transaction" ADD "is_taxable" boolean`
)
await queryRunner.query(
`ALTER TABLE "gift_card_transaction" ADD "tax_rate" real`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "gift_card_transaction" DROP COLUMN "is_taxable"`
)
await queryRunner.query(
`ALTER TABLE "gift_card_transaction" DROP COLUMN "tax_rate"`
)
}
}
@@ -1,38 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class extendedBatchJob1657267320181 implements MigrationInterface {
name = "extendedBatchJob1657267320181"
public async up(queryRunner: QueryRunner): Promise<void> {
// check if batch job table exists and status column exists
// if that's the case, the previous migration has already been run
const batchJobColumnStatusExists = await queryRunner.query(`
SELECT exists (
SELECT FROM information_schema.columns
WHERE table_name = 'batch_job'
AND column_name = 'status'
)`)
// if the table exists, we alter the table to add the new columns
if (batchJobColumnStatusExists[0].exists) {
await queryRunner.query(`
ALTER TABLE "batch_job" DROP COLUMN "status";
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;
ALTER TABLE "batch_job" ADD "confirmed_at" TIMESTAMP WITH TIME ZONE;
ALTER TABLE "batch_job" ADD "completed_at" TIMESTAMP WITH TIME ZONE;
ALTER TABLE "batch_job" ADD "canceled_at" TIMESTAMP WITH TIME ZONE;
ALTER TABLE "batch_job" ADD "failed_at" TIMESTAMP WITH TIME ZONE;
ALTER TABLE "batch_job" DROP COLUMN "created_by";
ALTER TABLE "batch_job" ADD "created_by" character varying;
ALTER TABLE "batch_job" ADD CONSTRAINT "FK_cdf30493ba1c9ef207e1e80c10a" FOREIGN KEY ("created_by") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
`)
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
void 0
}
}
@@ -1,46 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import TaxInclusivePricingFlag from "../loaders/feature-flags/tax-inclusive-pricing"
export const featureFlag = TaxInclusivePricingFlag.key
export class test1659501357661 implements MigrationInterface {
name = "test1659501357661"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "currency" ADD "includes_tax" boolean NOT NULL DEFAULT false`
)
await queryRunner.query(
`ALTER TABLE "region" ADD "includes_tax" boolean NOT NULL DEFAULT false`
)
await queryRunner.query(
`ALTER TABLE "shipping_option" ADD "includes_tax" boolean NOT NULL DEFAULT false`
)
await queryRunner.query(
`ALTER TABLE "price_list" ADD "includes_tax" boolean NOT NULL DEFAULT false`
)
await queryRunner.query(
`ALTER TABLE "shipping_method" ADD "includes_tax" boolean NOT NULL DEFAULT false`
)
await queryRunner.query(
`ALTER TABLE "line_item" ADD "includes_tax" boolean NOT NULL DEFAULT false`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "line_item" DROP COLUMN "includes_tax"`
)
await queryRunner.query(
`ALTER TABLE "shipping_method" DROP COLUMN "includes_tax"`
)
await queryRunner.query(
`ALTER TABLE "price_list" DROP COLUMN "includes_tax"`
)
await queryRunner.query(
`ALTER TABLE "shipping_option" DROP COLUMN "includes_tax"`
)
await queryRunner.query(`ALTER TABLE "region" DROP COLUMN "includes_tax"`)
await queryRunner.query(`ALTER TABLE "currency" DROP COLUMN "includes_tax"`)
}
}
@@ -1,13 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class paymentSessionUniqCartIdProviderId1660040729000 implements MigrationInterface {
name = "paymentSessionUniqCartIdProviderId1660040729000"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE UNIQUE INDEX "UniqPaymentSessionCartIdProviderId" ON "payment_session" ("cart_id", "provider_id")`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "UniqPaymentSessionCartIdProviderId"`)
}
}
@@ -1,25 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class multiPaymentCart1661345741249 implements MigrationInterface {
name = "multiPaymentCart1661345741249"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "payment" DROP CONSTRAINT "REL_4665f17abc1e81dd58330e5854"`
)
await queryRunner.query(
`CREATE UNIQUE INDEX "UniquePaymentActive" ON "payment" ("cart_id") WHERE canceled_at IS NULL`
)
await queryRunner.query(
`CREATE INDEX "IDX_aac4855eadda71aa1e4b6d7684" ON "payment" ("cart_id") WHERE canceled_at IS NOT NULL`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_aac4855eadda71aa1e4b6d7684"`)
await queryRunner.query(`DROP INDEX "UniquePaymentActive"`)
await queryRunner.query(
`ALTER TABLE "payment" ADD CONSTRAINT "REL_4665f17abc1e81dd58330e5854" UNIQUE ("cart_id")`
)
}
}
@@ -1,33 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class swapFulfillmentStatusRequiresAction1661863940645
implements MigrationInterface
{
name = "swapFulfillmentStatusRequiresAction1661863940645"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TYPE "swap_fulfillment_status_enum" RENAME TO "swap_fulfillment_status_enum_old"`
)
await queryRunner.query(
`CREATE TYPE "swap_fulfillment_status_enum" AS ENUM('not_fulfilled', 'fulfilled', 'shipped', 'partially_shipped', 'canceled', 'requires_action')`
)
await queryRunner.query(
`ALTER TABLE "swap" ALTER COLUMN "fulfillment_status" TYPE "swap_fulfillment_status_enum" USING "fulfillment_status"::"text"::"swap_fulfillment_status_enum"`
)
await queryRunner.query(`DROP TYPE "swap_fulfillment_status_enum_old"`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "swap_fulfillment_status_enum_old" AS ENUM('not_fulfilled', 'fulfilled', 'shipped', 'canceled', 'requires_action')`
)
await queryRunner.query(
`ALTER TABLE "swap" ALTER COLUMN "fulfillment_status" TYPE "swap_fulfillment_status_enum_old" USING "fulfillment_status"::"text"::"swap_fulfillment_status_enum_old"`
)
await queryRunner.query(`DROP TYPE "swap_fulfillment_status_enum"`)
await queryRunner.query(
`ALTER TYPE "swap_fulfillment_status_enum_old" RENAME TO "swap_fulfillment_status_enum"`
)
}
}
@@ -1,49 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class orderEditing1663059812399 implements MigrationInterface {
name = "orderEditing1663059812399"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "order_item_change_type_enum" AS ENUM('item_add', 'item_remove', 'item_update')`
)
await queryRunner.query(
`CREATE TABLE "order_item_change" ("id" character varying NOT NULL, "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, "type" "order_item_change_type_enum" NOT NULL, "order_edit_id" character varying NOT NULL, "original_line_item_id" character varying, "line_item_id" character varying, CONSTRAINT "UQ_da93cee3ca0dd50a5246268c2e9" UNIQUE ("order_edit_id", "line_item_id"), CONSTRAINT "UQ_5b7a99181e4db2ea821be0b6196" UNIQUE ("order_edit_id", "original_line_item_id"), CONSTRAINT "REL_5f9688929761f7df108b630e64" UNIQUE ("line_item_id"), CONSTRAINT "PK_d6eb138f77ffdee83567b85af0c" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE TABLE "order_edit" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "order_id" character varying NOT NULL, "internal_note" character varying, "created_by" character varying NOT NULL, "requested_by" character varying, "requested_at" TIMESTAMP WITH TIME ZONE, "confirmed_by" character varying, "confirmed_at" TIMESTAMP WITH TIME ZONE, "declined_by" character varying, "declined_reason" character varying, "declined_at" TIMESTAMP WITH TIME ZONE, "canceled_by" character varying, "canceled_at" TIMESTAMP WITH TIME ZONE, CONSTRAINT "PK_58ab6acf2e84b4e827f5f846f7a" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`ALTER TABLE "order_item_change" ADD CONSTRAINT "FK_44feeebb258bf4cfa4cc4202281" FOREIGN KEY ("order_edit_id") REFERENCES "order_edit"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "order_item_change" ADD CONSTRAINT "FK_b4d53b8d03c9f5e7d4317e818d9" FOREIGN KEY ("original_line_item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "order_item_change" ADD CONSTRAINT "FK_5f9688929761f7df108b630e64a" FOREIGN KEY ("line_item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "order_edit" ADD CONSTRAINT "FK_1f3a251488a91510f57e1bf93cd" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "order_edit" DROP CONSTRAINT "FK_1f3a251488a91510f57e1bf93cd"`
)
await queryRunner.query(
`ALTER TABLE "order_item_change" DROP CONSTRAINT "FK_5f9688929761f7df108b630e64a"`
)
await queryRunner.query(
`ALTER TABLE "order_item_change" DROP CONSTRAINT "FK_b4d53b8d03c9f5e7d4317e818d9"`
)
await queryRunner.query(
`ALTER TABLE "order_item_change" DROP CONSTRAINT "FK_44feeebb258bf4cfa4cc4202281"`
)
await queryRunner.query(`DROP TABLE "order_edit"`)
await queryRunner.query(`DROP TABLE "order_item_change"`)
await queryRunner.query(`DROP TYPE "order_item_change_type_enum"`)
}
}
@@ -1,46 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class lineItemOriginalItemRelation1663059812400
implements MigrationInterface
{
name = "lineItemOriginalItemRelation1663059812400"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "line_item"
ADD COLUMN IF NOT EXISTS original_item_id character varying,
ADD COLUMN IF NOT EXISTS order_edit_id character varying`
)
await queryRunner.query(
`ALTER TABLE "line_item"
ADD CONSTRAINT "line_item_original_item_fk" FOREIGN KEY ("original_item_id") REFERENCES "line_item" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "line_item"
ADD CONSTRAINT "line_item_order_edit_fk" FOREIGN KEY ("order_edit_id") REFERENCES "order_edit" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`CREATE UNIQUE INDEX "unique_li_original_item_id_order_edit_id" ON "line_item" ("order_edit_id", "original_item_id") WHERE original_item_id IS NOT NULL AND order_edit_id IS NOT NULL`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX IF EXISTS "unique_li_original_item_id_order_edit_id"`
)
await queryRunner.query(
`ALTER TABLE "line_item" DROP CONSTRAINT "line_item_original_item_fk"`
)
await queryRunner.query(
`ALTER TABLE "line_item" DROP CONSTRAINT "line_item_order_edit_fk"`
)
await queryRunner.query(
`ALTER TABLE "line_item" DROP COLUMN "original_item_id"`
)
await queryRunner.query(
`ALTER TABLE "line_item" DROP COLUMN "order_edit_id"`
)
}
}
@@ -1,124 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class paymentCollection1664880666982 implements MigrationInterface {
name = "paymentCollection1664880666982"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE "PAYMENT_COLLECTION_TYPE_ENUM" AS ENUM ('order_edit');
CREATE TYPE "PAYMENT_COLLECTION_STATUS_ENUM" AS ENUM (
'not_paid', 'awaiting', 'authorized',
'partially_authorized', 'canceled'
);
CREATE TABLE IF NOT EXISTS payment_collection
(
id character varying NOT NULL,
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 NULL,
type "PAYMENT_COLLECTION_TYPE_ENUM" NOT NULL,
status "PAYMENT_COLLECTION_STATUS_ENUM" NOT NULL,
description text NULL,
amount integer NOT NULL,
authorized_amount integer NULL,
region_id character varying NOT NULL,
currency_code character varying NOT NULL,
metadata jsonb NULL,
created_by character varying NOT NULL,
CONSTRAINT "PK_payment_collection_id" PRIMARY KEY ("id")
);
CREATE INDEX "IDX_payment_collection_region_id" ON "payment_collection" ("region_id") WHERE deleted_at IS NULL;
CREATE INDEX "IDX_payment_collection_currency_code" ON "payment_collection" ("currency_code") WHERE deleted_at IS NULL;
ALTER TABLE "payment_collection" ADD CONSTRAINT "FK_payment_collection_region_id" FOREIGN KEY ("region_id") REFERENCES "region"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
CREATE TABLE payment_collection_sessions
(
payment_collection_id CHARACTER VARYING NOT NULL,
payment_session_id CHARACTER VARYING NOT NULL,
CONSTRAINT "PK_payment_collection_sessions" PRIMARY KEY ("payment_collection_id", "payment_session_id")
);
CREATE INDEX "IDX_payment_collection_sessions_payment_collection_id" ON "payment_collection_sessions" ("payment_collection_id");
CREATE INDEX "IDX_payment_collection_sessions_payment_session_id" ON "payment_collection_sessions" ("payment_session_id");
ALTER TABLE "payment_collection_sessions" ADD CONSTRAINT "FK_payment_collection_sessions_payment_collection_id" FOREIGN KEY ("payment_collection_id") REFERENCES "payment_collection"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "payment_collection_sessions" ADD CONSTRAINT "FK_payment_collection_sessions_payment_session_id" FOREIGN KEY ("payment_session_id") REFERENCES "payment_session"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
CREATE TABLE payment_collection_payments
(
payment_collection_id CHARACTER VARYING NOT NULL,
payment_id CHARACTER VARYING NOT NULL,
CONSTRAINT "PK_payment_collection_payments" PRIMARY KEY ("payment_collection_id", "payment_id")
);
CREATE INDEX "IDX_payment_collection_payments_payment_collection_id" ON "payment_collection_payments" ("payment_collection_id");
CREATE INDEX "IDX_payment_collection_payments_payment_id" ON "payment_collection_payments" ("payment_id");
ALTER TABLE "payment_collection_payments" ADD CONSTRAINT "FK_payment_collection_payments_payment_collection_id" FOREIGN KEY ("payment_collection_id") REFERENCES "payment_collection"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "payment_collection_payments" ADD CONSTRAINT "FK_payment_collection_payments_payment_id" FOREIGN KEY ("payment_id") REFERENCES "payment"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE order_edit ADD COLUMN payment_collection_id character varying NULL;
CREATE INDEX "IDX_order_edit_payment_collection_id" ON "order_edit" ("payment_collection_id");
ALTER TABLE "order_edit" ADD CONSTRAINT "FK_order_edit_payment_collection_id" FOREIGN KEY ("payment_collection_id") REFERENCES "payment_collection"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE payment_session ADD COLUMN payment_authorized_at timestamp WITH time zone NULL;
ALTER TABLE payment_session ADD COLUMN amount integer NULL;
ALTER TABLE payment_session ALTER COLUMN cart_id DROP NOT NULL;
ALTER TABLE refund ADD COLUMN payment_id character varying NULL;
CREATE INDEX "IDX_refund_payment_id" ON "refund" ("payment_id");
ALTER TABLE "refund" ADD CONSTRAINT "FK_refund_payment_id" FOREIGN KEY ("payment_id") REFERENCES "payment"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE refund ALTER COLUMN order_id DROP NOT NULL;
`)
// Add missing indexes
await queryRunner.query(`
CREATE INDEX "IDX_order_edit_order_id" ON "order_edit" ("order_id");
CREATE INDEX "IDX_money_amount_currency_code" ON "money_amount" ("currency_code");
CREATE INDEX "IDX_order_currency_code" ON "order" ("currency_code");
CREATE INDEX "IDX_payment_currency_code" ON "payment" ("currency_code");
CREATE INDEX "IDX_region_currency_code" ON "region" ("currency_code");
`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "IDX_order_edit_payment_collection_id";
ALTER TABLE order_edit DROP CONSTRAINT "FK_order_edit_payment_collection_id";
DROP INDEX "IDX_refund_payment_id";
ALTER TABLE refund DROP CONSTRAINT "FK_refund_payment_id";
ALTER TABLE refund ALTER COLUMN order_id SET NOT NULL;
ALTER TABLE payment_collection DROP CONSTRAINT "FK_payment_collection_region_id";
ALTER TABLE payment_collection_sessions DROP CONSTRAINT "FK_payment_collection_sessions_payment_collection_id";
ALTER TABLE payment_collection_sessions DROP CONSTRAINT "FK_payment_collection_sessions_payment_session_id";
ALTER TABLE payment_collection_payments DROP CONSTRAINT "FK_payment_collection_payments_payment_collection_id";
ALTER TABLE payment_collection_payments DROP CONSTRAINT "FK_payment_collection_payments_payment_id";
ALTER TABLE order_edit DROP COLUMN payment_collection_id;
ALTER TABLE payment_session DROP COLUMN payment_authorized_at;
ALTER TABLE payment_session DROP COLUMN amount;
ALTER TABLE payment_session ALTER COLUMN cart_id SET NOT NULL;
ALTER TABLE refund DROP COLUMN payment_id;
DROP TABLE payment_collection;
DROP TABLE payment_collection_sessions;
DROP TABLE payment_collection_payments;
DROP TYPE "PAYMENT_COLLECTION_TYPE_ENUM";
DROP TYPE "PAYMENT_COLLECTION_STATUS_ENUM";
`)
await queryRunner.query(`
DROP INDEX "IDX_order_edit_order_id";
DROP INDEX "IDX_money_amount_currency_code";
DROP INDEX "IDX_order_currency_code";
DROP INDEX "IDX_payment_currency_code";
DROP INDEX "IDX_region_currency_code";
`)
}
}
@@ -1,24 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import AnalyticsFeatureFlag from "../loaders/feature-flags/analytics"
export const featureFlag = AnalyticsFeatureFlag.key
export class addAnalyticsConfig1666173221888 implements MigrationInterface {
name = "addAnalyticsConfig1666173221888"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "analytics_config" ("id" character varying NOT NULL, "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, "user_id" character varying NOT NULL, "opt_out" boolean NOT NULL DEFAULT false, "anonymize" boolean NOT NULL DEFAULT false, CONSTRAINT "PK_93505647c5d7cb479becb810b0f" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_379ca70338ce9991f3affdeedf" ON "analytics_config" ("id", "user_id") WHERE deleted_at IS NULL`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX "IDX_379ca70338ce9991f3affdeedf"`
)
await queryRunner.query(`DROP TABLE "analytics_config"`)
}
}
Loaded 100 of 226 files, more files were not shown because too many files have changed in this diff. Show more