@lunora/cli 1.0.0-alpha.157 → 1.0.0-alpha.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +3 -3
- package/dist/packem_shared/diffSnapshots-cgOtkd-G.mjs +5 -0
- package/dist/packem_shared/{schemaIrToSnapshot-Dahp39qH.mjs → schemaIrToSnapshot-DV2DilTz.mjs} +1 -1
- package/package.json +11 -11
- package/dist/packem_shared/diffSnapshots-BbwCuhoN.mjs +0 -5
package/dist/index.d.mts
CHANGED
|
@@ -1259,7 +1259,15 @@ interface SchemaDiff {
|
|
|
1259
1259
|
* `schema-snapshot.ts` builds the persisted snapshot from it.
|
|
1260
1260
|
*/
|
|
1261
1261
|
declare const validatorKindToSqlType: (kind: string) => ColumnSnapshot["sqlType"];
|
|
1262
|
-
/**
|
|
1262
|
+
/**
|
|
1263
|
+
* Emit `CREATE TABLE` SQL for a new global table.
|
|
1264
|
+
*
|
|
1265
|
+
* Refuses a table past D1's column ceiling rather than writing SQL that
|
|
1266
|
+
* `lunora migrate up` will reject: the runtime auto-provisioner checks the same
|
|
1267
|
+
* number, and a migration file is the worse place to find out — the failure
|
|
1268
|
+
* lands later, against a database, with none of the schema context that names
|
|
1269
|
+
* which table and field to split.
|
|
1270
|
+
*/
|
|
1263
1271
|
declare const renderCreateTable: (table: TableSnapshot) => string;
|
|
1264
1272
|
declare const renderDropTable: (tableName: string) => string;
|
|
1265
1273
|
declare const renderAddColumn: (tableName: string, columnName: string, column: ColumnSnapshot) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1259,7 +1259,15 @@ interface SchemaDiff {
|
|
|
1259
1259
|
* `schema-snapshot.ts` builds the persisted snapshot from it.
|
|
1260
1260
|
*/
|
|
1261
1261
|
declare const validatorKindToSqlType: (kind: string) => ColumnSnapshot["sqlType"];
|
|
1262
|
-
/**
|
|
1262
|
+
/**
|
|
1263
|
+
* Emit `CREATE TABLE` SQL for a new global table.
|
|
1264
|
+
*
|
|
1265
|
+
* Refuses a table past D1's column ceiling rather than writing SQL that
|
|
1266
|
+
* `lunora migrate up` will reject: the runtime auto-provisioner checks the same
|
|
1267
|
+
* number, and a migration file is the worse place to find out — the failure
|
|
1268
|
+
* lands later, against a database, with none of the schema context that names
|
|
1269
|
+
* which table and field to split.
|
|
1270
|
+
*/
|
|
1263
1271
|
declare const renderCreateTable: (table: TableSnapshot) => string;
|
|
1264
1272
|
declare const renderDropTable: (tableName: string) => string;
|
|
1265
1273
|
declare const renderAddColumn: (tableName: string, columnName: string, column: ColumnSnapshot) => string;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as o,i as a,f as n}from"./packem_shared/cli-DiEQDidI.mjs";import{runCodegenCommand as t}from"./packem_chunks/runCodegenCommand.mjs";import{runDeployCommand as p}from"./packem_chunks/runDeployCommand.mjs";import{planDevCommand as x,runDevCommand as i}from"./packem_chunks/planDevCommand.mjs";import{runInitCommand as C}from"./packem_chunks/runInitCommand.mjs";import{runMigrateGenerateCommand as u}from"./packem_chunks/runMigrateGenerateCommand.mjs";import{runResetCommand as g}from"./packem_chunks/runResetCommand.mjs";import{runRpcCommand as E}from"./packem_chunks/runRpcCommand.mjs";import{insertSchemaExtension as D}from"./packem_shared/insertSchemaExtension-DZReBZ4_.mjs";import{createLogger as A,pail as c}from"./packem_shared/createLogger-BoSxdb2T.mjs";import{diffSnapshots as v,renderAddColumn as _,renderCreateIndex as h,renderCreateTable as y,renderDropIndex as F,renderDropTable as L,renderMigrationFile as O,validatorKindToSqlType as b}from"./packem_shared/diffSnapshots-
|
|
1
|
+
import{d as o,i as a,f as n}from"./packem_shared/cli-DiEQDidI.mjs";import{runCodegenCommand as t}from"./packem_chunks/runCodegenCommand.mjs";import{runDeployCommand as p}from"./packem_chunks/runDeployCommand.mjs";import{planDevCommand as x,runDevCommand as i}from"./packem_chunks/planDevCommand.mjs";import{runInitCommand as C}from"./packem_chunks/runInitCommand.mjs";import{runMigrateGenerateCommand as u}from"./packem_chunks/runMigrateGenerateCommand.mjs";import{runResetCommand as g}from"./packem_chunks/runResetCommand.mjs";import{runRpcCommand as E}from"./packem_chunks/runRpcCommand.mjs";import{insertSchemaExtension as D}from"./packem_shared/insertSchemaExtension-DZReBZ4_.mjs";import{createLogger as A,pail as c}from"./packem_shared/createLogger-BoSxdb2T.mjs";import{diffSnapshots as v,renderAddColumn as _,renderCreateIndex as h,renderCreateTable as y,renderDropIndex as F,renderDropTable as L,renderMigrationFile as O,validatorKindToSqlType as b}from"./packem_shared/diffSnapshots-cgOtkd-G.mjs";import{default as B}from"./packem_shared/schemaIrToSnapshot-DV2DilTz.mjs";import{createRecordingSpawner as U,defaultSpawner as W}from"./packem_shared/createRecordingSpawner-SKs4R1fc.mjs";import{default as N}from"./packem_shared/parseManifest-x3WsxKHz.mjs";import{R as V,S as j}from"./packem_shared/import-C9in1wC3.mjs";import{REQUIRED_COMPATIBILITY_DATE as H,REQUIRED_FLAG as K,validateWranglerProject as Y,validateWranglerConfig as Z}from"@lunora/config/cloudflare";import{buildRegistryIndex as z}from"./packem_shared/buildRegistryIndex-DwySASBu.mjs";import{I as X,F as $,E as rr}from"./packem_shared/commands-CG9qEtqR.mjs";import{runExportCommand as or}from"./packem_shared/runExportCommand-BpE4AbuX.mjs";export{o as COMMANDS,V as DEFAULT_IMPORT_BATCH_SIZE,H as REQUIRED_COMPATIBILITY_DATE,K as REQUIRED_FLAG,a as VERSION,z as buildRegistryIndex,A as createLogger,U as createRecordingSpawner,W as defaultSpawner,v as diffSnapshots,D as insertSchemaExtension,c as pail,N as parseManifest,x as planDevCommand,_ as renderAddColumn,h as renderCreateIndex,y as renderCreateTable,F as renderDropIndex,L as renderDropTable,O as renderMigrationFile,X as runAddCommand,$ as runBuildIndexCommand,n as runCli,t as runCodegenCommand,p as runDeployCommand,i as runDevCommand,or as runExportCommand,j as runImportCommand,C as runInitCommand,u as runMigrateGenerateCommand,rr as runRegistryViewCommand,g as runResetCommand,E as runRpcCommand,B as schemaIrToSnapshot,Y as validateWrangler,Z as validateWranglerConfig,b as validatorKindToSqlType};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{existsSync as m,mkdirSync as k,writeFileSync as f,mkdtempSync as A,rmSync as I,readFileSync as T}from"node:fs";import{tmpdir as M}from"node:os";import{discoverSchema as _,readPackageDependencies as E,discoverMigrations as z}from"@lunora/codegen";import{isInteractive as F,promptSelect as N,promptText as
|
|
2
|
-
`,"utf8"),r.logger.success(`wrote ${g}`),l.unsupported.length>0&&r.logger.warn(`${String(l.unsupported.length)} unsupported diff(s) — see the comment block in ${$} and write the SQL manually`),{code:0,empty:!1,migrationFile:g}},V="migrations.ts",v=/^[A-Za-z_]\w*$/u,X=new Set(["await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),S=/^import\s*\{\s*defineMigration\s*\}\s*from\s*["'](?:@lunora\/server|lunorash\/server)["'][^\n]*$/mu,rr=r=>`import { defineMigration } from "${E(r)?.has("lunorash")??!1?"lunorash/server":"@lunora/server"}";`,er="__lunora_admin__:runMigration",tr="__lunora_admin__:migrationStatus",or="/_lunora/migrate",nr=r=>U(r.trim().toLowerCase().replaceAll(x,"-"),"-"),ir=r=>r.split("-").filter(e=>e.length>0).map((e,o)=>o===0?e:e.charAt(0).toUpperCase()+e.slice(1)).join(""),ar=r=>{const e=c(r,"lunora","schema.ts");if(!m(e))return[];try{const o=new h({skipAddingFilesFromTsConfig:!0});return _(o,e).tables.map(t=>t.name)}catch{return[]}},sr=async r=>r.length>0?N("Which table does this migration iterate?",r.map(e=>({label:e,value:e}))):
|
|
1
|
+
import{existsSync as m,mkdirSync as k,writeFileSync as f,mkdtempSync as A,rmSync as I,readFileSync as T}from"node:fs";import{tmpdir as M}from"node:os";import{discoverSchema as _,readPackageDependencies as E,discoverMigrations as z}from"@lunora/codegen";import{isInteractive as F,promptSelect as N,promptText as O}from"@lunora/config";import{LunoraError as y}from"@lunora/errors";import{join as c}from"@visulima/path";import{Project as h}from"ts-morph";import{u as R}from"../packem_shared/admin-url-Ca-KI3d_.mjs";import{i as q}from"../packem_shared/command-0l-ZPhIX.mjs";import{diffSnapshots as D,renderMigrationFile as L}from"../packem_shared/diffSnapshots-cgOtkd-G.mjs";import{d as j}from"../packem_shared/resolve-target-CeiNrCAx.mjs";import B from"../packem_shared/schemaIrToSnapshot-DV2DilTz.mjs";import{readAndLogBody as H}from"./runRpcCommand.mjs";import{runExportCommand as P}from"../packem_shared/runExportCommand-BpE4AbuX.mjs";import{S as J}from"../packem_shared/import-C9in1wC3.mjs";const u="__lunora_reproject__",W=r=>{if(!r.startsWith(u))return;const e=r.slice(u.length);return e===""?void 0:e},Z=".snapshot.json",x=/[^\da-z]+/gu,U=(r,e)=>{let o=0,t=r.length;for(;o<t&&r[o]===e;)o+=1;for(;t>o&&r[t-1]===e;)t-=1;return r.slice(o,t)},K=r=>{const e=U(r.toLowerCase().replaceAll(x,"_"),"_");return e===""?"auto":e},Q=r=>{const e=(o,t=2)=>o.toString().padStart(t,"0");return`${String(r.getUTCFullYear())}${e(r.getUTCMonth()+1)}${e(r.getUTCDate())}${e(r.getUTCHours())}${e(r.getUTCMinutes())}${e(r.getUTCSeconds())}`},Y=r=>{if(m(r))try{const e=T(r,"utf8"),o=JSON.parse(e);if(o.version!==1)throw new y("INTERNAL",`unsupported snapshot version: ${o.version}`);return o}catch(e){const o=e instanceof Error?e.message:String(e);throw new y("INTERNAL",`failed to read ${r}: ${o}`,{cause:e})}},G=r=>{const e=r.cwd??process.cwd(),o=c(e,"lunora","schema.ts");if(!m(o))return r.logger.error(`schema not found: ${o} — run \`vis generate lunora-table --name=<name>\` to create one`),{code:1,empty:!0,migrationFile:""};const t=new h({skipAddingFilesFromTsConfig:!0}),n=_(t,o),s=B(n),i=c(e,"lunora","migrations"),a=c(i,Z);let d;try{d=Y(a)}catch(p){return r.logger.error(p instanceof Error?p.message:String(p)),{code:1,empty:!0,migrationFile:""}}const l=D(d,s);if(l.empty)return r.logger.info("no schema changes detected — snapshot is already up to date"),{code:0,empty:!0,migrationFile:""};const b=(r.now??(()=>new Date))(),w=K(r.name??"auto"),$=`${Q(b)}_${w}.sql`,g=c(i,$);k(i,{recursive:!0});const C=L(w,l,b.toISOString());return f(g,C,"utf8"),f(a,`${JSON.stringify(s,void 0,4)}
|
|
2
|
+
`,"utf8"),r.logger.success(`wrote ${g}`),l.unsupported.length>0&&r.logger.warn(`${String(l.unsupported.length)} unsupported diff(s) — see the comment block in ${$} and write the SQL manually`),{code:0,empty:!1,migrationFile:g}},V="migrations.ts",v=/^[A-Za-z_]\w*$/u,X=new Set(["await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),S=/^import\s*\{\s*defineMigration\s*\}\s*from\s*["'](?:@lunora\/server|lunorash\/server)["'][^\n]*$/mu,rr=r=>`import { defineMigration } from "${E(r)?.has("lunorash")??!1?"lunorash/server":"@lunora/server"}";`,er="__lunora_admin__:runMigration",tr="__lunora_admin__:migrationStatus",or="/_lunora/migrate",nr=r=>U(r.trim().toLowerCase().replaceAll(x,"-"),"-"),ir=r=>r.split("-").filter(e=>e.length>0).map((e,o)=>o===0?e:e.charAt(0).toUpperCase()+e.slice(1)).join(""),ar=r=>{const e=c(r,"lunora","schema.ts");if(!m(e))return[];try{const o=new h({skipAddingFilesFromTsConfig:!0});return _(o,e).tables.map(t=>t.name)}catch{return[]}},sr=async r=>r.length>0?N("Which table does this migration iterate?",r.map(e=>({label:e,value:e}))):O("Target table for the migration: "),cr=async(r,e)=>{if(e.table!==void 0)return e.table;const o=e.promptTable??(F()?sr:void 0);if(o===void 0){e.logger.error("migrate create requires a target table when not running interactively — re-run with --table <table>");return}const t=(await o(ar(r)))?.trim();if(t===void 0||t===""){e.logger.error("no table selected — re-run with --table <table>");return}return t},dr=async r=>{const e=r.cwd??process.cwd(),o=nr(r.name);if(o==="")return r.logger.error(`invalid migration name: "${r.name}" — must contain at least one alphanumeric character`),{code:1,file:""};const t=ir(o);if(!v.test(t)||X.has(t))return r.logger.error(`invalid migration name: "${r.name}" derives the export \`${t}\`, which is not a valid identifier — pick a name that starts with a letter and isn't a reserved word`),{code:1,file:""};const n=await cr(e,r);if(n===void 0)return{code:1,file:""};if(!v.test(n))return r.logger.error(`invalid table: "${n}" — must be a valid identifier ([A-Za-z_][A-Za-z0-9_]*)`),{code:1,file:""};const s=c(e,"lunora"),i=c(s,V);let a=m(i)?T(i,"utf8"):"";if(a.includes(`id: "${o}"`)||new RegExp(String.raw`\bexport const ${t}\b`,"u").test(a))return r.logger.error(`a migration with id "${o}" (export \`${t}\`) already exists in ${i}`),{code:1,file:""};const d=rr(e);a.trim()===""?a=`${d}
|
|
3
3
|
`:S.test(a)?a=a.replace(S,d):a=`${d}
|
|
4
4
|
${a}`;const l=`export const ${t} = defineMigration({
|
|
5
5
|
id: "${o}",
|
|
@@ -8,4 +8,4 @@ ${a}`;const l=`export const ${t} = defineMigration({
|
|
|
8
8
|
});`;return k(s,{recursive:!0}),f(i,`${a.trimEnd()}
|
|
9
9
|
|
|
10
10
|
${l}
|
|
11
|
-
`,"utf8"),r.logger.success(`scaffolded migration "${o}" in ${i}`),{code:0,file:i}},lr=(r,e)=>{const o=new h({skipAddingFilesFromTsConfig:!0});return z(o,c(r,"lunora")).find(t=>t.id===e)?.table},ur=(r,e)=>{const o=W(e.id);if(o!==void 0)return o;if(e.id.startsWith(u)){e.logger.error(`"${e.id}" names no table — use ${u}<table>`);return}let t;try{t=lr(r,e.id)}catch(n){e.logger.error(n instanceof Error?n.message:String(n));return}if(t===void 0){e.logger.error(`migration "${e.id}" not found under lunora/ — declare it with defineMigration({ id: "${e.id}", ... })`);return}if(t===""){e.logger.error(`migration "${e.id}" must declare \`table\` as a static string literal`);return}return t},mr=r=>{const e=r.cwd??process.cwd();if(r.prod&&r.url===void 0){r.logger.error("--prod requires an explicit --url (refusing to migrate the implicit localhost worker)");return}if(r.prod&&(r.subcommand==="up"||r.subcommand==="down")&&!r.yes){r.logger.error(`migrate ${r.subcommand} --prod runs the migration against production. Re-run with --yes to confirm.`);return}const o=r.token??process.env.LUNORA_ADMIN_TOKEN;if(!o){r.logger.error("admin token required — pass --token or set LUNORA_ADMIN_TOKEN");return}const t=ur(e,r);if(t===void 0)return;const n=
|
|
11
|
+
`,"utf8"),r.logger.success(`scaffolded migration "${o}" in ${i}`),{code:0,file:i}},lr=(r,e)=>{const o=new h({skipAddingFilesFromTsConfig:!0});return z(o,c(r,"lunora")).find(t=>t.id===e)?.table},ur=(r,e)=>{const o=W(e.id);if(o!==void 0)return o;if(e.id.startsWith(u)){e.logger.error(`"${e.id}" names no table — use ${u}<table>`);return}let t;try{t=lr(r,e.id)}catch(n){e.logger.error(n instanceof Error?n.message:String(n));return}if(t===void 0){e.logger.error(`migration "${e.id}" not found under lunora/ — declare it with defineMigration({ id: "${e.id}", ... })`);return}if(t===""){e.logger.error(`migration "${e.id}" must declare \`table\` as a static string literal`);return}return t},mr=r=>{const e=r.cwd??process.cwd();if(r.prod&&r.url===void 0){r.logger.error("--prod requires an explicit --url (refusing to migrate the implicit localhost worker)");return}if(r.prod&&(r.subcommand==="up"||r.subcommand==="down")&&!r.yes){r.logger.error(`migrate ${r.subcommand} --prod runs the migration against production. Re-run with --yes to confirm.`);return}const o=r.token??process.env.LUNORA_ADMIN_TOKEN;if(!o){r.logger.error("admin token required — pass --token or set LUNORA_ADMIN_TOKEN");return}const t=ur(e,r);if(t===void 0)return;const n=R(r.url,r.logger,r.cwd);if(n===void 0)return;const s=r.fetchImpl??globalThis.fetch;if(typeof s!="function")throw new TypeError("no fetch implementation available — pass fetchImpl or run on Node >= 18");return{fetchImpl:s,requestUrl:`${n}${or}`,table:t,token:o}},gr=r=>{const e={id:r.id};return r.subcommand==="status"||(e.direction=r.subcommand,r.dryRun&&(e.dryRun=!0),r.batchSize!==void 0&&(e.batchSize=r.batchSize),r.maxBatches!==void 0&&(e.maxBatches=r.maxBatches)),e},pr=async r=>{const e=mr(r);if(e===void 0)return{body:void 0,code:1,requestUrl:""};const{fetchImpl:o,requestUrl:t,table:n,token:s}=e,i=r.subcommand==="status"?tr:er,a=gr(r);r.logger.info(`POST ${t} -> ${r.subcommand} ${r.id} (table "${n}")`);const d=await o(t,{body:JSON.stringify({args:a,functionPath:i,table:n}),headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},method:"POST"});return{body:await H(d,r.logger),code:d.ok?0:1,requestUrl:t}},fr=async r=>{const{logger:e}=r,o=r.fromUrl??r.toUrl,t=r.toUrl??r.fromUrl;if(o!==void 0&&o===t)return e.error("source and target are the same deployment — pass distinct --from-url and --to-url so the D1 export and Hyperdrive import don't run against one database"),{code:1};const n=r.out===void 0?A(c(M(),"lunora-d1ps-")):void 0,s=r.out??c(n,"dump.ndjson");try{e.info(`Exporting .global() data from the D1 source (${o??"http://localhost:8787"}) …`);const i=await P({fetchImpl:r.fetchImpl,logger:e,out:s,prod:r.prod,tables:r.tables,token:r.fromToken,url:o});if(i.code!==0)return{code:i.code};e.info(`Exported ${String(i.rows)} row(s) (${String(i.bytes)} bytes).`),e.info(`Importing into the Hyperdrive target (${t??"http://localhost:8787"}) …`);const a=await J({batchSize:r.batchSize,fetchImpl:r.fetchImpl,file:s,logger:e,prod:r.prod,token:r.toToken,url:t});return a.code!==0?{code:a.code}:(a.inserted===i.rows?e.info(`✓ Migrated ${String(i.rows)} row(s) — counts match. Verify your app reads from Hyperdrive, then decommission the D1 binding.`):e.warn(`Imported ${String(a.inserted)} of ${String(i.rows)} exported row(s) — the remainder likely already existed in the target (see conflicts above). Re-run after resolving, or inspect the dump with --out.`),{code:0})}finally{n!==void 0&&I(n,{force:!0,recursive:!0})}},Mr=q(({argument:r,cwd:e,logger:o,options:t})=>{const n=r[0];if(n==="generate")return G({cwd:e,logger:o,name:r[1]??t.name});if(n==="d1-to-hyperdrive")return fr({batchSize:t.batchSize,fromToken:t.fromToken??t.token,fromUrl:t.fromUrl??t.url,logger:o,out:t.out,prod:t.prod===!0,tables:t.tables,toToken:t.toToken??t.token,toUrl:t.toUrl??t.url});if(n==="create"){const s=r[1]??t.name;return s?dr({cwd:e,logger:o,name:s,table:t.table}):(o.error("migrate create requires a name. Usage: lunora migrate create <name> [--table <table>]"),{code:1})}if(n==="up"||n==="down"||n==="status"){const s=r[1]??t.name;return s?pr({batchSize:t.batchSize,cwd:e,dryRun:t.dryRun===!0,id:s,logger:o,maxBatches:t.steps,prod:t.prod===!0,subcommand:n,token:t.token,url:j({cwd:e,prod:t.prod===!0,url:t.url}),yes:t.yes===!0}):(o.error(`migrate ${n} requires a migration id. Usage: lunora migrate ${n} <id>`),{code:1})}return o.error(`unknown migrate subcommand: "${n??""}" — expected generate | create | up | down | status`),{code:1}});export{Mr as execute,dr as runMigrateCreateCommand,pr as runMigrateDataCommand,G as runMigrateGenerateCommand,fr as runMigrateToHyperdriveCommand};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{quoteIdentifier as l,sqlAffinityForKind as h,frameworkColumnDdl as $,MAX_D1_TABLE_COLUMNS as u,columnRef as y,physicalIndexName as d}from"@lunora/d1/dialect";import{LunoraError as T}from"@lunora/errors";const R=e=>h(e),m=(e,n)=>{const o=[l(e),n.sqlType];return n.nullable||o.push("NOT NULL"),o.join(" ")},L=e=>{const n=Object.entries(e.columns).map(([t,i])=>` ${m(t,i)}`),o=$(),r=o.length+n.length;if(r>u)throw new T("VALIDATION_ERROR",`table "${e.name}" needs ${String(r)} columns, over D1's ${String(u)}-column limit — split the table, or move the extra fields into one object field`);const s=[...o.map(t=>` ${t}`),...n].join(`,
|
|
2
|
+
`);return`CREATE TABLE IF NOT EXISTS ${l(e.name)} (
|
|
3
|
+
${s}
|
|
4
|
+
);`},b=e=>`DROP TABLE IF EXISTS ${l(e)};`,E=(e,n,o)=>`ALTER TABLE ${l(e)} ADD COLUMN ${m(n,o)};`,c=(e,n)=>{const o=n.fields.map(r=>y(r)).join(", ");return`CREATE ${n.unique?"UNIQUE ":""}INDEX IF NOT EXISTS ${d(e,n.name)} ON ${l(e)} (${o});`},O=(e,n)=>`DROP INDEX IF EXISTS ${d(e,n)};`,N=(e,n,o,r,s)=>{o.sqlType!==r.sqlType&&s.push({kind:"columnTypeChange",summary:`column type change on ${e}.${n}: ${o.sqlType} → ${r.sqlType} (write SQL manually)`}),o.nullable!==r.nullable&&s.push({kind:"columnTypeChange",summary:`nullability change on ${e}.${n}: ${o.nullable?"NULL":"NOT NULL"} → ${r.nullable?"NULL":"NOT NULL"} (write SQL manually)`})},g=(e,n,o,r,s)=>{for(const[t,i]of Object.entries(o)){const a=n[t];if(a===void 0){r.push({kind:"addColumn",sql:E(e,t,i),summary:`ADD COLUMN ${e}.${t}`});continue}N(e,t,a,i,s)}for(const t of Object.keys(n))o[t]===void 0&&s.push({kind:"dropColumn",summary:`DROP COLUMN ${e}.${t} (SQLite drop-column requires careful migration — write SQL manually)`})},I=(e,n,o,r,s)=>{for(const[t,i]of Object.entries(o)){const a=n[t];if(a===void 0){r.push({kind:"createIndex",sql:c(e,i),summary:`CREATE INDEX ${t} ON ${e}`});continue}(!(a.fields.length===i.fields.length&&a.fields.every((p,f)=>p===i.fields[f]))||a.unique!==i.unique)&&s.push({kind:"indexRename",summary:`index ${t} changed on ${e} — drop+create manually if intentional`})}for(const t of Object.keys(n))o[t]===void 0&&r.push({kind:"dropIndex",sql:O(e,t),summary:`DROP INDEX ${t}`})},D=(e,n,o)=>{o.push({kind:"createTable",sql:L(n),summary:`CREATE TABLE ${e}`});for(const r of Object.values(n.indexes))o.push({kind:"createIndex",sql:c(e,r),summary:`CREATE INDEX ${r.name} ON ${e}`})},S=(e,n)=>{const o=e?.tables??{},r=[],s=[];for(const[t,i]of Object.entries(n.tables)){const a=o[t];if(a===void 0){D(t,i,r);continue}g(t,a.columns,i.columns,r,s),I(t,a.indexes,i.indexes,r,s)}for(const t of Object.keys(o))n.tables[t]===void 0&&r.push({kind:"dropTable",sql:b(t),summary:`DROP TABLE ${t}`});return{empty:r.length===0&&s.length===0,entries:r,unsupported:s}},C=(e,n,o)=>{const r=[`-- Lunora migration: ${e}`,`-- Generated at ${o}`,"-- This file was produced by `lunora migrate generate`. Review carefully before applying.",""];for(const s of n.entries)r.push(`-- ${s.summary}`,s.sql,"");if(n.unsupported.length>0){r.push("-- ---------------------------------------------------------------","-- The following deltas are NOT auto-generated in v0.1.","-- Write the appropriate SQL below by hand:","--");for(const s of n.unsupported)r.push(`-- * ${s.summary}`);r.push("-- ---------------------------------------------------------------","")}return n.empty&&r.push("-- No changes detected. Re-running `lunora migrate generate` will overwrite this file.",""),r.join(`
|
|
5
|
+
`)};export{S as diffSnapshots,E as renderAddColumn,c as renderCreateIndex,L as renderCreateTable,O as renderDropIndex,b as renderDropTable,C as renderMigrationFile,R as validatorKindToSqlType};
|
package/dist/packem_shared/{schemaIrToSnapshot-Dahp39qH.mjs → schemaIrToSnapshot-DV2DilTz.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{validatorKindToSqlType as i}from"./diffSnapshots-
|
|
1
|
+
import{validatorKindToSqlType as i}from"./diffSnapshots-cgOtkd-G.mjs";const r=e=>e.kind==="optional"&&e.inner?{nullable:!0,sqlType:i(e.inner.kind)}:{nullable:!1,sqlType:i(e.kind)},f=e=>e==="global",c=e=>{const s={};for(const o of e.tables){if(!f(o.shardMode))continue;const a={};for(const[n,t]of Object.entries(o.shape))a[n]=r(t);const l={};for(const n of o.indexes)l[n.name]={fields:[...n.fields],name:n.name,unique:n.unique??!1};s[o.name]={columns:a,indexes:l,name:o.name}}return{tables:s,version:1}};export{c as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.159",
|
|
4
4
|
"description": "The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-skills",
|
|
@@ -52,16 +52,16 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@bomb.sh/tab": "0.0.21",
|
|
55
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
56
|
-
"@lunora/bindings": "1.0.0-alpha.
|
|
57
|
-
"@lunora/codegen": "1.0.0-alpha.
|
|
58
|
-
"@lunora/config": "1.0.0-alpha.
|
|
59
|
-
"@lunora/container": "1.0.0-alpha.
|
|
60
|
-
"@lunora/d1": "1.0.0-alpha.
|
|
61
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
62
|
-
"@lunora/mcp": "1.0.0-alpha.
|
|
63
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
64
|
-
"@lunora/seed": "1.0.0-alpha.
|
|
55
|
+
"@lunora/advisor": "1.0.0-alpha.75",
|
|
56
|
+
"@lunora/bindings": "1.0.0-alpha.27",
|
|
57
|
+
"@lunora/codegen": "1.0.0-alpha.103",
|
|
58
|
+
"@lunora/config": "1.0.0-alpha.132",
|
|
59
|
+
"@lunora/container": "1.0.0-alpha.29",
|
|
60
|
+
"@lunora/d1": "1.0.0-alpha.74",
|
|
61
|
+
"@lunora/errors": "1.0.0-alpha.20",
|
|
62
|
+
"@lunora/mcp": "1.0.0-alpha.67",
|
|
63
|
+
"@lunora/runtime": "1.0.0-alpha.60",
|
|
64
|
+
"@lunora/seed": "1.0.0-alpha.69",
|
|
65
65
|
"@visulima/cerebro": "3.0.0",
|
|
66
66
|
"@visulima/error": "6.0.0",
|
|
67
67
|
"@visulima/fs": "5.0.5",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{quoteIdentifier as l,sqlAffinityForKind as f,frameworkColumnDdl as y,columnRef as $,physicalIndexName as u}from"@lunora/d1/dialect";const q=e=>f(e),d=(e,n)=>{const s=[l(e),n.sqlType];return n.nullable||s.push("NOT NULL"),s.join(" ")},T=e=>{const n=Object.entries(e.columns).map(([r,a])=>` ${d(r,a)}`),s=[...y().map(r=>` ${r}`),...n].join(`,
|
|
2
|
-
`);return`CREATE TABLE IF NOT EXISTS ${l(e.name)} (
|
|
3
|
-
${s}
|
|
4
|
-
);`},h=e=>`DROP TABLE IF EXISTS ${l(e)};`,b=(e,n,s)=>`ALTER TABLE ${l(e)} ADD COLUMN ${d(n,s)};`,m=(e,n)=>{const s=n.fields.map(r=>$(r)).join(", ");return`CREATE ${n.unique?"UNIQUE ":""}INDEX IF NOT EXISTS ${u(e,n.name)} ON ${l(e)} (${s});`},E=(e,n)=>`DROP INDEX IF EXISTS ${u(e,n)};`,L=(e,n,s,r,a)=>{s.sqlType!==r.sqlType&&a.push({kind:"columnTypeChange",summary:`column type change on ${e}.${n}: ${s.sqlType} → ${r.sqlType} (write SQL manually)`}),s.nullable!==r.nullable&&a.push({kind:"columnTypeChange",summary:`nullability change on ${e}.${n}: ${s.nullable?"NULL":"NOT NULL"} → ${r.nullable?"NULL":"NOT NULL"} (write SQL manually)`})},N=(e,n,s,r,a)=>{for(const[o,i]of Object.entries(s)){const t=n[o];if(t===void 0){r.push({kind:"addColumn",sql:b(e,o,i),summary:`ADD COLUMN ${e}.${o}`});continue}L(e,o,t,i,a)}for(const o of Object.keys(n))s[o]===void 0&&a.push({kind:"dropColumn",summary:`DROP COLUMN ${e}.${o} (SQLite drop-column requires careful migration — write SQL manually)`})},O=(e,n,s,r,a)=>{for(const[o,i]of Object.entries(s)){const t=n[o];if(t===void 0){r.push({kind:"createIndex",sql:m(e,i),summary:`CREATE INDEX ${o} ON ${e}`});continue}(!(t.fields.length===i.fields.length&&t.fields.every((p,c)=>p===i.fields[c]))||t.unique!==i.unique)&&a.push({kind:"indexRename",summary:`index ${o} changed on ${e} — drop+create manually if intentional`})}for(const o of Object.keys(n))s[o]===void 0&&r.push({kind:"dropIndex",sql:E(e,o),summary:`DROP INDEX ${o}`})},g=(e,n,s)=>{s.push({kind:"createTable",sql:T(n),summary:`CREATE TABLE ${e}`});for(const r of Object.values(n.indexes))s.push({kind:"createIndex",sql:m(e,r),summary:`CREATE INDEX ${r.name} ON ${e}`})},D=(e,n)=>{const s=e?.tables??{},r=[],a=[];for(const[o,i]of Object.entries(n.tables)){const t=s[o];if(t===void 0){g(o,i,r);continue}N(o,t.columns,i.columns,r,a),O(o,t.indexes,i.indexes,r,a)}for(const o of Object.keys(s))n.tables[o]===void 0&&r.push({kind:"dropTable",sql:h(o),summary:`DROP TABLE ${o}`});return{empty:r.length===0&&a.length===0,entries:r,unsupported:a}},C=(e,n,s)=>{const r=[`-- Lunora migration: ${e}`,`-- Generated at ${s}`,"-- This file was produced by `lunora migrate generate`. Review carefully before applying.",""];for(const a of n.entries)r.push(`-- ${a.summary}`,a.sql,"");if(n.unsupported.length>0){r.push("-- ---------------------------------------------------------------","-- The following deltas are NOT auto-generated in v0.1.","-- Write the appropriate SQL below by hand:","--");for(const a of n.unsupported)r.push(`-- * ${a.summary}`);r.push("-- ---------------------------------------------------------------","")}return n.empty&&r.push("-- No changes detected. Re-running `lunora migrate generate` will overwrite this file.",""),r.join(`
|
|
5
|
-
`)};export{D as diffSnapshots,b as renderAddColumn,m as renderCreateIndex,T as renderCreateTable,E as renderDropIndex,h as renderDropTable,C as renderMigrationFile,q as validatorKindToSqlType};
|