Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"db:migrate": "tsx src/migrate.ts"
},
"dependencies": {
"@fastify/cookie": "^9.3.1",
"@fastify/cors": "^9.0.1",
"@fastify/multipart": "^8.2.0",
"@fastify/static": "^7.0.4",
"@fastify/swagger": "^8.15.0",
"@fastify/swagger-ui": "^3.0.0",
"@fastify/cookie": "^11.0.2",
"@fastify/cors": "^11.2.0",
"@fastify/multipart": "^10.0.0",
"@fastify/static": "^9.1.3",
"@fastify/swagger": "^9.7.0",
"@fastify/swagger-ui": "^5.2.6",
"bcryptjs": "^2.4.3",
"bullmq": "^5.7.8",
"dockerode": "^4.0.2",
"fastify": "^4.27.0",
"fastify": "^5.8.5",
"ioredis": "^5.4.1",
"pg": "^8.11.5",
"tar": "^7.2.0",
Expand Down
10 changes: 10 additions & 0 deletions apps/api/src/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { createDb } from './db.js';
import { bootstrapFirstAdmin } from './bootstrap.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));
const MIGRATION_LOCK_NAMESPACE = 92821920;
const MIGRATION_LOCK_ID = 1;

export async function runMigrations(): Promise<void> {
const config = loadConfig();
const db = createDb(config);
const lockClient = await db.pool.connect();
let migrationLockAcquired = false;
try {
await lockClient.query('SELECT pg_advisory_lock($1, $2)', [MIGRATION_LOCK_NAMESPACE, MIGRATION_LOCK_ID]);
migrationLockAcquired = true;
await db.query(`
CREATE TABLE IF NOT EXISTS schema_migrations (
name text PRIMARY KEY,
Expand Down Expand Up @@ -47,6 +53,10 @@ export async function runMigrations(): Promise<void> {

await bootstrapFirstAdmin(db, config);
} finally {
if (migrationLockAcquired) {
await lockClient.query('SELECT pg_advisory_unlock($1, $2)', [MIGRATION_LOCK_NAMESPACE, MIGRATION_LOCK_ID]);
}
lockClient.release();
await db.close();
}
}
Expand Down
Loading
Loading