breaking: remove POSTGRES prefix env variables in favor of DATABASE prefix (#8672)
This commit is contained in:
1
.github/workflows/test-cli-with-database.yml
vendored
1
.github/workflows/test-cli-with-database.yml
vendored
@@ -8,7 +8,6 @@ jobs:
|
||||
NODE_ENV: CI
|
||||
REDIS_URL: redis://localhost:6379
|
||||
DATABASE_URL: "postgres://postgres:postgres@localhost/cli-test"
|
||||
POSTGRES_URL: "postgres://postgres:postgres@localhost/cli-test"
|
||||
services:
|
||||
redis:
|
||||
image: redis
|
||||
|
||||
@@ -9,11 +9,11 @@ medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConfig: { clientUrl } }) => {
|
||||
describe("Standalone Modules", () => {
|
||||
beforeAll(async () => {
|
||||
process.env.POSTGRES_URL = clientUrl
|
||||
process.env.DATABASE_URL = clientUrl
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
process.env.POSTGRES_URL = undefined
|
||||
process.env.DATABASE_URL = undefined
|
||||
})
|
||||
|
||||
it("Should migrate database and initialize Product module using connection string from environment variable ", async function () {
|
||||
|
||||
@@ -9,7 +9,8 @@ import type { Client } from "pg"
|
||||
|
||||
const ADMIN_EMAIL = "admin@medusa-test.com"
|
||||
const STORE_CORS = "http://localhost:8000,https://docs.medusajs.com"
|
||||
const ADMIN_CORS = "http://localhost:7000,http://localhost:7001,https://docs.medusajs.com"
|
||||
const ADMIN_CORS =
|
||||
"http://localhost:7000,http://localhost:7001,https://docs.medusajs.com"
|
||||
const AUTH_CORS = ADMIN_CORS
|
||||
const DEFAULT_REDIS_URL = "redis://localhost:6379"
|
||||
|
||||
@@ -72,13 +73,13 @@ export default async ({
|
||||
let env = `MEDUSA_ADMIN_ONBOARDING_TYPE=${onboardingType}${EOL}STORE_CORS=${STORE_CORS}${EOL}ADMIN_CORS=${ADMIN_CORS}${EOL}AUTH_CORS=${AUTH_CORS}${EOL}REDIS_URL=${DEFAULT_REDIS_URL}${EOL}JWT_SECRET=supersecret${EOL}COOKIE_SECRET=supersecret`
|
||||
|
||||
if (!skipDb) {
|
||||
env += `${EOL}DATABASE_URL=${dbConnectionString}${EOL}POSTGRES_URL=${dbConnectionString}`
|
||||
env += `${EOL}DATABASE_URL=${dbConnectionString}`
|
||||
}
|
||||
|
||||
if (nextjsDirectory) {
|
||||
env += `${EOL}MEDUSA_ADMIN_ONBOARDING_NEXTJS_DIRECTORY=${nextjsDirectory}`
|
||||
}
|
||||
|
||||
|
||||
fs.appendFileSync(path.join(directory, `.env`), env)
|
||||
|
||||
factBoxOptions.interval = displayFactBox({
|
||||
@@ -183,10 +184,7 @@ export default async ({
|
||||
await processManager.runProcess({
|
||||
process: async () => {
|
||||
const proc = await execute(
|
||||
[
|
||||
`npx medusa user -e ${ADMIN_EMAIL} --invite`,
|
||||
npxOptions,
|
||||
],
|
||||
[`npx medusa user -e ${ADMIN_EMAIL} --invite`, npxOptions],
|
||||
{ verbose, needOutput: true }
|
||||
)
|
||||
|
||||
|
||||
@@ -2,20 +2,20 @@ import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
|
||||
describe("loadDatabaseConfig", function () {
|
||||
afterEach(() => {
|
||||
delete process.env.POSTGRES_URL
|
||||
delete process.env.MEDUSA_POSTGRES_URL
|
||||
delete process.env.PRODUCT_POSTGRES_URL
|
||||
delete process.env.DATABASE_URL
|
||||
delete process.env.MEDUSA_DATABASE_URL
|
||||
delete process.env.PRODUCT_DATABASE_URL
|
||||
})
|
||||
|
||||
it("should return the local configuration using the environment variable respecting their precedence", function () {
|
||||
process.env.MEDUSA_POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
process.env.PRODUCT_POSTGRES_URL = "postgres://localhost:5432/product"
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/share_db"
|
||||
process.env.MEDUSA_DATABASE_URL = "postgres://localhost:5432/medusa"
|
||||
process.env.PRODUCT_DATABASE_URL = "postgres://localhost:5432/product"
|
||||
process.env.DATABASE_URL = "postgres://localhost:5432/share_db"
|
||||
|
||||
let config = loadDatabaseConfig("product")
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: process.env.PRODUCT_POSTGRES_URL,
|
||||
clientUrl: process.env.PRODUCT_DATABASE_URL,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
@@ -25,11 +25,11 @@ describe("loadDatabaseConfig", function () {
|
||||
schema: "",
|
||||
})
|
||||
|
||||
delete process.env.PRODUCT_POSTGRES_URL
|
||||
delete process.env.PRODUCT_DATABASE_URL
|
||||
config = loadDatabaseConfig("product")
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: process.env.MEDUSA_POSTGRES_URL,
|
||||
clientUrl: process.env.MEDUSA_DATABASE_URL,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
@@ -39,11 +39,11 @@ describe("loadDatabaseConfig", function () {
|
||||
schema: "",
|
||||
})
|
||||
|
||||
delete process.env.MEDUSA_POSTGRES_URL
|
||||
delete process.env.MEDUSA_DATABASE_URL
|
||||
config = loadDatabaseConfig("product")
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: process.env.POSTGRES_URL,
|
||||
clientUrl: process.env.DATABASE_URL,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: false,
|
||||
@@ -55,11 +55,11 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
|
||||
it("should return the remote configuration using the environment variable", function () {
|
||||
process.env.POSTGRES_URL = "postgres://https://test.com:5432/medusa"
|
||||
process.env.DATABASE_URL = "postgres://https://test.com:5432/medusa"
|
||||
let config = loadDatabaseConfig("product")
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: process.env.POSTGRES_URL,
|
||||
clientUrl: process.env.DATABASE_URL,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: {
|
||||
@@ -71,12 +71,12 @@ describe("loadDatabaseConfig", function () {
|
||||
schema: "",
|
||||
})
|
||||
|
||||
delete process.env.POSTGRES_URL
|
||||
process.env.PRODUCT_POSTGRES_URL = "postgres://https://test.com:5432/medusa"
|
||||
delete process.env.DATABASE_URL
|
||||
process.env.PRODUCT_DATABASE_URL = "postgres://https://test.com:5432/medusa"
|
||||
config = loadDatabaseConfig("product")
|
||||
|
||||
expect(config).toEqual({
|
||||
clientUrl: process.env.PRODUCT_POSTGRES_URL,
|
||||
clientUrl: process.env.PRODUCT_DATABASE_URL,
|
||||
driverOptions: {
|
||||
connection: {
|
||||
ssl: {
|
||||
@@ -90,7 +90,7 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
|
||||
it("should return the local configuration using the options", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
process.env.DATABASE_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl: "postgres://localhost:5432/medusa-test",
|
||||
@@ -112,7 +112,7 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
|
||||
it("should return the local configuration using the options", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
process.env.DATABASE_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl: "postgres://127.0.0.1:5432/medusa-test",
|
||||
@@ -134,7 +134,7 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
|
||||
it("should return the remote configuration using the options", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
process.env.DATABASE_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl: "postgres://https://test.com:5432/medusa-test",
|
||||
@@ -158,7 +158,7 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
|
||||
it("should return the local configuration using the client url ssl_mode=disable", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
process.env.DATABASE_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl:
|
||||
@@ -181,7 +181,7 @@ describe("loadDatabaseConfig", function () {
|
||||
})
|
||||
|
||||
it("should return the remote configuration using the client url ssl_mode=false", function () {
|
||||
process.env.POSTGRES_URL = "postgres://localhost:5432/medusa"
|
||||
process.env.DATABASE_URL = "postgres://localhost:5432/medusa"
|
||||
const options = {
|
||||
database: {
|
||||
clientUrl:
|
||||
@@ -212,7 +212,7 @@ describe("loadDatabaseConfig", function () {
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"No database clientUrl provided. Please provide the clientUrl through the [MODULE]_POSTGRES_URL, MEDUSA_POSTGRES_URL or POSTGRES_URL environment variable or the options object in the initialize function."
|
||||
"No database clientUrl provided. Please provide the clientUrl through the [MODULE]_DATABASE_URL, MEDUSA_DATABASE_URL or DATABASE_URL environment variable or the options object in the initialize function."
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -57,7 +57,7 @@ function getDatabaseUrl(
|
||||
|
||||
/**
|
||||
* Load the config for the database connection. The options can be retrieved
|
||||
* e.g through PRODUCT_* (e.g PRODUCT_POSTGRES_URL) or * (e.g POSTGRES_URL) environment variables or the options object.
|
||||
* e.g through PRODUCT_* (e.g PRODUCT_DATABASE_URL) or * (e.g DATABASE_URL) environment variables or the options object.
|
||||
* @param options
|
||||
* @param moduleName
|
||||
*/
|
||||
@@ -70,13 +70,13 @@ export function loadDatabaseConfig(
|
||||
"clientUrl" | "schema" | "driverOptions" | "debug"
|
||||
> {
|
||||
const clientUrl =
|
||||
options?.database?.clientUrl ?? getEnv("POSTGRES_URL", moduleName)
|
||||
options?.database?.clientUrl ?? getEnv("DATABASE_URL", moduleName)
|
||||
|
||||
const database = {
|
||||
clientUrl,
|
||||
schema: getEnv("POSTGRES_SCHEMA", moduleName) ?? "public",
|
||||
schema: getEnv("DATABASE_SCHEMA", moduleName) ?? "public",
|
||||
driverOptions: JSON.parse(
|
||||
getEnv("POSTGRES_DRIVER_OPTIONS", moduleName) ||
|
||||
getEnv("DATABASE_DRIVER_OPTIONS", moduleName) ||
|
||||
JSON.stringify(getDefaultDriverOptions(clientUrl))
|
||||
),
|
||||
debug: false,
|
||||
@@ -98,7 +98,7 @@ export function loadDatabaseConfig(
|
||||
if (!database.clientUrl && !silent && !database.connection) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_ARGUMENT,
|
||||
"No database clientUrl provided. Please provide the clientUrl through the [MODULE]_POSTGRES_URL, MEDUSA_POSTGRES_URL or POSTGRES_URL environment variable or the options object in the initialize function."
|
||||
"No database clientUrl provided. Please provide the clientUrl through the [MODULE]_DATABASE_URL, MEDUSA_DATABASE_URL or DATABASE_URL environment variable or the options object in the initialize function."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ npm install @medusajs/product
|
||||
2\. Add Database URL to your environment variables
|
||||
|
||||
```bash
|
||||
POSTGRES_URL=<DATABASE_URL>
|
||||
DATABASE_URL=<URL_GOES_HERE>
|
||||
```
|
||||
|
||||
3\. Apply database migrations
|
||||
|
||||
@@ -53,7 +53,6 @@ module.exports = defineConfig({
|
||||
workerMode: process.env.MEDUSA_WORKER_MODE,
|
||||
},
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Later, you’ll set different values of the `MEDUSA_WORKER_MODE` environment variable for each Medusa application deployment.
|
||||
@@ -80,7 +79,6 @@ module.exports = defineConfig({
|
||||
disable: process.env.DISABLE_MEDUSA_ADMIN === "true",
|
||||
},
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Later, you’ll set different values of the `DISABLE_MEDUSA_ADMIN` environment variable.
|
||||
@@ -96,7 +94,6 @@ module.exports = defineConfig({
|
||||
redisUrl: process.env.REDIS_URL,
|
||||
},
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
@@ -150,13 +147,13 @@ module.exports = defineConfig({
|
||||
// ...
|
||||
[Modules.CACHE]: {
|
||||
resolve: "@medusajs/cache-redis",
|
||||
options: {
|
||||
options: {
|
||||
redisUrl: process.env.REDIS_URL,
|
||||
},
|
||||
},
|
||||
[Modules.EVENT_BUS]: {
|
||||
resolve: "@medusajs/event-bus-redis",
|
||||
options: {
|
||||
options: {
|
||||
redisUrl: process.env.REDIS_URL,
|
||||
},
|
||||
},
|
||||
@@ -240,7 +237,6 @@ DISABLE_MEDUSA_ADMIN=true
|
||||
MEDUSA_WORKER_MODE=worker
|
||||
PORT=9000
|
||||
DATABASE_URL=${{Postgres.DATABASE_PUBLIC_URL}}
|
||||
POSTGRES_URL=${{Postgres.DATABASE_PUBLIC_URL}}
|
||||
REDIS_URL=${{Redis.REDIS_PUBLIC_URL}}
|
||||
```
|
||||
|
||||
@@ -279,7 +275,7 @@ You can either generate a random domain name or set a custom one. To do that:
|
||||
2. Choose the Settings tab.
|
||||
3. Scroll down to the Networking section.
|
||||
4. Under Public Networking, click on Generate domain to generate a domain name or Custom domain to add your custom domain.
|
||||
1. Choose the `9000` port.
|
||||
1. Choose the `9000` port.
|
||||
5. Save the changes.
|
||||
|
||||
### Additional Configuration if Deploying with Admin
|
||||
@@ -349,7 +345,6 @@ DISABLE_MEDUSA_ADMIN=false
|
||||
MEDUSA_WORKER_MODE=worker
|
||||
PORT=9000
|
||||
DATABASE_URL=${{Postgres.DATABASE_PUBLIC_URL}}
|
||||
POSTGRES_URL=${{Postgres.DATABASE_PUBLIC_URL}}
|
||||
REDIS_URL=${{Redis.REDIS_PUBLIC_URL}}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user