chore(db): move drizzle scripts and update commands
Relocate migration scripts to `drizzle/scripts`, update `start` and `migrate` to use the new path, and add a `generate` script for contributors. Update README migration guidance for SQLite vs Postgres workflows. BREAKING CHANGE: remove `migrate:force` and change migration script paths; consumers relying on `scripts/migrate*.mjs` or `pnpm migrate:force` must update to the new commands.
This commit is contained in:
parent
297752e83e
commit
6089d2c445
5 changed files with 66 additions and 45 deletions
23
README.md
23
README.md
|
|
@ -85,7 +85,7 @@ OpenReader WebUI is an open source text to speech document reader web app built
|
||||||
| `API_KEY` | Default TTS API key | `none` or your provider key |
|
| `API_KEY` | Default TTS API key | `none` or your provider key |
|
||||||
| `BETTER_AUTH_URL` | Enables auth when set with `BETTER_AUTH_SECRET` | External URL for this app, e.g. `http://localhost:3003` or `https://reader.example.com` |
|
| `BETTER_AUTH_URL` | Enables auth when set with `BETTER_AUTH_SECRET` | External URL for this app, e.g. `http://localhost:3003` or `https://reader.example.com` |
|
||||||
| `BETTER_AUTH_SECRET` | Enables auth when set with `BETTER_AUTH_URL` | Generate with `openssl rand -base64 32` |
|
| `BETTER_AUTH_SECRET` | Enables auth when set with `BETTER_AUTH_URL` | Generate with `openssl rand -base64 32` |
|
||||||
| `POSTGRES_URL` | Use Postgres for auth storage instead of SQLite | If set, run migrations manually (see note above) |
|
| `POSTGRES_URL` | Use Postgres for auth storage instead of SQLite | If set, startup migrations target Postgres |
|
||||||
| `GITHUB_CLIENT_ID` | Optional GitHub OAuth sign-in | Requires `GITHUB_CLIENT_SECRET` |
|
| `GITHUB_CLIENT_ID` | Optional GitHub OAuth sign-in | Requires `GITHUB_CLIENT_SECRET` |
|
||||||
| `GITHUB_CLIENT_SECRET` | Optional GitHub OAuth sign-in | Requires `GITHUB_CLIENT_ID` |
|
| `GITHUB_CLIENT_SECRET` | Optional GitHub OAuth sign-in | Requires `GITHUB_CLIENT_ID` |
|
||||||
|
|
||||||
|
|
@ -263,15 +263,20 @@ Optionally required for different features:
|
||||||
- **Production / Docker**: Migrations run automatically on startup via `pnpm start`.
|
- **Production / Docker**: Migrations run automatically on startup via `pnpm start`.
|
||||||
- **Development**: Run explicitly:
|
- **Development**: Run explicitly:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm migrate
|
pnpm migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: If you set `POSTGRES_URL` in `.env`, migrations will target Postgres instead of local SQLite.
|
> Note: If you set `POSTGRES_URL` in `.env`, migrations will target Postgres instead of local SQLite.
|
||||||
>
|
>
|
||||||
> Manual Drizzle Kit runs:
|
> Generating migrations (contributors):
|
||||||
> - SQLite: `npx drizzle-kit migrate --config drizzle.config.sqlite.ts`
|
> - `pnpm generate` generates migrations for **both** SQLite and Postgres (requires `POSTGRES_URL`).
|
||||||
> - Postgres: `npx drizzle-kit migrate --config drizzle.config.pg.ts`
|
>
|
||||||
|
> Manual Drizzle Kit runs:
|
||||||
|
> - SQLite migrate: `npx drizzle-kit migrate --config drizzle.config.sqlite.ts`
|
||||||
|
> - Postgres migrate: `npx drizzle-kit migrate --config drizzle.config.pg.ts`
|
||||||
|
> - SQLite generate: `npx drizzle-kit generate --config drizzle.config.sqlite.ts`
|
||||||
|
> - Postgres generate: `npx drizzle-kit generate --config drizzle.config.pg.ts`
|
||||||
|
|
||||||
5. Start the development server:
|
5. Start the development server:
|
||||||
|
|
||||||
|
|
|
||||||
49
drizzle/scripts/generate.mjs
Normal file
49
drizzle/scripts/generate.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
|
import path from 'node:path';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
|
||||||
|
function loadEnvFiles() {
|
||||||
|
// Approximate Next.js behavior enough for server-side scripts.
|
||||||
|
// Load .env first, then .env.local (local overrides).
|
||||||
|
const cwd = process.cwd();
|
||||||
|
const envPath = path.join(cwd, '.env');
|
||||||
|
const envLocalPath = path.join(cwd, '.env.local');
|
||||||
|
|
||||||
|
if (fs.existsSync(envPath)) {
|
||||||
|
dotenv.config({ path: envPath });
|
||||||
|
}
|
||||||
|
if (fs.existsSync(envLocalPath)) {
|
||||||
|
dotenv.config({ path: envLocalPath, override: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadEnvFiles();
|
||||||
|
|
||||||
|
const authEnabled = Boolean(process.env.BETTER_AUTH_SECRET && process.env.BETTER_AUTH_URL);
|
||||||
|
|
||||||
|
if (!authEnabled) {
|
||||||
|
// When auth is disabled, the app must not touch sqlite/postgres at all.
|
||||||
|
console.log('[generate] Skipping (auth disabled). Missing BETTER_AUTH_SECRET and/or BETTER_AUTH_URL.');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!process.env.POSTGRES_URL) {
|
||||||
|
console.error('[generate] POSTGRES_URL is required to generate postgres migrations.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const extraArgs = process.argv.slice(2);
|
||||||
|
|
||||||
|
for (const configFile of ['drizzle.config.sqlite.ts', 'drizzle.config.pg.ts']) {
|
||||||
|
const result = spawnSync('drizzle-kit', ['generate', '--config', configFile, ...extraArgs], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
env: process.env,
|
||||||
|
});
|
||||||
|
|
||||||
|
if ((result.status ?? 1) !== 0) {
|
||||||
|
process.exit(result.status ?? 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack -p 3003",
|
"dev": "next dev --turbopack -p 3003",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "node scripts/migrate-if-auth.mjs && next start -p 3003",
|
"start": "node drizzle/scripts/migrate-if-auth.mjs && next start -p 3003",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"test": "playwright test",
|
"test": "playwright test",
|
||||||
"migrate": "node scripts/migrate-if-auth.mjs",
|
"migrate": "node drizzle/scripts/migrate-if-auth.mjs",
|
||||||
"migrate:force": "node scripts/migrate.mjs"
|
"generate": "node drizzle/scripts/generate.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@headlessui/react": "^2.2.9",
|
"@headlessui/react": "^2.2.9",
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
import { spawnSync } from 'node:child_process';
|
|
||||||
import path from 'node:path';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
|
|
||||||
function loadEnvFiles() {
|
|
||||||
// Approximate Next.js behavior enough for server-side scripts.
|
|
||||||
// Load .env first, then .env.local (local overrides).
|
|
||||||
const cwd = process.cwd();
|
|
||||||
const envPath = path.join(cwd, '.env');
|
|
||||||
const envLocalPath = path.join(cwd, '.env.local');
|
|
||||||
|
|
||||||
if (fs.existsSync(envPath)) {
|
|
||||||
dotenv.config({ path: envPath });
|
|
||||||
}
|
|
||||||
if (fs.existsSync(envLocalPath)) {
|
|
||||||
dotenv.config({ path: envLocalPath, override: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadEnvFiles();
|
|
||||||
|
|
||||||
const extraArgs = process.argv.slice(2);
|
|
||||||
const hasConfigArg = extraArgs.includes('--config');
|
|
||||||
const configFile = process.env.POSTGRES_URL ? 'drizzle.config.pg.ts' : 'drizzle.config.sqlite.ts';
|
|
||||||
const configArgs = hasConfigArg ? [] : ['--config', configFile];
|
|
||||||
|
|
||||||
const result = spawnSync('drizzle-kit', ['migrate', ...configArgs, ...extraArgs], {
|
|
||||||
stdio: 'inherit',
|
|
||||||
env: process.env,
|
|
||||||
});
|
|
||||||
|
|
||||||
process.exit(result.status ?? 1);
|
|
||||||
Loading…
Reference in a new issue