openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
12 lines • 2.21 kB
JavaScript
import{c as e,n as t,r as n}from"./transcript-sqlite-schema-sql-BnVx4b5A.mjs";import{h as r,o as i}from"./transcript-sqlite-schema-facts-C1_zV4Yg.mjs";import{r as a}from"./transcript-openclaw-state-db-schema-helpers-B1k_oHgC.mjs";const o=/CREATE (?:UNIQUE )?INDEX ("(?:[^"]|"")+") ON ("(?:[^"]|"")+") (?:'(?:[^']|'')*'|"(?:[^"]|"")*"|[^;'"])*;/g,s=/'(?:[^']|'')*'|"(?:[^"]|"")*"|\) (ASC|DESC)(?=,|\))/g;function withLegacyPostgresIndexOrdering(e,t=`sqlite`,n=e){let r=/* @__PURE__ */ new Map;if(t===`schema-nullability`)for(let[,e,t]of n.matchAll(/CREATE TABLE ("(?:[^"]|"")+") \(\n([\s\S]*?)\n\);/g))r.set(e,new Set([...t.matchAll(/^ {2}("(?:[^"]|"")+") (?:text|bigint|bytea|double precision)([^\n]*)/gm)].filter(e=>!/\bNOT NULL\b/.test(e[2].replace(`GENERATED BY DEFAULT AS IDENTITY`,``).split(/\bDEFAULT\b/)[0])).map(([,e])=>e)));return e.replace(o,(e,n,i)=>t===`schema-nullability`?e.replace(/'(?:[^']|'')*'|"(?:[^"]|"")*"|\(("(?:[^"]|"")+")\) (ASC|DESC)(?=,|\))/g,(e,t,n)=>t&&r.get(i)?.has(t)?`${e} NULLS ${n===`DESC`?`LAST`:`FIRST`}`:e):e.replace(s,(e,t)=>t?`${e} NULLS ${t===`DESC`?`LAST`:`FIRST`}`:e))}function postgresIndexOrderingMigration(e,t=`sqlite`){let n=withLegacyPostgresIndexOrdering(e,t),r=new Map([...n.matchAll(o)].map(([e,t])=>[t,e]));return[...e.matchAll(o)].filter(([e,t])=>r.get(t)!==e).map(([e,t,n])=>`DO $index_order$
BEGIN
IF to_regclass('${n.replaceAll(`'`,`''`)}') IS NOT NULL THEN
DROP INDEX ${t};
${e}
END IF;
END $index_order$;`).join(`
`)}function migrateSqliteTableWithoutRowid(o,s){let c=i(o)??r(o),l=c.tableSql.get(s);if(!l)return!1;let u=t(l,`(`),d=n(l,u),f=l.slice(d+1).replace(/;\s*$/u,``).trim();if(/\bWITHOUT\s+ROWID\b/iu.test(f))return!1;let p=e(s),m=e(`${s}_without_rowid_migration`),h=[...a(o,s)].map(e).join(`, `);o.exec(`CREATE TABLE ${m} ${l.slice(u,d+1)}
${f?`${f}, `:``}WITHOUT ROWID;
INSERT INTO ${m} (${h}) SELECT ${h} FROM ${p};
DROP TABLE ${p};
ALTER TABLE ${m} RENAME TO ${p};`);for(let e of[...c.indexDefinitions.values(),...c.triggers.values()])e.table===s&&typeof e.sql==`string`&&o.exec(e.sql);return!0}export{postgresIndexOrderingMigration as n,withLegacyPostgresIndexOrdering as r,migrateSqliteTableWithoutRowid as t};