Files
probably-rendering-one-more…/apps/wiki/scripts/bootstrap.ts
T
codex-bot a2330b22e2
python CI and deployment / verify-and-deploy (push) Successful in 7m23s
studio CI and deployment / verify-and-deploy (push) Failing after 5m28s
wiki CI and deployment / verify-and-deploy (push) Failing after 6m13s
Restructure into Wiki, Studio and Python monorepo with scoped CI
2026-10-25 21:13:43 +08:00

21 lines
1.3 KiB
TypeScript

import { readdir,readFile } from "node:fs/promises";
import { db } from "../src/lib/db";
import { ensureBucket } from "../src/lib/storage";
import { setTimeout } from "node:timers/promises";
async function main(){
for(let i=0;;i++){try{await db().query('SELECT 1');break;}catch(e){if(i>=60)throw e;await setTimeout(2000);}}
const client=await db().connect();
try{
await client.query('SELECT pg_advisory_lock(18131001)');
for(const name of (await readdir('db')).filter(n=>n.endsWith('.sql')).sort()){
const present=await client.query("SELECT to_regclass('public.schema_migrations') AS table");
if(present.rows[0].table && (await client.query('SELECT 1 FROM schema_migrations WHERE version=$1',[name.replace('.sql','')])).rowCount)continue;
await client.query(await readFile('db/'+name,'utf8'));console.log('Applied migration '+name);
}
}catch(error){await client.query('ROLLBACK');throw error;}
finally{await client.query('SELECT pg_advisory_unlock(18131001)');client.release();}
for(let i=0;;i++){try{await ensureBucket();break;}catch(e){if(i>=90)throw e;await setTimeout(2000);}}
console.log('PostgreSQL and S3 are ready');await db().end();
}
main().catch(error=>{console.error('Storage bootstrap failed:',error instanceof Error?error.message:'Unknown error');process.exit(1);});