"use strict";exports.id=5258,exports.ids=[5258],exports.modules={32372:(a,b,c)=>{c.d(b,{I:()=>f});var d=c(77598),e=c(73024);function f(a){let b=a.migrationsFolder,c=[],f=`${b}/meta/_journal.json`;if(!e.existsSync(f))throw Error("Can't find meta/_journal.json file");for(let a of JSON.parse(e.readFileSync(`${b}/meta/_journal.json`).toString()).entries){let f=`${b}/${a.tag}.sql`;try{let f=e.readFileSync(`${b}/${a.tag}.sql`).toString(),g=f.split("--\x3e statement-breakpoint").map(a=>a);c.push({sql:g,bps:a.breakpoints,folderMillis:a.when,hash:d.createHash("sha256").update(f).digest("hex")})}catch{throw Error(`No file ${f} found in ${b} folder`)}}return c}},35258:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{provisionDb:()=>p});var e=c(28855),f=c(55871),g=c(96942),h=c(32372),i=c(76760),j=c(73136),k=a([e,f]);[e,f]=k.then?(await k)():k;let q=(0,i.dirname)((0,i.dirname)((0,i.dirname)((0,j.fileURLToPath)("file:///home/runner/work/beacon/beacon/lib/drizzle/provision.ts")))),r=process.env.BEACON_MIGRATIONS_DIR||(0,i.join)(q,"drizzle"),s={Node:["createdAt","updatedAt"],Note:["createdAt","updatedAt"],DbTable:["createdAt","updatedAt"],Endpoint:["createdAt","updatedAt"],DraftTable:["createdAt"],SyncState:["codeGraphSyncedAt","updatedAt"],AppSetting:["updatedAt"],ProjectMeta:["updatedAt"],CodeFile:["updatedAt"]};async function l(a,b){return(await a.execute({sql:"SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?",args:[b]})).rows.length>0}async function m(a,b){let c=await a.execute(`PRAGMA table_info("${b}")`);return new Set(c.rows.map(a=>String(a.name)))}async function n(a){if(!await l(a,"__drizzle_migrations"))return 0;let b=await a.execute('SELECT count(*) AS n FROM "__drizzle_migrations"');return Number(b.rows[0]?.n??0)}async function o(a){for(let[b,c]of Object.entries(s)){if(!await l(a,b))continue;let d=await m(a,b);for(let e of c)d.has(e)&&await a.execute(`UPDATE "${b}" SET "${e}" = CAST((julianday("${e}") - 2440587.5) * 86400000 AS INTEGER) WHERE typeof("${e}") = 'text'`)}}async function p(a,b=r){let c=(0,e.createClient)({url:a});try{await c.execute("PRAGMA journal_mode = WAL;"),await c.execute("PRAGMA foreign_keys = ON;");let a=await l(c,"__drizzle_migrations"),d=await l(c,"Node"),e=!1;if(d&&!a){let a=(0,h.I)({migrationsFolder:b})[0];a&&(await c.execute('CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric)'),await c.execute({sql:'INSERT INTO "__drizzle_migrations" ("hash", "created_at") VALUES (?, ?)',args:[a.hash,a.folderMillis]}),e=!0)}let i=await n(c);return await (0,g._)((0,f.f)(c),{migrationsFolder:b}),await n(c)>i&&(e=!0),await o(c),{migrated:e}}finally{c.close()}}d()}catch(a){d(a)}})},96942:(a,b,c)=>{c.d(b,{_:()=>f});var d=c(32372),e=c(91430);async function f(a,b){let c=(0,d.I)(b),f=b.migrationsTable??"__drizzle_migrations",g=(0,e.ll)`
		CREATE TABLE IF NOT EXISTS ${e.ll.identifier(f)} (
			id SERIAL PRIMARY KEY,
			hash text NOT NULL,
			created_at numeric
		)
	`;await a.session.run(g);let h=(await a.values((0,e.ll)`SELECT id, hash, created_at FROM ${e.ll.identifier(f)} ORDER BY created_at DESC LIMIT 1`))[0]??void 0,i=[];for(let b of c)if(!h||Number(h[2])<b.folderMillis){for(let c of b.sql)i.push(a.run(e.ll.raw(c)));i.push(a.run((0,e.ll)`INSERT INTO ${e.ll.identifier(f)} ("hash", "created_at") VALUES(${b.hash}, ${b.folderMillis})`))}await a.session.migrate(i)}}};