feat(medusa): Remove sqlite support (#4026)
This commit is contained in:
committed by
GitHub
parent
e2d29d35c4
commit
a91987fab3
8
.changeset/tall-humans-count.md
Normal file
8
.changeset/tall-humans-count.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@medusajs/medusa-cli": patch
|
||||
"medusa-plugin-contentful": patch
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/utils": patch
|
||||
---
|
||||
|
||||
feat(medusa): Remove sqlite support
|
||||
2
.github/workflows/test-cli-with-database.yml
vendored
2
.github/workflows/test-cli-with-database.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
db: [sqlite, postgres]
|
||||
db: [postgres]
|
||||
|
||||
services:
|
||||
redis:
|
||||
|
||||
@@ -27,8 +27,6 @@ const keepTables = [
|
||||
"currency",
|
||||
]
|
||||
|
||||
let dataSourceType = "postgresql"
|
||||
|
||||
const DbTestUtil = {
|
||||
db_: null,
|
||||
|
||||
@@ -47,11 +45,7 @@ const DbTestUtil = {
|
||||
|
||||
const manager = this.db_.manager
|
||||
|
||||
if (dataSourceType === "sqlite") {
|
||||
await manager.query(`PRAGMA foreign_keys = OFF`)
|
||||
} else {
|
||||
await manager.query(`SET session_replication_role = 'replica';`)
|
||||
}
|
||||
await manager.query(`SET session_replication_role = 'replica';`)
|
||||
|
||||
for (const entity of entities) {
|
||||
if (
|
||||
@@ -64,11 +58,8 @@ const DbTestUtil = {
|
||||
await manager.query(`DELETE
|
||||
FROM "${entity.tableName}";`)
|
||||
}
|
||||
if (dataSourceType === "sqlite") {
|
||||
await manager.query(`PRAGMA foreign_keys = ON`)
|
||||
} else {
|
||||
await manager.query(`SET session_replication_role = 'origin';`)
|
||||
}
|
||||
|
||||
await manager.query(`SET session_replication_role = 'origin';`)
|
||||
},
|
||||
|
||||
shutdown: async function () {
|
||||
@@ -82,7 +73,7 @@ const instance = DbTestUtil
|
||||
module.exports = {
|
||||
initDb: async function ({ cwd, database_extra }) {
|
||||
const { configModule } = getConfigFile(cwd, `medusa-config`)
|
||||
const { projectConfig, featureFlags } = configModule
|
||||
const { featureFlags } = configModule
|
||||
|
||||
const featureFlagsLoader =
|
||||
require("@medusajs/medusa/dist/loaders/feature-flags").default
|
||||
@@ -91,69 +82,53 @@ module.exports = {
|
||||
const modelsLoader = require("@medusajs/medusa/dist/loaders/models").default
|
||||
const entities = modelsLoader({}, { register: false })
|
||||
|
||||
if (projectConfig.database_type === "sqlite") {
|
||||
dataSourceType = "sqlite"
|
||||
const dataSource = new DataSource({
|
||||
type: "sqlite",
|
||||
database: projectConfig.database_database,
|
||||
synchronize: true,
|
||||
entities,
|
||||
extra: database_extra ?? {},
|
||||
})
|
||||
await dbFactory.createFromTemplate(DB_NAME)
|
||||
|
||||
const dbDataSource = await dataSource.initialize()
|
||||
|
||||
instance.setDb(dbDataSource)
|
||||
return dbDataSource
|
||||
} else {
|
||||
await dbFactory.createFromTemplate(DB_NAME)
|
||||
|
||||
// get migrations with enabled featureflags
|
||||
const migrationDir = path.resolve(
|
||||
path.join(
|
||||
__dirname,
|
||||
`../../`,
|
||||
`node_modules`,
|
||||
`@medusajs`,
|
||||
`medusa`,
|
||||
`dist`,
|
||||
`migrations`,
|
||||
`*.js`
|
||||
)
|
||||
// get migrations with enabled featureflags
|
||||
const migrationDir = path.resolve(
|
||||
path.join(
|
||||
__dirname,
|
||||
`../../`,
|
||||
`node_modules`,
|
||||
`@medusajs`,
|
||||
`medusa`,
|
||||
`dist`,
|
||||
`migrations`,
|
||||
`*.js`
|
||||
)
|
||||
)
|
||||
|
||||
const {
|
||||
getEnabledMigrations,
|
||||
getModuleSharedResources,
|
||||
} = require("@medusajs/medusa/dist/commands/utils/get-migrations")
|
||||
const {
|
||||
getEnabledMigrations,
|
||||
getModuleSharedResources,
|
||||
} = require("@medusajs/medusa/dist/commands/utils/get-migrations")
|
||||
|
||||
const { migrations: moduleMigrations, models: moduleModels } =
|
||||
getModuleSharedResources(configModule, featureFlagsRouter)
|
||||
const { migrations: moduleMigrations, models: moduleModels } =
|
||||
getModuleSharedResources(configModule, featureFlagsRouter)
|
||||
|
||||
const enabledMigrations = getEnabledMigrations([migrationDir], (flag) =>
|
||||
featureFlagsRouter.isFeatureEnabled(flag)
|
||||
)
|
||||
const enabledMigrations = getEnabledMigrations([migrationDir], (flag) =>
|
||||
featureFlagsRouter.isFeatureEnabled(flag)
|
||||
)
|
||||
|
||||
const enabledEntities = entities.filter(
|
||||
(e) => typeof e.isFeatureEnabled === "undefined" || e.isFeatureEnabled()
|
||||
)
|
||||
const enabledEntities = entities.filter(
|
||||
(e) => typeof e.isFeatureEnabled === "undefined" || e.isFeatureEnabled()
|
||||
)
|
||||
|
||||
const dbDataSource = new DataSource({
|
||||
type: "postgres",
|
||||
url: DB_URL,
|
||||
entities: enabledEntities.concat(moduleModels),
|
||||
migrations: enabledMigrations.concat(moduleMigrations),
|
||||
extra: database_extra ?? {},
|
||||
name: "integration-tests",
|
||||
})
|
||||
const dbDataSource = new DataSource({
|
||||
type: "postgres",
|
||||
url: DB_URL,
|
||||
entities: enabledEntities.concat(moduleModels),
|
||||
migrations: enabledMigrations.concat(moduleMigrations),
|
||||
extra: database_extra ?? {},
|
||||
name: "integration-tests",
|
||||
})
|
||||
|
||||
await dbDataSource.initialize()
|
||||
await dbDataSource.initialize()
|
||||
|
||||
await dbDataSource.runMigrations()
|
||||
await dbDataSource.runMigrations()
|
||||
|
||||
instance.setDb(dbDataSource)
|
||||
return dbDataSource
|
||||
}
|
||||
instance.setDb(dbDataSource)
|
||||
return dbDataSource
|
||||
},
|
||||
useDb: function () {
|
||||
return instance
|
||||
|
||||
@@ -363,15 +363,8 @@ export const newStarter = async (args) => {
|
||||
}
|
||||
|
||||
const medusaConfig = getMedusaConfig(rootPath)
|
||||
if (medusaConfig) {
|
||||
let isPostgres = false
|
||||
if (medusaConfig.projectConfig) {
|
||||
const databaseType = medusaConfig.projectConfig.database_type
|
||||
isPostgres = databaseType === "postgres"
|
||||
}
|
||||
|
||||
if (!isPostgres && seed) {
|
||||
await attemptSeed(rootPath)
|
||||
}
|
||||
if (medusaConfig && seed) {
|
||||
await attemptSeed(rootPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@
|
||||
"regenerator-runtime": "^0.13.11",
|
||||
"resolve-cwd": "^3.0.0",
|
||||
"semver": "^7.3.8",
|
||||
"sqlite3": "^5.0.2",
|
||||
"stack-trace": "^0.0.10",
|
||||
"ulid": "^2.3.0",
|
||||
"url": "^0.11.0",
|
||||
|
||||
@@ -19,7 +19,7 @@ import inquirer from "inquirer"
|
||||
import reporter from "../reporter"
|
||||
import { getPackageManager, setPackageManager } from "../util/package-manager"
|
||||
|
||||
const removeUndefined = obj => {
|
||||
const removeUndefined = (obj) => {
|
||||
return Object.fromEntries(
|
||||
Object.entries(obj)
|
||||
.filter(([_, v]) => v != null)
|
||||
@@ -50,21 +50,21 @@ const isAlreadyGitRepository = async () => {
|
||||
try {
|
||||
return await spawn(`git rev-parse --is-inside-work-tree`, {
|
||||
stdio: `pipe`,
|
||||
}).then(output => output.stdout === `true`)
|
||||
}).then((output) => output.stdout === `true`)
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize newly cloned directory as a git repo
|
||||
const gitInit = async rootPath => {
|
||||
const gitInit = async (rootPath) => {
|
||||
reporter.info(`Initialising git in ${rootPath}`)
|
||||
|
||||
return await spawn(`git init`, { cwd: rootPath })
|
||||
}
|
||||
|
||||
// Create a .gitignore file if it is missing in the new directory
|
||||
const maybeCreateGitIgnore = async rootPath => {
|
||||
const maybeCreateGitIgnore = async (rootPath) => {
|
||||
if (existsSync(sysPath.join(rootPath, `.gitignore`))) {
|
||||
return
|
||||
}
|
||||
@@ -98,7 +98,7 @@ const createInitialGitCommit = async (rootPath, starterUrl) => {
|
||||
}
|
||||
|
||||
// Executes `npm install` or `yarn install` in rootPath.
|
||||
const install = async rootPath => {
|
||||
const install = async (rootPath) => {
|
||||
const prevDir = process.cwd()
|
||||
|
||||
reporter.info(`Installing packages...`)
|
||||
@@ -128,7 +128,7 @@ const install = async rootPath => {
|
||||
}
|
||||
}
|
||||
|
||||
const ignored = path => !/^\.(git|hg)$/.test(sysPath.basename(path))
|
||||
const ignored = (path) => !/^\.(git|hg)$/.test(sysPath.basename(path))
|
||||
|
||||
// Copy starter from file system.
|
||||
const copy = async (starterPath, rootPath) => {
|
||||
@@ -187,13 +187,13 @@ const clone = async (hostInfo, rootPath) => {
|
||||
rootPath,
|
||||
`--recursive`,
|
||||
`--depth=1`,
|
||||
].filter(arg => Boolean(arg))
|
||||
].filter((arg) => Boolean(arg))
|
||||
|
||||
await execa(`git`, args, {})
|
||||
.then(() => {
|
||||
reporter.success(createAct, `Created starter directory layout`)
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
reporter.failure(createAct, `Failed to clone repository`)
|
||||
throw err
|
||||
})
|
||||
@@ -207,7 +207,7 @@ const clone = async (hostInfo, rootPath) => {
|
||||
if (!isGit) await createInitialGitCommit(rootPath, url)
|
||||
}
|
||||
|
||||
const getMedusaConfig = rootPath => {
|
||||
const getMedusaConfig = (rootPath) => {
|
||||
try {
|
||||
const configPath = sysPath.join(rootPath, "medusa-config.js")
|
||||
if (existsSync(configPath)) {
|
||||
@@ -268,7 +268,7 @@ const getPaths = async (starterPath, rootPath) => {
|
||||
return { starterPath, rootPath, selectedOtherStarter }
|
||||
}
|
||||
|
||||
const successMessage = path => {
|
||||
const successMessage = (path) => {
|
||||
reporter.info(`Your new Medusa project is ready for you! To start developing run:
|
||||
|
||||
cd ${path}
|
||||
@@ -284,7 +284,7 @@ const defaultDBCreds = {
|
||||
host: "localhost",
|
||||
}
|
||||
|
||||
const verifyPgCreds = async creds => {
|
||||
const verifyPgCreds = async (creds) => {
|
||||
const pool = new Pool(creds)
|
||||
return new Promise((resolve, reject) => {
|
||||
pool.query("SELECT NOW()", (err, res) => {
|
||||
@@ -361,7 +361,7 @@ Do you wish to continue with these credentials?
|
||||
message: `DB database`,
|
||||
},
|
||||
])
|
||||
.then(async answers => {
|
||||
.then(async (answers) => {
|
||||
const collectedCreds = Object.assign({}, credentials, {
|
||||
user: answers.user,
|
||||
password: answers.password,
|
||||
@@ -372,14 +372,14 @@ Do you wish to continue with these credentials?
|
||||
|
||||
switch (answers.continueWithDefault) {
|
||||
case "Continue": {
|
||||
const done = await verifyPgCreds(credentials).catch(_ => false)
|
||||
const done = await verifyPgCreds(credentials).catch((_) => false)
|
||||
if (done) {
|
||||
return credentials
|
||||
}
|
||||
return false
|
||||
}
|
||||
case "Change credentials": {
|
||||
const done = await verifyPgCreds(collectedCreds).catch(_ => false)
|
||||
const done = await verifyPgCreds(collectedCreds).catch((_) => false)
|
||||
if (done) {
|
||||
return collectedCreds
|
||||
}
|
||||
@@ -412,7 +412,7 @@ const setupDB = async (dbName, dbCreds = {}) => {
|
||||
.then(() => {
|
||||
reporter.success(dbActivity, `Created database "${dbName}"`)
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
if (err.name === "PDG_ERR::DuplicateDatabase") {
|
||||
reporter.success(
|
||||
dbActivity,
|
||||
@@ -456,7 +456,7 @@ const setupEnvVars = async (
|
||||
}
|
||||
}
|
||||
|
||||
const runMigrations = async rootPath => {
|
||||
const runMigrations = async (rootPath) => {
|
||||
const migrationActivity = reporter.activity("Applying database migrations...")
|
||||
|
||||
const cliPath = sysPath.join(
|
||||
@@ -472,7 +472,7 @@ const runMigrations = async rootPath => {
|
||||
.then(() => {
|
||||
reporter.success(migrationActivity, "Database migrations completed.")
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
reporter.failure(
|
||||
migrationActivity,
|
||||
"Failed to migrate database you must complete migration manually before starting your server."
|
||||
@@ -481,7 +481,7 @@ const runMigrations = async rootPath => {
|
||||
})
|
||||
}
|
||||
|
||||
const attemptSeed = async rootPath => {
|
||||
const attemptSeed = async (rootPath) => {
|
||||
const seedActivity = reporter.activity("Seeding database")
|
||||
|
||||
const pkgPath = sysPath.resolve(rootPath, "package.json")
|
||||
@@ -499,7 +499,7 @@ const attemptSeed = async rootPath => {
|
||||
.then(() => {
|
||||
reporter.success(seedActivity, "Seed completed")
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
reporter.failure(seedActivity, "Failed to complete seed; skipping")
|
||||
console.error(err)
|
||||
})
|
||||
@@ -517,7 +517,7 @@ const attemptSeed = async rootPath => {
|
||||
/**
|
||||
* Main function that clones or copies the starter.
|
||||
*/
|
||||
export const newStarter = async args => {
|
||||
export const newStarter = async (args) => {
|
||||
track("CLI_NEW")
|
||||
|
||||
const {
|
||||
@@ -614,33 +614,29 @@ medusa new ${rootPath} [url-to-starter]
|
||||
const medusaConfig = getMedusaConfig(rootPath)
|
||||
|
||||
let isPostgres = false
|
||||
if (medusaConfig && medusaConfig.projectConfig) {
|
||||
const databaseType = medusaConfig.projectConfig.database_type
|
||||
isPostgres = databaseType === "postgres"
|
||||
}
|
||||
|
||||
track("CLI_NEW_LAYOUT_COMPLETED")
|
||||
|
||||
let creds = dbCredentials
|
||||
|
||||
if (isPostgres && !useDefaults && !skipDb && !skipEnv) {
|
||||
if (!useDefaults && !skipDb && !skipEnv) {
|
||||
creds = await interactiveDbCreds(rootPath, dbCredentials)
|
||||
}
|
||||
|
||||
if (creds === null) {
|
||||
reporter.info("Skipping automatic database setup")
|
||||
} else {
|
||||
if (!skipDb && isPostgres) {
|
||||
if (!skipDb) {
|
||||
track("CLI_NEW_SETUP_DB")
|
||||
await setupDB(rootPath, creds)
|
||||
}
|
||||
|
||||
if (!skipEnv) {
|
||||
track("CLI_NEW_SETUP_ENV")
|
||||
await setupEnvVars(rootPath, rootPath, creds, isPostgres)
|
||||
await setupEnvVars(rootPath, rootPath, creds)
|
||||
}
|
||||
|
||||
if (!skipMigrations && isPostgres) {
|
||||
if (!skipMigrations) {
|
||||
track("CLI_NEW_RUN_MIGRATIONS")
|
||||
await runMigrations(rootPath)
|
||||
}
|
||||
|
||||
@@ -45,21 +45,6 @@ Manage the content of your storefront with rich Content Management System (CMS)
|
||||
DATABASE_URL=<YOUR_DB_URL>
|
||||
```
|
||||
|
||||
3\. In `medusa-config.js`, enable PostgreSQL and remove the SQLite configurations:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
projectConfig: {
|
||||
// ...
|
||||
database_url: DATABASE_URL,
|
||||
database_type: "postgres",
|
||||
// REMOVE OR COMMENT OUT THE BELOW:
|
||||
// database_database: "./medusa-db.sql",
|
||||
// database_type: "sqlite",
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
4\. Migrate the content types into Contentful with the following command:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -58,8 +58,7 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) {
|
||||
|
||||
const featureFlagRouter = featureFlagLoader(configModule)
|
||||
|
||||
const dbType = configModule.projectConfig.database_type
|
||||
if (migrate && dbType !== "sqlite") {
|
||||
if (migrate) {
|
||||
const { coreMigrations } = getMigrations(directory, featureFlagRouter)
|
||||
|
||||
const { migrations: moduleMigrations } = getModuleSharedResources(
|
||||
@@ -68,7 +67,7 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) {
|
||||
)
|
||||
|
||||
const connectionOptions = {
|
||||
type: configModule.projectConfig.database_type,
|
||||
type: "postgres",
|
||||
database: configModule.projectConfig.database_database,
|
||||
schema: configModule.projectConfig.database_schema,
|
||||
url: configModule.projectConfig.database_url,
|
||||
@@ -171,6 +170,33 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) {
|
||||
await shippingOptionService.withTransaction(tx).create(so)
|
||||
}
|
||||
|
||||
const createProductCategory = async (
|
||||
parameters,
|
||||
parentCategoryId: string | null = null
|
||||
) => {
|
||||
// default to the categories being visible and public
|
||||
parameters.is_active = parameters.is_active || true
|
||||
parameters.is_internal = parameters.is_internal || false
|
||||
parameters.parent_category_id = parentCategoryId
|
||||
|
||||
const categoryChildren = parameters.category_children || []
|
||||
delete parameters.category_children
|
||||
|
||||
const category = await productCategoryService
|
||||
.withTransaction(tx)
|
||||
.create(parameters as CreateProductCategoryInput)
|
||||
|
||||
if (categoryChildren.length) {
|
||||
for (const categoryChild of categoryChildren) {
|
||||
await createProductCategory(categoryChild, category.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const c of categories) {
|
||||
await createProductCategory(c)
|
||||
}
|
||||
|
||||
for (const p of products) {
|
||||
const variants = p.variants
|
||||
delete p.variants
|
||||
@@ -209,35 +235,6 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const createProductCategory = async (
|
||||
parameters,
|
||||
parentCategoryId: string | null = null
|
||||
) => {
|
||||
// default to the categories being visible and public
|
||||
parameters.is_active = parameters.is_active || true
|
||||
parameters.is_internal = parameters.is_internal || false
|
||||
parameters.parent_category_id = parentCategoryId
|
||||
|
||||
const categoryChildren = parameters.category_children || []
|
||||
delete parameters.category_children
|
||||
|
||||
const category = await productCategoryService
|
||||
.withTransaction(tx)
|
||||
.create(parameters as CreateProductCategoryInput)
|
||||
|
||||
if (categoryChildren.length) {
|
||||
for (const categoryChild of categoryChildren) {
|
||||
await createProductCategory(categoryChild, category.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dbType !== "sqlite") {
|
||||
for (const c of categories) {
|
||||
await createProductCategory(c, null)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
track("CLI_SEED_COMPLETED")
|
||||
|
||||
@@ -58,12 +58,6 @@ export default (rootDirectory: string): ConfigModule => {
|
||||
)
|
||||
}
|
||||
|
||||
if (!configModule?.projectConfig?.database_type) {
|
||||
console.log(
|
||||
`[medusa-config] ⚠️ database_type not found. fallback to default sqlite.`
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
projectConfig: {
|
||||
jwt_secret: jwt_secret ?? "supersecret",
|
||||
|
||||
@@ -39,10 +39,8 @@ export default async ({
|
||||
}: Options): Promise<DataSource> => {
|
||||
const entities = container.resolve("db_entities")
|
||||
|
||||
const isSqlite = configModule.projectConfig.database_type === "sqlite"
|
||||
|
||||
dataSource = new DataSource({
|
||||
type: configModule.projectConfig.database_type,
|
||||
type: "postgres",
|
||||
url: configModule.projectConfig.database_url,
|
||||
database: configModule.projectConfig.database_database,
|
||||
extra: configModule.projectConfig.database_extra || {},
|
||||
@@ -54,12 +52,33 @@ export default async ({
|
||||
(configModule.projectConfig.database_logging || false),
|
||||
} as DataSourceOptions)
|
||||
|
||||
await dataSource.initialize()
|
||||
try {
|
||||
await dataSource.initialize()
|
||||
} catch (err) {
|
||||
// database name does not exist
|
||||
if (err.code === "3D000") {
|
||||
throw new Error(
|
||||
`Specified database does not exist. Please create it and try again.\n${err.message}`
|
||||
)
|
||||
}
|
||||
|
||||
if (isSqlite) {
|
||||
await dataSource.query(`PRAGMA foreign_keys = OFF`)
|
||||
await dataSource.synchronize()
|
||||
await dataSource.query(`PRAGMA foreign_keys = ON`)
|
||||
throw err
|
||||
}
|
||||
|
||||
// If migrations are not included in the config, we assume you are attempting to start the server
|
||||
// Therefore, throw if the database is not migrated
|
||||
if (!dataSource.migrations?.length) {
|
||||
try {
|
||||
await dataSource.query(`select * from migrations`)
|
||||
} catch (err) {
|
||||
if (err.code === "42P01") {
|
||||
throw new Error(
|
||||
`Migrations missing. Please run 'medusa migrations run' and try again.`
|
||||
)
|
||||
}
|
||||
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
return dataSource
|
||||
|
||||
@@ -9,15 +9,14 @@ import {
|
||||
} from "typeorm"
|
||||
import {
|
||||
DbAwareColumn,
|
||||
resolveDbGenerationStrategy,
|
||||
resolveDbType,
|
||||
resolveDbType
|
||||
} from "../utils/db-aware-column"
|
||||
|
||||
import { BaseEntity } from "../interfaces/models/base-entity"
|
||||
import { Cart } from "./cart"
|
||||
import { Order } from "./order"
|
||||
import { generateEntityId } from "../utils/generate-entity-id"
|
||||
import { manualAutoIncrement } from "../utils/manual-auto-increment"
|
||||
import { Cart } from "./cart"
|
||||
import { Order } from "./order"
|
||||
|
||||
export enum DraftOrderStatus {
|
||||
OPEN = "open",
|
||||
@@ -31,7 +30,7 @@ export class DraftOrder extends BaseEntity {
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
@Generated(resolveDbGenerationStrategy("increment"))
|
||||
@Generated("increment")
|
||||
display_id: number
|
||||
|
||||
@Index()
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
} from "typeorm"
|
||||
import { DbAwareColumn, resolveDbGenerationStrategy, resolveDbType, } from "../utils/db-aware-column"
|
||||
import { DbAwareColumn, resolveDbType } from "../utils/db-aware-column"
|
||||
import { FeatureFlagColumn, FeatureFlagDecorators, } from "../utils/feature-flag-decorators"
|
||||
|
||||
import { BaseEntity } from "../interfaces/models/base-entity"
|
||||
@@ -86,7 +86,7 @@ export class Order extends BaseEntity {
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
@Generated(resolveDbGenerationStrategy("increment"))
|
||||
@Generated("increment")
|
||||
display_id: number
|
||||
|
||||
@Index()
|
||||
|
||||
@@ -1,52 +1,12 @@
|
||||
import { Column, ColumnOptions, ColumnType } from "typeorm"
|
||||
import path from "path"
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
|
||||
const pgSqliteTypeMapping: { [key: string]: ColumnType } = {
|
||||
increment: "rowid",
|
||||
timestamptz: "datetime",
|
||||
jsonb: "simple-json",
|
||||
enum: "text",
|
||||
}
|
||||
|
||||
const pgSqliteGenerationMapping: {
|
||||
[key: string]: "increment" | "uuid" | "rowid"
|
||||
} = {
|
||||
increment: "rowid",
|
||||
}
|
||||
|
||||
let dbType: string
|
||||
export function resolveDbType(pgSqlType: ColumnType): ColumnType {
|
||||
if (!dbType) {
|
||||
const { configModule } = getConfigFile(
|
||||
path.resolve("."),
|
||||
`medusa-config`
|
||||
) as any
|
||||
|
||||
dbType = configModule?.projectConfig?.database_type || "postgres"
|
||||
}
|
||||
|
||||
if (dbType === "sqlite" && (pgSqlType as string) in pgSqliteTypeMapping) {
|
||||
return pgSqliteTypeMapping[pgSqlType.toString()]
|
||||
}
|
||||
return pgSqlType
|
||||
}
|
||||
|
||||
export function resolveDbGenerationStrategy(
|
||||
pgSqlType: "increment" | "uuid" | "rowid"
|
||||
): "increment" | "uuid" | "rowid" {
|
||||
if (!dbType) {
|
||||
const { configModule } = getConfigFile(
|
||||
path.resolve("."),
|
||||
`medusa-config`
|
||||
) as any
|
||||
|
||||
dbType = configModule?.projectConfig?.database_type || "postgres"
|
||||
}
|
||||
|
||||
if (dbType === "sqlite" && pgSqlType in pgSqliteTypeMapping) {
|
||||
return pgSqliteGenerationMapping[pgSqlType]
|
||||
}
|
||||
return pgSqlType
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,5 @@
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
import path from "path"
|
||||
import { getConnection } from "typeorm"
|
||||
|
||||
export async function manualAutoIncrement(
|
||||
tableName: string
|
||||
): Promise<number | null> {
|
||||
const { configModule } = getConfigFile(
|
||||
path.resolve("."),
|
||||
`medusa-config`
|
||||
) as any
|
||||
|
||||
const dbType = configModule?.projectConfig?.database_type || "postgres"
|
||||
|
||||
if (dbType === "sqlite") {
|
||||
const connection = getConnection()
|
||||
const [rec] = await connection.query(
|
||||
`SELECT MAX(rowid) as mr FROM "${tableName}"`
|
||||
)
|
||||
|
||||
let mr = 0
|
||||
if (rec && rec.mr) {
|
||||
mr = rec.mr
|
||||
}
|
||||
return mr + 1
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -31,11 +31,13 @@ export type ProjectConfigOptions = {
|
||||
cookie_secret?: string
|
||||
|
||||
database_url?: string
|
||||
database_type: string
|
||||
database_database?: string
|
||||
database_schema?: string
|
||||
database_logging: LoggerOptions
|
||||
|
||||
// @deprecated - only postgres is supported, so this config has no effect
|
||||
database_type?: string
|
||||
|
||||
http_compression?: HttpCompressionOptions
|
||||
|
||||
database_extra?: Record<string, unknown> & {
|
||||
|
||||
@@ -1,52 +1,12 @@
|
||||
import path from "path"
|
||||
import { Column, ColumnOptions, ColumnType } from "typeorm"
|
||||
import getConfigFile from "./get-config-file"
|
||||
|
||||
const pgSqliteTypeMapping: { [key: string]: ColumnType } = {
|
||||
increment: "rowid",
|
||||
timestamptz: "datetime",
|
||||
jsonb: "simple-json",
|
||||
enum: "text",
|
||||
}
|
||||
|
||||
const pgSqliteGenerationMapping: {
|
||||
[key: string]: "increment" | "uuid" | "rowid"
|
||||
} = {
|
||||
increment: "rowid",
|
||||
}
|
||||
|
||||
let dbType: string
|
||||
export function resolveDbType(pgSqlType: ColumnType): ColumnType {
|
||||
if (!dbType) {
|
||||
const { configModule } = getConfigFile(
|
||||
path.resolve("."),
|
||||
`medusa-config`
|
||||
) as any
|
||||
|
||||
dbType = configModule?.projectConfig?.database_type || "postgres"
|
||||
}
|
||||
|
||||
if (dbType === "sqlite" && (pgSqlType as string) in pgSqliteTypeMapping) {
|
||||
return pgSqliteTypeMapping[pgSqlType.toString()]
|
||||
}
|
||||
return pgSqlType
|
||||
}
|
||||
|
||||
export function resolveDbGenerationStrategy(
|
||||
pgSqlType: "increment" | "uuid" | "rowid"
|
||||
): "increment" | "uuid" | "rowid" {
|
||||
if (!dbType) {
|
||||
const { configModule } = getConfigFile(
|
||||
path.resolve("."),
|
||||
`medusa-config`
|
||||
) as any
|
||||
|
||||
dbType = configModule?.projectConfig?.database_type || "postgres"
|
||||
}
|
||||
|
||||
if (dbType === "sqlite" && pgSqlType in pgSqliteTypeMapping) {
|
||||
return pgSqliteGenerationMapping[pgSqlType]
|
||||
}
|
||||
return pgSqlType
|
||||
}
|
||||
|
||||
|
||||
144
yarn.lock
144
yarn.lock
@@ -5781,25 +5781,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mapbox/node-pre-gyp@npm:^1.0.0":
|
||||
version: 1.0.10
|
||||
resolution: "@mapbox/node-pre-gyp@npm:1.0.10"
|
||||
dependencies:
|
||||
detect-libc: ^2.0.0
|
||||
https-proxy-agent: ^5.0.0
|
||||
make-dir: ^3.1.0
|
||||
node-fetch: ^2.6.7
|
||||
nopt: ^5.0.0
|
||||
npmlog: ^5.0.1
|
||||
rimraf: ^3.0.2
|
||||
semver: ^7.3.5
|
||||
tar: ^6.1.11
|
||||
bin:
|
||||
node-pre-gyp: bin/node-pre-gyp
|
||||
checksum: 469f3bc00778c76e0a7ffaf40742482462e05fec31b53c55ad6d6a892894046c0db7bb8543ed49b2cf1926dfcd9af1289985c367c5d20076939f8a889f686e45
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mdx-js/mdx@npm:^1.6.22":
|
||||
version: 1.6.22
|
||||
resolution: "@mdx-js/mdx@npm:1.6.22"
|
||||
@@ -6057,7 +6038,6 @@ __metadata:
|
||||
regenerator-runtime: ^0.13.11
|
||||
resolve-cwd: ^3.0.0
|
||||
semver: ^7.3.8
|
||||
sqlite3: ^5.0.2
|
||||
stack-trace: ^0.0.10
|
||||
ulid: ^2.3.0
|
||||
url: ^0.11.0
|
||||
@@ -13057,17 +13037,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"agentkeepalive@npm:^4.1.3":
|
||||
version: 4.3.0
|
||||
resolution: "agentkeepalive@npm:4.3.0"
|
||||
dependencies:
|
||||
debug: ^4.1.0
|
||||
depd: ^2.0.0
|
||||
humanize-ms: ^1.2.1
|
||||
checksum: 61cbdab12d45e82e9ae515b0aa8d09617b66f72409e541a646dd7be4b7260d335d7f56a38079ad305bf0ffb8405592a459faf1294111289107f48352a20c2799
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"agentkeepalive@npm:^4.2.1":
|
||||
version: 4.2.1
|
||||
resolution: "agentkeepalive@npm:4.2.1"
|
||||
@@ -15474,7 +15443,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"cacache@npm:^15.0.5, cacache@npm:^15.2.0":
|
||||
"cacache@npm:^15.0.5":
|
||||
version: 15.3.0
|
||||
resolution: "cacache@npm:15.3.0"
|
||||
dependencies:
|
||||
@@ -17978,7 +17947,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"depd@npm:2.0.0, depd@npm:^2.0.0, depd@npm:~2.0.0":
|
||||
"depd@npm:2.0.0, depd@npm:~2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "depd@npm:2.0.0"
|
||||
checksum: 58bd06ec20e19529b06f7ad07ddab60e504d9e0faca4bd23079fac2d279c3594334d736508dc350e06e510aba5e22e4594483b3a6562ce7c17dd797f4cc4ad2c
|
||||
@@ -18666,7 +18635,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"encoding@npm:^0.1.11, encoding@npm:^0.1.12, encoding@npm:^0.1.13":
|
||||
"encoding@npm:^0.1.11, encoding@npm:^0.1.13":
|
||||
version: 0.1.13
|
||||
resolution: "encoding@npm:0.1.13"
|
||||
dependencies:
|
||||
@@ -28797,30 +28766,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"make-fetch-happen@npm:^9.1.0":
|
||||
version: 9.1.0
|
||||
resolution: "make-fetch-happen@npm:9.1.0"
|
||||
dependencies:
|
||||
agentkeepalive: ^4.1.3
|
||||
cacache: ^15.2.0
|
||||
http-cache-semantics: ^4.1.0
|
||||
http-proxy-agent: ^4.0.1
|
||||
https-proxy-agent: ^5.0.0
|
||||
is-lambda: ^1.0.1
|
||||
lru-cache: ^6.0.0
|
||||
minipass: ^3.1.3
|
||||
minipass-collect: ^1.0.2
|
||||
minipass-fetch: ^1.3.2
|
||||
minipass-flush: ^1.0.5
|
||||
minipass-pipeline: ^1.2.4
|
||||
negotiator: ^0.6.2
|
||||
promise-retry: ^2.0.1
|
||||
socks-proxy-agent: ^6.0.0
|
||||
ssri: ^8.0.0
|
||||
checksum: 2c737faf6a7f67077679da548b5bfeeef890595bf8c4323a1f76eae355d27ebb33dcf9cf1a673f944cf2f2a7cbf4e2b09f0a0a62931737728f210d902c6be966
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"makeerror@npm:1.0.12":
|
||||
version: 1.0.12
|
||||
resolution: "makeerror@npm:1.0.12"
|
||||
@@ -30300,21 +30245,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"minipass-fetch@npm:^1.3.2":
|
||||
version: 1.4.1
|
||||
resolution: "minipass-fetch@npm:1.4.1"
|
||||
dependencies:
|
||||
encoding: ^0.1.12
|
||||
minipass: ^3.1.0
|
||||
minipass-sized: ^1.0.3
|
||||
minizlib: ^2.0.0
|
||||
dependenciesMeta:
|
||||
encoding:
|
||||
optional: true
|
||||
checksum: a43da7401cd7c4f24b993887d41bd37d097356083b0bb836fd655916467463a1e6e9e553b2da4fcbe8745bf23d40c8b884eab20745562199663b3e9060cd8e7a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"minipass-fetch@npm:^2.0.3":
|
||||
version: 2.1.0
|
||||
resolution: "minipass-fetch@npm:2.1.0"
|
||||
@@ -30376,15 +30306,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"minipass@npm:^3.1.0, minipass@npm:^3.1.3":
|
||||
version: 3.3.6
|
||||
resolution: "minipass@npm:3.3.6"
|
||||
dependencies:
|
||||
yallist: ^4.0.0
|
||||
checksum: a114746943afa1dbbca8249e706d1d38b85ed1298b530f5808ce51f8e9e941962e2a5ad2e00eae7dd21d8a4aae6586a66d4216d1a259385e9d0358f0c1eba16c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"minizlib@npm:^1.3.3":
|
||||
version: 1.3.3
|
||||
resolution: "minizlib@npm:1.3.3"
|
||||
@@ -30394,7 +30315,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"minizlib@npm:^2.0.0, minizlib@npm:^2.1.1, minizlib@npm:^2.1.2":
|
||||
"minizlib@npm:^2.1.1, minizlib@npm:^2.1.2":
|
||||
version: 2.1.2
|
||||
resolution: "minizlib@npm:2.1.2"
|
||||
dependencies:
|
||||
@@ -30901,7 +30822,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"negotiator@npm:0.6.3, negotiator@npm:^0.6.2, negotiator@npm:^0.6.3, negotiator@npm:~0.6.2":
|
||||
"negotiator@npm:0.6.3, negotiator@npm:^0.6.3, negotiator@npm:~0.6.2":
|
||||
version: 0.6.3
|
||||
resolution: "negotiator@npm:0.6.3"
|
||||
checksum: 3ec9fd413e7bf071c937ae60d572bc67155262068ed522cf4b3be5edbe6ddf67d095ec03a3a14ebf8fc8e95f8e1d61be4869db0dbb0de696f6b837358bd43fc2
|
||||
@@ -30973,7 +30894,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-addon-api@npm:^4.2.0, node-addon-api@npm:^4.3.0":
|
||||
"node-addon-api@npm:^4.3.0":
|
||||
version: 4.3.0
|
||||
resolution: "node-addon-api@npm:4.3.0"
|
||||
dependencies:
|
||||
@@ -31126,26 +31047,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-gyp@npm:8.x":
|
||||
version: 8.4.1
|
||||
resolution: "node-gyp@npm:8.4.1"
|
||||
dependencies:
|
||||
env-paths: ^2.2.0
|
||||
glob: ^7.1.4
|
||||
graceful-fs: ^4.2.6
|
||||
make-fetch-happen: ^9.1.0
|
||||
nopt: ^5.0.0
|
||||
npmlog: ^6.0.0
|
||||
rimraf: ^3.0.2
|
||||
semver: ^7.3.5
|
||||
tar: ^6.1.2
|
||||
which: ^2.0.2
|
||||
bin:
|
||||
node-gyp: bin/node-gyp.js
|
||||
checksum: 80ef333b3a882eb6a2695a8e08f31d618f4533eff192864e4a3a16b67ff0abc9d8c1d5fac0395550ec699326b9248c5e2b3be178492f7f4d1ccf97d2cf948021
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-gyp@npm:latest":
|
||||
version: 9.0.0
|
||||
resolution: "node-gyp@npm:9.0.0"
|
||||
@@ -37206,17 +37107,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"socks-proxy-agent@npm:^6.0.0":
|
||||
version: 6.2.1
|
||||
resolution: "socks-proxy-agent@npm:6.2.1"
|
||||
dependencies:
|
||||
agent-base: ^6.0.2
|
||||
debug: ^4.3.3
|
||||
socks: ^2.6.2
|
||||
checksum: d75c1cf1fdd7f8309a43a77f84409b793fc0f540742ef915154e70ac09a08b0490576fe85d4f8d68bbf80e604a62957a17ab5ef50d312fe1442b0ab6f8f6e6f6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"socks-proxy-agent@npm:^7.0.0":
|
||||
version: 7.0.0
|
||||
resolution: "socks-proxy-agent@npm:7.0.0"
|
||||
@@ -37456,26 +37346,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"sqlite3@npm:^5.0.2":
|
||||
version: 5.1.6
|
||||
resolution: "sqlite3@npm:5.1.6"
|
||||
dependencies:
|
||||
"@mapbox/node-pre-gyp": ^1.0.0
|
||||
node-addon-api: ^4.2.0
|
||||
node-gyp: 8.x
|
||||
tar: ^6.1.11
|
||||
peerDependencies:
|
||||
node-gyp: 8.x
|
||||
dependenciesMeta:
|
||||
node-gyp:
|
||||
optional: true
|
||||
peerDependenciesMeta:
|
||||
node-gyp:
|
||||
optional: true
|
||||
checksum: 85f1dd1f4b9fa906578330e7badc1116c61ef4e7c64a09897268923f5c9ff4ae1e0a447dd4594c0f8c3b20a410fcc5d8d00d1056225a5186c57ea7f7c9b18974
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"sshpk@npm:^1.7.0":
|
||||
version: 1.17.0
|
||||
resolution: "sshpk@npm:1.17.0"
|
||||
@@ -37506,7 +37376,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ssri@npm:^8.0.0, ssri@npm:^8.0.1":
|
||||
"ssri@npm:^8.0.1":
|
||||
version: 8.0.1
|
||||
resolution: "ssri@npm:8.0.1"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user