@lunora/cli
Version:
The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands
2 lines (1 loc) • 3.07 kB
JavaScript
import{d as p}from"../packem_shared/command-BpMv2n0o.mjs";import{EXIT_CODE as u}from"../packem_shared/EXIT_CODE-DQVhSE-1.mjs";import{a as m}from"../packem_shared/resolve-target-C_ZloTvd.mjs";import{runMigrateDataCommand as g,runMigrateGenerateCommand as y,runMigrateBackendCommand as b,runMigrateCreateCommand as h}from"../packem_shared/runMigrateGenerateCommand-DHdSMKbu.mjs";import{r as w}from"../packem_shared/sql-u1MSmopg.mjs";const f=o=>{const{argument:a,cwd:n,logger:r,options:t}=o,e=y({cwd:n,logger:r,name:a[1]??t.name});return{code:e.code,data:{empty:e.empty,migrationFile:e.migrationFile===""?void 0:e.migrationFile,subcommand:"generate"},...e.error===void 0?{}:{error:e.error}}},k=async(o,a)=>{const{logger:n,options:r}=o,t=await b({batchSize:r.batchSize,direction:a,fromToken:r.fromToken??r.token,fromUrl:r.fromUrl??r.url,logger:n,out:r.out,prod:r.prod===!0,replace:r.replace===!0,tables:r.tables,toToken:r.toToken??r.token,toUrl:r.toUrl??r.url,yes:r.yes===!0});return{code:t.code,data:{bytes:t.bytes,exported:t.exported,imported:t.imported,replaced:t.replaced,subcommand:a},...t.error===void 0?{}:{error:t.error}}},v=async o=>{const{argument:a,cwd:n,logger:r,options:t}=o,e=a[1]??t.name;if(!e){const c="migrate create requires a name. Usage: lunora migrate create <name> [--table <table>]";return r.error(c),{code:u.USAGE,error:c}}const s=await h({cwd:n,logger:r,name:e,table:t.table});return{code:s.code,data:{file:s.file===""?void 0:s.file,name:e,subcommand:"create"}}},i=async(o,a)=>{const{cwd:n,logger:r,options:t}=o,e=await w({allowDestructive:t.allowDestructive===!0,baseline:a.baseline,baselineThrough:a.baselineThrough,cwd:n,dryRun:a.dryRun,logger:r,prod:t.prod===!0,token:t.token,url:m({cwd:n,prod:t.prod===!0,url:t.url}),yes:t.yes===!0});return{code:e.code,data:{files:e.files,subcommand:a.subcommand},...e.error===void 0?{}:{error:e.error}}},l=async(o,a)=>{const{argument:n,cwd:r,logger:t,options:e}=o,s=n[1]??e.name;if(!s){const d=`migrate ${a} requires a migration id. Usage: lunora migrate ${a} <id>`;return t.error(d),{code:u.USAGE,error:d}}const c=await g({batchSize:e.batchSize,cwd:r,dryRun:e.dryRun===!0,id:s,logger:t,maxBatches:e.steps,prod:e.prod===!0,subcommand:a,token:e.token,url:m({cwd:r,prod:e.prod===!0,url:e.url}),yes:e.yes===!0});return{code:c.code,data:{id:s,result:c.body,subcommand:a}}},R=p(async({argument:o,cwd:a,logger:n,options:r})=>{const t=o[0],e={argument:o,cwd:a,logger:n,options:r};switch(t){case"apply":return await i(e,{baseline:r.baseline===!0,baselineThrough:r.baselineThrough,dryRun:r.dryRun===!0,subcommand:"apply"});case"create":return await v(e);case"d1-to-hyperdrive":case"hyperdrive-to-d1":return await k(e,t);case"down":case"up":return await l(e,t);case"generate":return f(e);case"status":return r.sql===!0?await i(e,{baseline:!1,dryRun:!0,subcommand:"status-sql"}):await l(e,t);default:{const s=`unknown migrate subcommand: "${t??""}" — expected generate | apply | create | up | down | status | d1-to-hyperdrive | hyperdrive-to-d1`;return e.logger.error(s),{code:u.USAGE,error:s}}}});export{R as execute};