From 700681314dd3018c69adc47846d6d590d565d681 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Tue, 28 Nov 2023 11:14:31 -1000 Subject: [PATCH] Add `prisma` script to remove env files --- README.md | 11 ++++++----- package.json | 13 +++++++------ prisma.ts | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 prisma.ts diff --git a/README.md b/README.md index 79c0cbd5..2cbc5774 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,6 @@ RUN chmod +x /docker-entrypoint-initdb.d/init.sh 5. Run migrations: ```bash -# Replace this with Postgres credentials -# This env file only needs to be there for migrations, it can be deleted after -echo "DATABASE_URL=postgres://xxx:xxx@xxx:xxx/xxx" > .env bun migrate ``` @@ -108,6 +105,10 @@ bun cli You can use the `help` command to see a list of available commands. These include creating users, deleting users and more. +### Using Database Commands + +The `bun prisma` commands allows you to use Prisma commands without needing to add in environment variables for the database config. Just run Prisma commands as you would normally, replacing `bunx prisma` with `bun prisma`. + ## With Docker > **Note**: Docker is currently broken, as Bun with Prisma does not work well with Docker yet for unknown reasons. The following instructions are for when this is fixed. @@ -122,8 +123,8 @@ You can also run Lysand using Docker. To do so, you can: ```bash docker network create lysand-net ``` -4. Fill in the config file and the .env file (see [Installation](#installation)) -5. Run the following command: +1. Fill in the config file (see [Installation](#installation)) +2. Run the following command: ```bash docker-compose up -d ``` diff --git a/package.json b/package.json index e521f599..9a83932f 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "url": "https://cpluspatch.com" }, "bugs": { - "url": "https://github.com/CPlusPatch/lysand/issues" + "url": "https://github.com/lysand-org/lysand/issues" }, - "icon": "https://github.com/CPlusPatch/lysand", + "icon": "https://github.com/lysand-org/lysand", "license": "AGPL-3.0", "keywords": [ "federated", @@ -28,16 +28,17 @@ ], "repository": { "type": "git", - "url": "git+https://github.com/CPlusPatch/lysand.git" + "url": "git+https://github.com/lysand-org/lysand.git" }, "private": true, "scripts": { "dev": "bun run index.ts", "start": "bun run index.ts", - "migrate-dev": "bunx prisma migrate dev", - "migrate": "bunx prisma migrate deploy", + "migrate-dev": "bun prisma migrate dev", + "migrate": "bun prisma migrate deploy", "lint": "eslint --config .eslintrc.cjs --ext .ts .", - "generate": "bunx prisma generate", + "prisma": "bun run prisma.ts", + "generate": "bun prisma generate", "cli": "bun run cli.ts" }, "trustedDependencies": [ diff --git a/prisma.ts b/prisma.ts new file mode 100644 index 00000000..39c1743d --- /dev/null +++ b/prisma.ts @@ -0,0 +1,17 @@ +// Proxies all `bunx prisma` commands with an environment variable + +import { getConfig } from "@config"; + +const args = process.argv.slice(2); +const config = getConfig(); + +const { stdout } = Bun.spawn(["bunx", "prisma", ...args], { + env: { + ...process.env, + DATABASE_URL: `postgresql://${config.database.username}:${config.database.password}@${config.database.host}:${config.database.port}/${config.database.database}`, + }, +}); + +// Show stdout +const text = await new Response(stdout).text(); +console.log(text); // => "hello"