Skip to content

Commit

Permalink
Adjust to new prisma migration methodology
Browse files Browse the repository at this point in the history
(Needs DB schema support to reach parity with old.)
  • Loading branch information
chuck-dbos committed Jun 7, 2024
1 parent 68ac74a commit c5ea2e3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/bank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ jobs:
# The default PostgreSQL port
POSTGRES_PORT: 5432
BANK_PORT: 8081
BANK_SCHEMA: banktest
# CB 6/6/2024 - temporary limitation
BANK_SCHEMA: public
2 changes: 2 additions & 0 deletions bank/bank-backend/dbos-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ database:
app_db_name: 'bank'
password: ${PGPASSWORD}
app_db_client: "prisma"
migrate:
- npx prisma migrate deploy
runtimeConfig:
port: 8081
application:
Expand Down
16 changes: 16 additions & 0 deletions bank/bank-backend/generate_env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { parseConfigFile } = require('@dbos-inc/dbos-sdk/dist/src/dbos-runtime/config');
const fs = require('node:fs');
const path = require('node:path');

// Load the configuration file
const [dbosConfig, ] = parseConfigFile();

// Write out the .env file
const databaseURL = `postgresql://${dbosConfig.poolConfig.user}:${dbosConfig.poolConfig.password}@${dbosConfig.poolConfig.host}:${dbosConfig.poolConfig.port}/${dbosConfig.poolConfig.database}?schema=${process.env['BANK_SCHEMA']}`;

try {
fs.writeFileSync(path.join(process.cwd(), 'prisma', '.env'), `DATABASE_URL="${databaseURL}"`);
console.log("Wrote database URL to the prisma/.env file.");
} catch (error) {
console.error("Error writing prisma/.env file:", error.message);
}
4 changes: 2 additions & 2 deletions bank/bank-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "dist/main.js",
"types": "dist/main.d.js",
"scripts": {
"build": "npx prisma generate && tsc",
"build": "node generate_env.js && npx prisma generate && tsc",
"start": "node .",
"test": "jest --detectOpenHandles",
"test": "npm run build && npx dbos migrate && jest --detectOpenHandles",
"lint-fix": "eslint --ext .ts --fix .",
"lint": "eslint --ext .ts ."
},
Expand Down
8 changes: 1 addition & 7 deletions bank/bank-backend/prisma/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL=postgresql://bank:${PGPASSWORD}@localhost:5432/bank?schema=${BANK_SCHEMA}
DATABASE_URL="postgresql://bank:postgres@localhost:5432/bank?schema=testbank"

0 comments on commit c5ea2e3

Please sign in to comment.