Add prisma script to remove env files

This commit is contained in:
Jesse Wierzbinski 2023-11-28 11:14:31 -10:00
parent e3d999d7bd
commit 700681314d
No known key found for this signature in database
3 changed files with 30 additions and 11 deletions

View file

@ -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
```

View file

@ -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": [

17
prisma.ts Normal file
View file

@ -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"