@lunora/studio 1.0.0-alpha.185 → 1.0.0-alpha.186
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/packem_chunks/migrations-route.mjs +1 -1
- package/dist/standalone/{chunk-3PUGTMHP.js → chunk-23C2QL7Z.js} +1 -1
- package/dist/standalone/{chunk-SMMYONB7.js → chunk-2FGXE3E5.js} +1 -1
- package/dist/standalone/{chunk-2VGRBZVS.js → chunk-367RGUUX.js} +1 -1
- package/dist/standalone/{chunk-QZJVCXWS.js → chunk-3BN3N2CX.js} +1 -1
- package/dist/standalone/{chunk-VWLX4CH4.js → chunk-62IKYVD3.js} +2 -2
- package/dist/standalone/{chunk-UCYK6YWD.js → chunk-6A34IMQS.js} +1 -1
- package/dist/standalone/{chunk-6MMHVZID.js → chunk-6DLHIMOI.js} +1 -1
- package/dist/standalone/{chunk-UD47ZOIF.js → chunk-6FTYD55M.js} +1 -1
- package/dist/standalone/{chunk-EMUTRNK5.js → chunk-6MJU7KID.js} +1 -1
- package/dist/standalone/{chunk-ZVMUTCUE.js → chunk-7SBL2ENI.js} +1 -1
- package/dist/standalone/{chunk-GXSHHAYL.js → chunk-AJU3V2XW.js} +1 -1
- package/dist/standalone/{chunk-XXB357HN.js → chunk-AO3LNXNG.js} +1 -1
- package/dist/standalone/{chunk-MH73AR4R.js → chunk-AWN2GXCK.js} +1 -1
- package/dist/standalone/{chunk-JA7FUFCP.js → chunk-B6BFVYFA.js} +1 -1
- package/dist/standalone/{chunk-GQQPTCCH.js → chunk-BG52HJBJ.js} +1 -1
- package/dist/standalone/{chunk-77UI3GTT.js → chunk-BI2PP4AE.js} +1 -1
- package/dist/standalone/{chunk-UREV5NIX.js → chunk-BNIDGSDE.js} +1 -1
- package/dist/standalone/{chunk-YAMJRRT2.js → chunk-BWRPOIEI.js} +1 -1
- package/dist/standalone/{chunk-FGEBPY6M.js → chunk-C3UMVVZD.js} +1 -1
- package/dist/standalone/{chunk-U5EMA2D7.js → chunk-CFN6A74K.js} +1 -1
- package/dist/standalone/{chunk-HEIGV6KL.js → chunk-CMO25UOM.js} +1 -1
- package/dist/standalone/{chunk-2TAFAGWH.js → chunk-DAAYIBSL.js} +1 -1
- package/dist/standalone/{chunk-RY2LZULX.js → chunk-DAXY4RAL.js} +1 -1
- package/dist/standalone/{chunk-EKMKNRYI.js → chunk-DK7IUHFW.js} +1 -1
- package/dist/standalone/{chunk-H7UQ7W6L.js → chunk-DLF7WRVK.js} +1 -1
- package/dist/standalone/{chunk-5G2MAI3G.js → chunk-FI3UY4QJ.js} +1 -1
- package/dist/standalone/{chunk-NSYGYSMJ.js → chunk-FUXL36RK.js} +1 -1
- package/dist/standalone/{chunk-22EHJEFE.js → chunk-I57A5YB6.js} +1 -1
- package/dist/standalone/{chunk-2PYJCU6C.js → chunk-IZDX3F65.js} +1 -1
- package/dist/standalone/{chunk-Q5R67CRQ.js → chunk-J53LW4GK.js} +1 -1
- package/dist/standalone/{chunk-J6ESSV7B.js → chunk-KE5T44IA.js} +1 -1
- package/dist/standalone/{chunk-CEA2QYAI.js → chunk-MKL7VDTL.js} +2 -2
- package/dist/standalone/{chunk-PAWM6IP3.js → chunk-N4GEA5GK.js} +1 -1
- package/dist/standalone/{chunk-MVJL6J4Y.js → chunk-N6CQJUDY.js} +1 -1
- package/dist/standalone/{chunk-ZEZ5FW7V.js → chunk-NO5VGTWP.js} +1 -1
- package/dist/standalone/{chunk-NGEP4H3Q.js → chunk-ORJB5XQH.js} +1 -1
- package/dist/standalone/{chunk-QAIEAIIE.js → chunk-P5RUFDVX.js} +1 -1
- package/dist/standalone/chunk-PAZ72JHQ.js +1 -0
- package/dist/standalone/{chunk-MRI7UILC.js → chunk-PGV42T2U.js} +1 -1
- package/dist/standalone/{chunk-2254YC77.js → chunk-PJSZTRRT.js} +1 -1
- package/dist/standalone/{chunk-OUKLYU72.js → chunk-PTRUAQYA.js} +1 -1
- package/dist/standalone/{chunk-SZSHO6RE.js → chunk-PYI2MI4Q.js} +1 -1
- package/dist/standalone/{chunk-TLFNAWL6.js → chunk-Q6PUWGXK.js} +1 -1
- package/dist/standalone/{chunk-HB2AVFM7.js → chunk-QIPTFNQK.js} +1 -1
- package/dist/standalone/{chunk-RJZI2ZRF.js → chunk-STS6SGNB.js} +1 -1
- package/dist/standalone/{chunk-METTWXRR.js → chunk-U7YOMGYN.js} +1 -1
- package/dist/standalone/{chunk-OGEHSNF7.js → chunk-UDXIBUS6.js} +1 -1
- package/dist/standalone/{chunk-RBAMNKW7.js → chunk-USCV7TYG.js} +1 -1
- package/dist/standalone/{chunk-IOPBEKDK.js → chunk-VBDYQCRQ.js} +1 -1
- package/dist/standalone/{chunk-P52AMBNB.js → chunk-VXQJWD3F.js} +1 -1
- package/dist/standalone/{chunk-K5ZNTNAC.js → chunk-W5YA2J66.js} +1 -1
- package/dist/standalone/{chunk-PCQP4NHL.js → chunk-WD22LMYA.js} +1 -1
- package/dist/standalone/{chunk-QMFQGVTQ.js → chunk-WJPA7RPR.js} +1 -1
- package/dist/standalone/{chunk-L3AFRJE2.js → chunk-WNVPC7FI.js} +1 -1
- package/dist/standalone/{chunk-HQWKWSY4.js → chunk-XSNWSHZ6.js} +1 -1
- package/dist/standalone/{chunk-XRR2R2H5.js → chunk-Y76TQLLR.js} +1 -1
- package/dist/standalone/{chunk-AMPB3H6K.js → chunk-YOKBLIIN.js} +1 -1
- package/dist/standalone/{chunk-6DGK6352.js → chunk-YVVP4DRM.js} +1 -1
- package/dist/standalone/{chunk-FHW7T5NC.js → chunk-ZNYTH4BS.js} +1 -1
- package/dist/standalone/{chunk-7F5LVCXA.js → chunk-ZTQSA34U.js} +1 -1
- package/dist/standalone/{chunk-Z4FYPU4Q.js → chunk-ZWDPWM3I.js} +1 -1
- package/dist/standalone/studio.js +1 -1
- package/package.json +6 -6
- package/dist/standalone/chunk-GLTOTU4J.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as q}from"react/compiler-runtime";import{useMemo as T,useState as W}from"react";import{useT as E}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as j}from"../packem_shared/utils-bhneXptQ.mjs";import{MigrationsPanel as _}from"../packem_shared/MigrationsPanel-BPWzFdxC.mjs";import{useNavigate as B,useSearch as z}from"@tanstack/react-router";import{E as X}from"../packem_shared/error-alert-tf5zvSLV.mjs";import{E as Y}from"../packem_shared/empty-state-D7jEML_T.mjs";import{u as I}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{ADMIN_FUNCTIONS as M}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as Z,f as ee}from"../packem_shared/internal-B6haJbiP.mjs";import{S as te}from"../packem_shared/schema-diagram-CDj_69jF.mjs";import{jsx as c,jsxs as v}from"react/jsx-runtime";const R=1;function ne(t){const e={},i=Object.keys(t);i.sort();for(const n of i)e[n]=t[n];return e}const w=t=>typeof t=="object"&&t!==null,ie=t=>w(t)&&w(t.fields)&&w(t.indexes)&&w(t.relations)&&typeof t.shardMode=="string",se=t=>{if(t===void 0||t.trim()==="")return{status:"absent"};let e;try{e=JSON.parse(t)}catch(n){return{error:`baseline is not valid JSON: ${n instanceof Error?n.message:String(n)}`,status:"invalid"}}if(!w(e)||e.version!==R||!w(e.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(R)})`,status:"invalid"};for(const[n,s]of Object.entries(e.tables))if(!ie(s))return{error:`baseline table "${n}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof e.jurisdiction=="string"?e.jurisdiction:void 0,migrationIds:Array.isArray(e.migrationIds)?e.migrationIds:[],tables:e.tables,version:R},status:"ok"}},ae=(t,e)=>t.unique===e.unique&&t.fields.length===e.fields.length&&t.fields.every((i,n)=>i===e.fields[n]),J=t=>t.unique!==void 0,A=({nullable:t,optional:e,refined:i,unique:n,...s})=>JSON.stringify(ne(s)),P=t=>({form:JSON.stringify([A(t),t.optional===!0,t.nullable===!0]),refined:t.refined===!0}),V=t=>t.kind==="union"&&t.members?t.members.map(e=>P(e)):[P({...t,nullable:!1,optional:!1})],oe=(t,e)=>{if(e.kind!=="union")return!1;const i=V(e);return V(t).every(n=>i.some(s=>s.form===n.form&&(n.refined||!s.refined)))},y=t=>{switch(t.kind){case"array":return`array(${t.of?y(t.of):"?"})`;case"id":return`id(${t.ref??"?"})`;case"literal":return`literal(${t.literal??"?"})`;case"object":return`object({ ${Object.keys(t.fields??{}).join(", ")} })`;case"record":return`record(${t.key?y(t.key):"?"}, ${t.of?y(t.of):"?"})`;case"union":return(t.members??[]).map(e=>y(e)).join(" | ");default:return t.kind}},O=(t,e,i)=>({remediation:"backfill",scope:"table",severity:"breaking",summary:i,table:t,type:e}),F=(t,e,i)=>({remediation:"none",scope:"table",severity:"safe",summary:i,table:t,type:e}),re=(t,e,i,n,s)=>{if(!(i.kind===n.kind&&(!s||A(i)===A(n))))return s&&oe(i,n)?F(t,"widenedFieldShape",`field ${t}.${e} widened: ${y(i)} → ${y(n)} — every stored value stays valid`):i.kind!==n.kind?O(t,"changedFieldKind",`field ${t}.${e} changed type: ${i.kind} → ${n.kind} — add a data migration to convert existing values`):O(t,"changedFieldShape",`field ${t}.${e} changed shape: ${y(i)} → ${y(n)} — stored values were written against the old shape; add a data migration to convert them`)},de=(t,e,i,n)=>{const s=[];return i.unique!==n.unique&&s.push(n.unique===!0?O(t,"addedFieldConstraint",`field ${t}.${e} became unique — existing duplicates would violate it; add a data migration to de-duplicate first`):F(t,"relaxedFieldConstraint",`field ${t}.${e} is no longer unique`)),i.nullable!==n.nullable&&s.push(n.nullable===!0?F(t,"relaxedFieldConstraint",`field ${t}.${e} became nullable`):O(t,"addedFieldConstraint",`field ${t}.${e} is no longer nullable — rows holding NULL would be invalid; add a data migration to backfill them`)),i.refined!==n.refined&&s.push(n.refined===!0?O(t,"addedFieldConstraint",`field ${t}.${e} gained a validation refinement — stored values were never checked against it; add a data migration if any could fail`):F(t,"relaxedFieldConstraint",`field ${t}.${e} dropped its validation refinement`)),s},K=(t,e,i,n)=>{const s=[],o=J(i)&&J(n),a=re(t,e,i,n,o);return a&&s.push(a),o&&s.push(...de(t,e,i,n)),i.optional&&!n.optional?s.push({remediation:"backfill",severity:"breaking",summary:`field ${t}.${e} became required — rows missing it would be invalid; add a data migration to backfill it`,table:t,scope:"table",type:"fieldOptionalToRequired"}):!i.optional&&n.optional&&s.push({remediation:"none",scope:"table",severity:"safe",summary:`field ${t}.${e} became optional`,table:t,type:"fieldRequiredToOptional"}),s},le=(t,e,i)=>i.optional?{remediation:"none",scope:"table",severity:"safe",summary:`added optional field ${t}.${e}`,table:t,type:"addedOptionalField"}:{remediation:"backfill",severity:"breaking",summary:`added required field ${t}.${e} — existing rows have no value; add a data migration to backfill it`,table:t,scope:"table",type:"addedRequiredField"},ce=(t,e,i,n)=>{for(const[s,o]of Object.entries(i.fields)){const a=e.fields[s];a===void 0?n.push(le(t,s,o)):n.push(...K(t,s,a,o))}for(const s of Object.keys(e.fields))i.fields[s]===void 0&&n.push({remediation:"backfill",severity:"breaking",summary:`removed field ${t}.${s} — add a data migration if stored data must be cleaned up`,table:t,scope:"table",type:"removedField"})},ue=(t,e,i,n)=>{for(const[s,o]of Object.entries(i.indexes)){const a=e.indexes[s];if(a===void 0){n.push(o.unique?{remediation:"backfill",scope:"table",severity:"breaking",summary:`added unique index ${s} on ${t} — existing duplicates would violate it; add a data migration to de-duplicate first`,table:t,type:"addedIndex"}:{remediation:"none",scope:"table",severity:"safe",summary:`added index ${s} on ${t}`,table:t,type:"addedIndex"});continue}ae(a,o)||n.push({remediation:"code",severity:"breaking",summary:`index ${s} on ${t} changed shape — a query may have relied on the old index`,table:t,scope:"table",type:"changedIndex"})}for(const s of Object.keys(e.indexes))i.indexes[s]===void 0&&n.push({remediation:"code",severity:"breaking",summary:`removed index ${s} on ${t} — a query that used \`.withIndex("${s}")\` would break`,table:t,scope:"table",type:"removedIndex"})},me=(t,e,i,n)=>{for(const s of Object.keys(i.relations))e.relations[s]===void 0&&n.push({remediation:"none",scope:"schema",severity:"safe",summary:`added relation ${t}.${s}`,table:t,type:"addedRelation"});for(const s of Object.keys(e.relations))i.relations[s]===void 0&&n.push({remediation:"code",scope:"schema",severity:"breaking",summary:`removed relation ${t}.${s}`,table:t,type:"removedRelation"})},fe=(t,e,i,n)=>{e.shardMode!==i.shardMode&&n.push({remediation:"rehome",severity:"breaking",summary:`table ${t} changed shard mode: ${e.shardMode} → ${i.shardMode} — its physical storage moves, and existing rows do NOT follow the schema; re-home them with an export/import round trip (https://lunora.sh/docs/concepts/sharding#migrating-a-populated-table)`,table:t,scope:"table",type:"changedShardMode"}),ce(t,e,i,n),ue(t,e,i,n),me(t,e,i,n)},he=(t,e)=>{const i=[],n=t?.tables??{};for(const[s,o]of Object.entries(e.tables)){const a=n[s];if(a===void 0){i.push({remediation:"none",scope:"table",severity:"safe",summary:`added table ${s}`,table:s,type:"addedTable"});continue}fe(s,a,o,i)}for(const s of Object.keys(n))e.tables[s]===void 0&&i.push({remediation:"rehome",scope:"table",severity:"breaking",summary:`removed table ${s} — its rows stay in each shard's SQLite, unreachable through the schema; export the shard first if the data must be kept`,table:s,type:"removedTable"});if(t!==void 0&&t.jurisdiction!==e.jurisdiction){const s=t.jurisdiction??"(none)",o=e.jurisdiction??"(none)";i.push({remediation:"rehome",scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${s} to ${o} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,type:"changedJurisdiction"})}return{changes:i}},H=t=>Object.entries(t.fields).map(([e,i])=>({name:e,optional:i.optional,ref:Object.values(t.relations).find(n=>n.field===e&&n.kind==="one")?.table,type:y(i)})),Q=(t,e,i)=>{const n={},s=e?.fields??{},o=i?.fields??{};for(const[a,r]of Object.entries(o)){const d=s[a];d===void 0?n[a]=e===void 0?"unchanged":"added":n[a]=K(t,a,d,r).length===0?"unchanged":"changed"}for(const a of Object.keys(s))o[a]===void 0&&(n[a]="removed");return n},pe=(t,e)=>{const{changes:i}=he(t,e),n=new Set(i.filter(a=>a.scope==="table"&&a.table!==void 0).map(a=>a.table)),s=[],o=(a,r)=>a?"added":n.has(r)?"changed":"context";for(const[a,r]of Object.entries(e.tables)){const d=t?.tables[a],u=o(d===void 0,a);s.push({columns:H(r),fieldStatus:Q(a,d,r),name:a,shardMode:r.shardMode,status:u})}for(const[a,r]of Object.entries(t?.tables??{}))e.tables[a]===void 0&&s.push({columns:H(r),fieldStatus:Q(a,r,void 0),name:a,shardMode:r.shardMode,status:"removed"});return s.sort((a,r)=>a.name.localeCompare(r.name)),{breakingCount:i.filter(a=>a.severity==="breaking").length,changes:i,tables:s}},L=t=>{const e=se(t);return e.status==="ok"?e.snapshot:void 0},ge={added:"ring-2 ring-emerald-500/60",changed:"ring-2 ring-amber-500/70",context:"opacity-55",removed:"opacity-70 ring-2 ring-destructive/60"},be=t=>t==="global"?"global":"shard",ve=t=>{const e=q(24),{appliedAt:i,hash:n,onSelect:s,selected:o,seq:a}=t,r=o?"border-s-primary bg-accent/60 text-foreground":"border-s-transparent text-muted-foreground hover:bg-accent/30 hover:text-foreground";let d;e[0]!==r?(d=j("flex w-full flex-col items-start gap-1 border-s-2 px-4 py-3 text-start outline-none transition-colors",r),e[0]=r,e[1]=d):d=e[1];const u=`sh-version-${n}`;let h;e[2]!==n||e[3]!==s?(h=()=>{s(n)},e[2]=n,e[3]=s,e[4]=h):h=e[4];let f;e[5]!==a?(f=v("span",{className:"font-mono text-[13px] tabular-nums",children:["v",a]}),e[5]=a,e[6]=f):f=e[6];let g;e[7]!==n?(g=n.slice(0,7),e[7]=n,e[8]=g):g=e[8];let p;e[9]!==g?(p=c("span",{className:"ms-auto font-mono text-[10px] tracking-wider text-muted-foreground/70 uppercase",children:g}),e[9]=g,e[10]=p):p=e[10];let m;e[11]!==f||e[12]!==p?(m=v("span",{className:"flex w-full items-baseline gap-2",children:[f,p]}),e[11]=f,e[12]=p,e[13]=m):m=e[13];let b;e[14]!==i?(b=Z(i),e[14]=i,e[15]=b):b=e[15];let x;e[16]!==b?(x=c("span",{className:"font-mono text-[10px] tracking-wide text-muted-foreground/70",children:b}),e[16]=b,e[17]=x):x=e[17];let k;return e[18]!==x||e[19]!==d||e[20]!==u||e[21]!==h||e[22]!==m?(k=c("li",{children:v("button",{className:d,"data-testid":u,onClick:h,type:"button",children:[m,x]})}),e[18]=x,e[19]=d,e[20]=u,e[21]=h,e[22]=m,e[23]=k):k=e[23],k},xe=t=>{const e=q(26),{breaking:i,count:n,first:s}=t,o=E();if(s){let p;e[0]!==n?(p=c("span",{className:"text-3xl leading-none font-light tracking-tight tabular-nums",children:n}),e[0]=n,e[1]=p):p=e[1];let m;e[2]!==o?(m=o("tables"),e[2]=o,e[3]=m):m=e[3];let b;e[4]!==m?(b=c("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:m}),e[4]=m,e[5]=b):b=e[5];let x;return e[6]!==p||e[7]!==b?(x=v("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[p,b]}),e[6]=p,e[7]=b,e[8]=x):x=e[8],x}const a=i>0&&"text-destructive";let r;e[9]!==a?(r=j("text-3xl leading-none font-light tracking-tight tabular-nums",a),e[9]=a,e[10]=r):r=e[10];let d;e[11]!==n||e[12]!==r?(d=c("span",{className:r,children:n}),e[11]=n,e[12]=r,e[13]=d):d=e[13];let u;e[14]!==n||e[15]!==o?(u=o(n===1?"change":"changes"),e[14]=n,e[15]=o,e[16]=u):u=e[16];let h;e[17]!==u?(h=c("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:u}),e[17]=u,e[18]=h):h=e[18];let f;e[19]!==i||e[20]!==o?(f=i>0&&v("span",{className:"font-mono text-[11px] tracking-widest text-destructive uppercase",children:["· ",o("{count} breaking",{count:i})]}),e[19]=i,e[20]=o,e[21]=f):f=e[21];let g;return e[22]!==d||e[23]!==h||e[24]!==f?(g=v("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[d,h,f]}),e[22]=d,e[23]=h,e[24]=f,e[25]=g):g=e[25],g},U={addedFieldConstraint:{action:"added",kind:"constraint"},addedIndex:{action:"added",kind:"index"},addedOptionalField:{action:"added",kind:"field?"},addedRelation:{action:"added",kind:"relation"},addedRequiredField:{action:"added",kind:"field"},addedTable:{action:"added",kind:"table"},changedFieldKind:{action:"changed",kind:"field kind"},changedFieldShape:{action:"changed",kind:"field shape"},changedIndex:{action:"changed",kind:"index"},changedJurisdiction:{action:"changed",kind:"jurisdiction"},changedShardMode:{action:"changed",kind:"shard mode"},fieldOptionalToRequired:{action:"changed",kind:"field → required"},fieldRequiredToOptional:{action:"changed",kind:"field → optional"},relaxedFieldConstraint:{action:"removed",kind:"constraint"},removedField:{action:"removed",kind:"field"},removedIndex:{action:"removed",kind:"index"},removedRelation:{action:"removed",kind:"relation"},removedTable:{action:"removed",kind:"table"},widenedFieldShape:{action:"changed",kind:"field → wider"}},ye=(t,e)=>{const i=`${U[t.type].action} ${e} `;return t.summary.startsWith(i)?t.summary.slice(i.length):t.summary},ke=t=>{const e=new Map;for(const n of t){const s=n.table??"",o=e.get(s);o===void 0?e.set(s,[n]):o.push(n)}const i=[...e].map(([n,s])=>({changes:s,table:n}));return[...i.filter(n=>n.table!==""),...i.filter(n=>n.table==="")]},$e=t=>{const e=q(2),{children:i}=t;let n;return e[0]!==i?(n=c("div",{className:"px-4 pt-4 pb-2 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:i}),e[0]=i,e[1]=n):n=e[1],n},we=({pane:t,shardKey:e=""})=>{const i=E(),n=B(),o=z({strict:!1}).version,a=l=>{ee(n({search:{version:l},to:"/migrations"}))},r=I(M.schemaHistory,{},{shardKey:e}),d=r.data?.versions??[],u=o!==void 0&&d.some(l=>l.hash===o)?o:d[0]?.hash,h=d.findIndex(l=>l.hash===u),f=h===-1?void 0:d[h+1]?.hash,g=I(M.schemaVersion,{hash:u??""},{enabled:u!==void 0,shardKey:e}),p=I(M.schemaVersion,{hash:f??""},{enabled:f!==void 0,shardKey:e}),m=T(()=>{const l=L(g.data?.version?.snapshotJson);if(l!==void 0)return pe(L(p.data?.version?.snapshotJson),l)},[g.data,p.data]),b=T(()=>(m?.tables??[]).map(l=>({columns:l.columns,name:l.name,tier:be(l.shardMode)})),[m]),x=T(()=>{const l={};for(const S of m?.tables??[])l[S.name]=ge[S.status];return l},[m]);if(r.error!==null)return c(X,{error:r.errorSource,testId:"sh-error"});if(d.length===0)return c(Y,{description:i("Each distinct schema shape this shard runs is recorded here, so you can see what changed and when."),testId:"sh-empty",title:i("No schema versions recorded yet.")});const k=m?.changes??[];return v("div",{className:"flex min-h-0 flex-1 gap-4","data-testid":"lunora-schema-history",children:[v("nav",{className:"flex w-56 shrink-0 flex-col overflow-hidden border-e border-border","data-testid":"sh-timeline-rail",children:[c($e,{children:i("Schema versions")}),c("ul",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-timeline",children:d.map(l=>c(ve,{appliedAt:l.appliedAt,hash:l.hash,onSelect:a,selected:l.hash===u,seq:l.seq},l.hash))})]}),v("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 pe-1 pt-4",children:[c(xe,{breaking:m?.breakingCount??0,count:f===void 0?b.length:k.length,first:f===void 0}),t==="diagram"?c("div",{className:"flex min-h-0 flex-1 flex-col",children:c(te,{fill:!0,nodeClasses:x,tables:b,testIdPrefix:"sh"})}):c("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-changes",children:ke(k).map(l=>{const S=(m?.tables??[]).find($=>$.name===l.table);return v("section",{className:"mb-6",children:[v("div",{className:"flex items-baseline gap-3 border-b border-border/60 pb-1.5",children:[c("span",{className:"font-mono text-[13px] text-foreground",children:l.table===""?i("schema"):l.table}),S!==void 0&&c("span",{className:"font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums uppercase",children:i("{count} columns",{count:S.columns.length})}),l.changes.length>1&&c("span",{className:"ms-auto font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums",children:l.changes.length})]}),c("ul",{children:l.changes.map($=>{const{action:G,kind:N}=U[$.type],C=$.severity==="breaking",D=ye($,N);return v("li",{className:"flex items-baseline gap-4 border-s-2 py-1.5 ps-3 transition-colors hover:bg-accent/30",children:[c("span",{"aria-hidden":"true",className:j("-ms-3 h-3 w-0.5 shrink-0 self-center",C?"bg-destructive":"bg-transparent")}),v("span",{className:"w-44 shrink-0 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:[i(G)," ",N]}),D!==l.table&&c("span",{className:j("min-w-0 font-mono text-[13px]",C?"text-destructive":"text-foreground"),children:D}),C&&c("span",{className:"ms-auto shrink-0 font-mono text-[10px] tracking-widest text-destructive uppercase",children:i("breaking")})]},`${$.type}-${$.summary}`)})})]},l.table)})})]})]})},Se=t=>j("-mb-px border-b-2 px-3 py-2.5 font-mono text-[11px] tracking-wider uppercase transition-colors outline-none","hover:bg-accent/40 focus-visible:bg-accent/40",t?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Je=t=>{const e=q(11),{initialShardKey:i}=t,n=E(),[s,o]=W("diagram");let a;e[0]!==s?(a=(f,g,p,m)=>v("button",{"aria-selected":s===f,className:Se(s===f),"data-testid":p,onClick:()=>{o(f)},role:"tab",type:"button",children:[g,m!==void 0&&c("span",{className:"ms-2 tabular-nums text-muted-foreground/70",children:m})]}),e[0]=s,e[1]=a):a=e[1];const r=a;let d;e[2]!==n||e[3]!==r?(d=v("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-3","data-testid":"mg-panes",role:"tablist",children:[r("diagram",n("Diagram"),"mg-pane-diagram"),r("changes",n("Changes"),"mg-pane-changes"),r("data",n("Data migrations"),"mg-pane-data")]}),e[2]=n,e[3]=r,e[4]=d):d=e[4];let u;e[5]!==i||e[6]!==s?(u=c("div",{className:"flex min-h-0 flex-1 flex-col",children:s==="data"?c("div",{className:"min-h-0 flex-1 overflow-y-auto px-4",children:c(_,{initialShardKey:i})}):c(we,{pane:s,shardKey:i})}),e[5]=i,e[6]=s,e[7]=u):u=e[7];let h;return e[8]!==d||e[9]!==u?(h=v("div",{className:"flex min-h-0 flex-1 flex-col pt-4","data-testid":"lunora-migrations-route",children:[d,u]}),e[8]=d,e[9]=u,e[10]=h):h=e[10],h};export{Je as default};
|
|
1
|
+
import{c as C}from"react/compiler-runtime";import{useMemo as I,useState as Z}from"react";import{useT as L}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as j}from"../packem_shared/utils-bhneXptQ.mjs";import{MigrationsPanel as N}from"../packem_shared/MigrationsPanel-BPWzFdxC.mjs";import{useNavigate as ee,useSearch as te}from"@tanstack/react-router";import{E as ie}from"../packem_shared/error-alert-tf5zvSLV.mjs";import{E as ne}from"../packem_shared/empty-state-D7jEML_T.mjs";import{u as R}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{ADMIN_FUNCTIONS as E}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as se,f as oe}from"../packem_shared/internal-B6haJbiP.mjs";import{S as ae}from"../packem_shared/schema-diagram-CDj_69jF.mjs";import{jsx as c,jsxs as y}from"react/jsx-runtime";const A=1;function re(t){const e={},i=Object.keys(t);i.sort();for(const n of i)e[n]=t[n];return e}const O=t=>typeof t=="object"&&t!==null,de=t=>O(t)&&O(t.fields)&&O(t.indexes)&&O(t.relations)&&typeof t.shardMode=="string",le=t=>{if(t===void 0||t.trim()==="")return{status:"absent"};let e;try{e=JSON.parse(t)}catch(n){return{error:`baseline is not valid JSON: ${n instanceof Error?n.message:String(n)}`,status:"invalid"}}if(!O(e)||e.version!==A||!O(e.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(A)})`,status:"invalid"};for(const[n,s]of Object.entries(e.tables))if(!de(s))return{error:`baseline table "${n}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof e.jurisdiction=="string"?e.jurisdiction:void 0,migrationIds:Array.isArray(e.migrationIds)?e.migrationIds:[],tables:e.tables,version:A},status:"ok"}},ce=(t,e)=>t.unique===e.unique&&t.fields.length===e.fields.length&&t.fields.every((i,n)=>i===e.fields[n]),J=t=>t.unique!==void 0,D=({nullable:t,optional:e,refined:i,unique:n,...s})=>JSON.stringify(re(s)),H=t=>({form:JSON.stringify([D(t),t.optional===!0,t.nullable===!0]),refined:t.refined===!0}),V=t=>t.kind==="union"&&t.members?t.members.map(e=>H(e)):[H({...t,nullable:!1,optional:!1})],me=(t,e)=>{if(e.kind!=="union")return!1;const i=V(e);return V(t).every(n=>i.some(s=>s.form===n.form&&(n.refined||!s.refined)))},x=t=>{switch(t.kind){case"array":return`array(${t.of?x(t.of):"?"})`;case"id":return`id(${t.ref??"?"})`;case"literal":return`literal(${t.literal??"?"})`;case"object":return`object({ ${Object.keys(t.fields??{}).join(", ")} })`;case"record":return`record(${t.key?x(t.key):"?"}, ${t.of?x(t.of):"?"})`;case"union":return(t.members??[]).map(e=>x(e)).join(" | ");default:return t.kind}},T=(t,e,i)=>({remediation:"backfill",scope:"table",severity:"breaking",summary:i,table:t,type:e}),q=(t,e,i)=>({remediation:"none",scope:"table",severity:"safe",summary:i,table:t,type:e}),he=(t,e,i,n,s)=>{if(!(i.kind===n.kind&&(!s||D(i)===D(n))))return s&&me(i,n)?q(t,"widenedFieldShape",`field ${t}.${e} widened: ${x(i)} → ${x(n)} — every stored value stays valid`):i.kind!==n.kind?T(t,"changedFieldKind",`field ${t}.${e} changed type: ${i.kind} → ${n.kind} — add a data migration to convert existing values`):T(t,"changedFieldShape",`field ${t}.${e} changed shape: ${x(i)} → ${x(n)} — stored values were written against the old shape; add a data migration to convert them`)},fe=(t,e,i,n)=>{const s=[];return i.unique!==n.unique&&s.push(n.unique===!0?T(t,"addedFieldConstraint",`field ${t}.${e} became unique — existing duplicates would violate it; add a data migration to de-duplicate first`):q(t,"relaxedFieldConstraint",`field ${t}.${e} is no longer unique`)),i.nullable!==n.nullable&&s.push(n.nullable===!0?q(t,"relaxedFieldConstraint",`field ${t}.${e} became nullable`):T(t,"addedFieldConstraint",`field ${t}.${e} is no longer nullable — rows holding NULL would be invalid; add a data migration to backfill them`)),i.refined!==n.refined&&s.push(n.refined===!0?T(t,"addedFieldConstraint",`field ${t}.${e} gained a validation refinement — stored values were never checked against it; add a data migration if any could fail`):q(t,"relaxedFieldConstraint",`field ${t}.${e} dropped its validation refinement`)),s},Y=(t,e,i,n)=>{const s=[],a=J(i)&&J(n),o=he(t,e,i,n,a);return o&&s.push(o),a&&s.push(...fe(t,e,i,n)),i.optional&&!n.optional?s.push({remediation:"backfill",severity:"breaking",summary:`field ${t}.${e} became required — rows missing it would be invalid; add a data migration to backfill it`,table:t,scope:"table",type:"fieldOptionalToRequired"}):!i.optional&&n.optional&&s.push({remediation:"none",scope:"table",severity:"safe",summary:`field ${t}.${e} became optional`,table:t,type:"fieldRequiredToOptional"}),s},ue=(t,e,i)=>i.optional?{remediation:"none",scope:"table",severity:"safe",summary:`added optional field ${t}.${e}`,table:t,type:"addedOptionalField"}:{remediation:"backfill",severity:"breaking",summary:`added required field ${t}.${e} — existing rows have no value; add a data migration to backfill it`,table:t,scope:"table",type:"addedRequiredField"},pe=(t,e,i,n)=>{for(const[s,a]of Object.entries(i.fields)){const o=e.fields[s];o===void 0?n.push(ue(t,s,a)):n.push(...Y(t,s,o,a))}for(const s of Object.keys(e.fields))i.fields[s]===void 0&&n.push({remediation:"backfill",severity:"breaking",summary:`removed field ${t}.${s} — add a data migration if stored data must be cleaned up`,table:t,scope:"table",type:"removedField"})},ge=(t,e,i,n)=>{for(const[s,a]of Object.entries(i.indexes)){const o=e.indexes[s];if(o===void 0){n.push(a.unique?{remediation:"backfill",scope:"table",severity:"breaking",summary:`added unique index ${s} on ${t} — existing duplicates would violate it; add a data migration to de-duplicate first`,table:t,type:"addedIndex"}:{remediation:"none",scope:"table",severity:"safe",summary:`added index ${s} on ${t}`,table:t,type:"addedIndex"});continue}ce(o,a)||n.push({remediation:"code",severity:"breaking",summary:`index ${s} on ${t} changed shape — a query may have relied on the old index`,table:t,scope:"table",type:"changedIndex"})}for(const s of Object.keys(e.indexes))i.indexes[s]===void 0&&n.push({remediation:"code",severity:"breaking",summary:`removed index ${s} on ${t} — a query that used \`.withIndex("${s}")\` would break`,table:t,scope:"table",type:"removedIndex"})},be=(t,e,i,n)=>{for(const s of Object.keys(i.relations))e.relations[s]===void 0&&n.push({remediation:"none",scope:"schema",severity:"safe",summary:`added relation ${t}.${s}`,table:t,type:"addedRelation"});for(const s of Object.keys(e.relations))i.relations[s]===void 0&&n.push({remediation:"code",scope:"schema",severity:"breaking",summary:`removed relation ${t}.${s}`,table:t,type:"removedRelation"})},G="shardBy:_unknown_",F="global",ye=(t,e)=>t===F&&e.startsWith(`${F}:`)||e===F&&t.startsWith(`${F}:`),ve=(t,e,i)=>{if(e===i)return i!==G?void 0:{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${t} declares a non-literal .shardBy(...) key, so codegen cannot read which column partitions it — every such key records as "${G}" and two DIFFERENT keys would compare equal. Pass the shard key as a string literal; until then this is reported on every run, because the alternative is a silent pass on a re-home that strands every row (export/import is the only way back).`,table:t,type:"changedShardMode"};if(!ye(e,i))return{remediation:"rehome",severity:"breaking",summary:`table ${t} changed shard mode: ${e} → ${i} — its physical storage moves, and existing rows do NOT follow the schema; re-home them with an export/import round trip (https://lunora.sh/docs/concepts/sharding#migrating-a-populated-table)`,table:t,scope:"table",type:"changedShardMode"}},Q=t=>t.memory!==void 0,W=t=>t.after??0,w=t=>t.after===void 0?`.ttl("${t.field}")`:`.ttl("${t.field}", { after: ${String(t.after)} })`,xe=(t,e,i)=>{if(e===void 0&&i===void 0)return;const n=r=>({remediation:"backfill",scope:"table",severity:"breaking",summary:r,table:t,type:"changedTtlPolicy"}),s=r=>({remediation:"none",scope:"table",severity:"safe",summary:r,table:t,type:"changedTtlPolicy"});if(i===void 0)return s(`table ${t} dropped its TTL policy — its rows are no longer swept`);if(e===void 0)return n(`table ${t} gained a TTL policy ${w(i)} — every row already past the cutoff is deleted on the next alarm sweep; add a data migration to refresh or clear "${i.field}" on the rows written before it`);if(e.field!==i.field)return n(`table ${t} moved its TTL to a different column: ${w(e)} → ${w(i)} — rows are now expired by a column they were never written against; add a data migration to populate "${i.field}"`);const a=W(e),o=W(i);return o<a?n(`table ${t} shortened its TTL: ${w(e)} → ${w(i)} — rows that were not expired under the old offset are deleted on the next alarm sweep; add a data migration to refresh "${i.field}" on the rows that must survive`):o>a?s(`table ${t} lengthened its TTL: ${w(e)} → ${w(i)}`):void 0},ke=(t,e,i)=>{const n=[];return e.memory!==i.memory&&n.push(i.memory===!0?{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${t} became a .memory() table — every row is deleted in every shard on the next Durable Object cold start, and no data migration survives that; export the rows first if they must be kept, or revert`,table:t,type:"changedMemoryMode"}:{remediation:"none",scope:"table",severity:"safe",summary:`table ${t} is no longer a .memory() table — its rows now survive a cold start`,table:t,type:"changedMemoryMode"}),e.commitOrdered!==i.commitOrdered&&n.push(i.commitOrdered===!0?{remediation:"backfill",scope:"table",severity:"breaking",summary:`table ${t} became .commitOrdered() — rows written before it carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed never offers them; add a data migration over the table to stamp them (the rewrite allocates a sequence)`,table:t,type:"changedCommitOrdering"}:{remediation:"code",scope:"table",severity:"breaking",summary:`table ${t} is no longer .commitOrdered() — new rows carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed stops advancing without erroring; update the consumers before deploying`,table:t,type:"changedCommitOrdering"}),n},$e=(t,e,i,n)=>{const s=ve(t,e.shardMode,i.shardMode);if(s&&n.push(s),Q(e)&&Q(i)){n.push(...ke(t,e,i));const a=xe(t,e.ttl,i.ttl);a&&n.push(a)}pe(t,e,i,n),ge(t,e,i,n),be(t,e,i,n)},we=(t,e)=>{const i=[],n=t?.tables??{};for(const[s,a]of Object.entries(e.tables)){const o=n[s];if(o===void 0){i.push({remediation:"none",scope:"table",severity:"safe",summary:`added table ${s}`,table:s,type:"addedTable"});continue}$e(s,o,a,i)}for(const s of Object.keys(n))e.tables[s]===void 0&&i.push({remediation:"rehome",scope:"table",severity:"breaking",summary:`removed table ${s} — its rows stay in each shard's SQLite, unreachable through the schema; export the shard first if the data must be kept`,table:s,type:"removedTable"});if(t!==void 0&&t.jurisdiction!==e.jurisdiction){const s=t.jurisdiction??"(none)",a=e.jurisdiction??"(none)";i.push({remediation:"rehome",scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${s} to ${a} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,type:"changedJurisdiction"})}return{changes:i}},B=t=>Object.entries(t.fields).map(([e,i])=>({name:e,optional:i.optional,ref:Object.values(t.relations).find(n=>n.field===e&&n.kind==="one")?.table,type:x(i)})),U=(t,e,i)=>{const n={},s=e?.fields??{},a=i?.fields??{};for(const[o,r]of Object.entries(a)){const d=s[o];d===void 0?n[o]=e===void 0?"unchanged":"added":n[o]=Y(t,o,d,r).length===0?"unchanged":"changed"}for(const o of Object.keys(s))a[o]===void 0&&(n[o]="removed");return n},Oe=(t,e)=>{const{changes:i}=we(t,e),n=new Set(i.filter(o=>o.scope==="table"&&o.table!==void 0).map(o=>o.table)),s=[],a=(o,r)=>o?"added":n.has(r)?"changed":"context";for(const[o,r]of Object.entries(e.tables)){const d=t?.tables[o],m=a(d===void 0,o);s.push({columns:B(r),fieldStatus:U(o,d,r),name:o,shardMode:r.shardMode,status:m})}for(const[o,r]of Object.entries(t?.tables??{}))e.tables[o]===void 0&&s.push({columns:B(r),fieldStatus:U(o,r,void 0),name:o,shardMode:r.shardMode,status:"removed"});return s.sort((o,r)=>o.name.localeCompare(r.name)),{breakingCount:i.filter(o=>o.severity==="breaking").length,changes:i,tables:s}},K=t=>{const e=le(t);return e.status==="ok"?e.snapshot:void 0},Se={added:"ring-2 ring-emerald-500/60",changed:"ring-2 ring-amber-500/70",context:"opacity-55",removed:"opacity-70 ring-2 ring-destructive/60"},Te=t=>t==="global"||t.startsWith("global:")?"global":"shard",je=t=>{const e=C(24),{appliedAt:i,hash:n,onSelect:s,selected:a,seq:o}=t,r=a?"border-s-primary bg-accent/60 text-foreground":"border-s-transparent text-muted-foreground hover:bg-accent/30 hover:text-foreground";let d;e[0]!==r?(d=j("flex w-full flex-col items-start gap-1 border-s-2 px-4 py-3 text-start outline-none transition-colors",r),e[0]=r,e[1]=d):d=e[1];const m=`sh-version-${n}`;let u;e[2]!==n||e[3]!==s?(u=()=>{s(n)},e[2]=n,e[3]=s,e[4]=u):u=e[4];let f;e[5]!==o?(f=y("span",{className:"font-mono text-[13px] tabular-nums",children:["v",o]}),e[5]=o,e[6]=f):f=e[6];let g;e[7]!==n?(g=n.slice(0,7),e[7]=n,e[8]=g):g=e[8];let p;e[9]!==g?(p=c("span",{className:"ms-auto font-mono text-[10px] tracking-wider text-muted-foreground/70 uppercase",children:g}),e[9]=g,e[10]=p):p=e[10];let h;e[11]!==f||e[12]!==p?(h=y("span",{className:"flex w-full items-baseline gap-2",children:[f,p]}),e[11]=f,e[12]=p,e[13]=h):h=e[13];let b;e[14]!==i?(b=se(i),e[14]=i,e[15]=b):b=e[15];let v;e[16]!==b?(v=c("span",{className:"font-mono text-[10px] tracking-wide text-muted-foreground/70",children:b}),e[16]=b,e[17]=v):v=e[17];let k;return e[18]!==v||e[19]!==d||e[20]!==m||e[21]!==u||e[22]!==h?(k=c("li",{children:y("button",{className:d,"data-testid":m,onClick:u,type:"button",children:[h,v]})}),e[18]=v,e[19]=d,e[20]=m,e[21]=u,e[22]=h,e[23]=k):k=e[23],k},Fe=t=>{const e=C(26),{breaking:i,count:n,first:s}=t,a=L();if(s){let p;e[0]!==n?(p=c("span",{className:"text-3xl leading-none font-light tracking-tight tabular-nums",children:n}),e[0]=n,e[1]=p):p=e[1];let h;e[2]!==a?(h=a("tables"),e[2]=a,e[3]=h):h=e[3];let b;e[4]!==h?(b=c("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:h}),e[4]=h,e[5]=b):b=e[5];let v;return e[6]!==p||e[7]!==b?(v=y("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[p,b]}),e[6]=p,e[7]=b,e[8]=v):v=e[8],v}const o=i>0&&"text-destructive";let r;e[9]!==o?(r=j("text-3xl leading-none font-light tracking-tight tabular-nums",o),e[9]=o,e[10]=r):r=e[10];let d;e[11]!==n||e[12]!==r?(d=c("span",{className:r,children:n}),e[11]=n,e[12]=r,e[13]=d):d=e[13];let m;e[14]!==n||e[15]!==a?(m=a(n===1?"change":"changes"),e[14]=n,e[15]=a,e[16]=m):m=e[16];let u;e[17]!==m?(u=c("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:m}),e[17]=m,e[18]=u):u=e[18];let f;e[19]!==i||e[20]!==a?(f=i>0&&y("span",{className:"font-mono text-[11px] tracking-widest text-destructive uppercase",children:["· ",a("{count} breaking",{count:i})]}),e[19]=i,e[20]=a,e[21]=f):f=e[21];let g;return e[22]!==d||e[23]!==u||e[24]!==f?(g=y("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[d,u,f]}),e[22]=d,e[23]=u,e[24]=f,e[25]=g):g=e[25],g},z={addedFieldConstraint:{action:"added",kind:"constraint"},addedIndex:{action:"added",kind:"index"},addedOptionalField:{action:"added",kind:"field?"},addedRelation:{action:"added",kind:"relation"},addedRequiredField:{action:"added",kind:"field"},addedTable:{action:"added",kind:"table"},changedCommitOrdering:{action:"changed",kind:"commit ordering"},changedFieldKind:{action:"changed",kind:"field kind"},changedFieldShape:{action:"changed",kind:"field shape"},changedIndex:{action:"changed",kind:"index"},changedJurisdiction:{action:"changed",kind:"jurisdiction"},changedMemoryMode:{action:"changed",kind:"memory mode"},changedShardMode:{action:"changed",kind:"shard mode"},changedTtlPolicy:{action:"changed",kind:"TTL policy"},fieldOptionalToRequired:{action:"changed",kind:"field → required"},fieldRequiredToOptional:{action:"changed",kind:"field → optional"},relaxedFieldConstraint:{action:"removed",kind:"constraint"},removedField:{action:"removed",kind:"field"},removedIndex:{action:"removed",kind:"index"},removedRelation:{action:"removed",kind:"relation"},removedTable:{action:"removed",kind:"table"},widenedFieldShape:{action:"changed",kind:"field → wider"}},qe=(t,e)=>{const i=`${z[t.type].action} ${e} `;return t.summary.startsWith(i)?t.summary.slice(i.length):t.summary},Ce=t=>{const e=new Map;for(const n of t){const s=n.table??"",a=e.get(s);a===void 0?e.set(s,[n]):a.push(n)}const i=[...e].map(([n,s])=>({changes:s,table:n}));return[...i.filter(n=>n.table!==""),...i.filter(n=>n.table==="")]},Me=t=>{const e=C(2),{children:i}=t;let n;return e[0]!==i?(n=c("div",{className:"px-4 pt-4 pb-2 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:i}),e[0]=i,e[1]=n):n=e[1],n},Ie=({pane:t,shardKey:e=""})=>{const i=L(),n=ee(),a=te({strict:!1}).version,o=l=>{oe(n({search:{version:l},to:"/migrations"}))},r=R(E.schemaHistory,{},{shardKey:e}),d=r.data?.versions??[],m=a!==void 0&&d.some(l=>l.hash===a)?a:d[0]?.hash,u=d.findIndex(l=>l.hash===m),f=u===-1?void 0:d[u+1]?.hash,g=R(E.schemaVersion,{hash:m??""},{enabled:m!==void 0,shardKey:e}),p=R(E.schemaVersion,{hash:f??""},{enabled:f!==void 0,shardKey:e}),h=I(()=>{const l=K(g.data?.version?.snapshotJson);if(l!==void 0)return Oe(K(p.data?.version?.snapshotJson),l)},[g.data,p.data]),b=I(()=>(h?.tables??[]).map(l=>({columns:l.columns,name:l.name,tier:Te(l.shardMode)})),[h]),v=I(()=>{const l={};for(const S of h?.tables??[])l[S.name]=Se[S.status];return l},[h]);if(r.error!==null)return c(ie,{error:r.errorSource,testId:"sh-error"});if(d.length===0)return c(ne,{description:i("Each distinct schema shape this shard runs is recorded here, so you can see what changed and when."),testId:"sh-empty",title:i("No schema versions recorded yet.")});const k=h?.changes??[];return y("div",{className:"flex min-h-0 flex-1 gap-4","data-testid":"lunora-schema-history",children:[y("nav",{className:"flex w-56 shrink-0 flex-col overflow-hidden border-e border-border","data-testid":"sh-timeline-rail",children:[c(Me,{children:i("Schema versions")}),c("ul",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-timeline",children:d.map(l=>c(je,{appliedAt:l.appliedAt,hash:l.hash,onSelect:o,selected:l.hash===m,seq:l.seq},l.hash))})]}),y("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 pe-1 pt-4",children:[c(Fe,{breaking:h?.breakingCount??0,count:f===void 0?b.length:k.length,first:f===void 0}),t==="diagram"?c("div",{className:"flex min-h-0 flex-1 flex-col",children:c(ae,{fill:!0,nodeClasses:v,tables:b,testIdPrefix:"sh"})}):c("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-changes",children:Ce(k).map(l=>{const S=(h?.tables??[]).find($=>$.name===l.table);return y("section",{className:"mb-6",children:[y("div",{className:"flex items-baseline gap-3 border-b border-border/60 pb-1.5",children:[c("span",{className:"font-mono text-[13px] text-foreground",children:l.table===""?i("schema"):l.table}),S!==void 0&&c("span",{className:"font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums uppercase",children:i("{count} columns",{count:S.columns.length})}),l.changes.length>1&&c("span",{className:"ms-auto font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums",children:l.changes.length})]}),c("ul",{children:l.changes.map($=>{const{action:X,kind:P}=z[$.type],M=$.severity==="breaking",_=qe($,P);return y("li",{className:"flex items-baseline gap-4 border-s-2 py-1.5 ps-3 transition-colors hover:bg-accent/30",children:[c("span",{"aria-hidden":"true",className:j("-ms-3 h-3 w-0.5 shrink-0 self-center",M?"bg-destructive":"bg-transparent")}),y("span",{className:"w-44 shrink-0 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:[i(X)," ",P]}),_!==l.table&&c("span",{className:j("min-w-0 font-mono text-[13px]",M?"text-destructive":"text-foreground"),children:_}),M&&c("span",{className:"ms-auto shrink-0 font-mono text-[10px] tracking-widest text-destructive uppercase",children:i("breaking")})]},`${$.type}-${$.summary}`)})})]},l.table)})})]})]})},Re=t=>j("-mb-px border-b-2 px-3 py-2.5 font-mono text-[11px] tracking-wider uppercase transition-colors outline-none","hover:bg-accent/40 focus-visible:bg-accent/40",t?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Ue=t=>{const e=C(11),{initialShardKey:i}=t,n=L(),[s,a]=Z("diagram");let o;e[0]!==s?(o=(f,g,p,h)=>y("button",{"aria-selected":s===f,className:Re(s===f),"data-testid":p,onClick:()=>{a(f)},role:"tab",type:"button",children:[g,h!==void 0&&c("span",{className:"ms-2 tabular-nums text-muted-foreground/70",children:h})]}),e[0]=s,e[1]=o):o=e[1];const r=o;let d;e[2]!==n||e[3]!==r?(d=y("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-3","data-testid":"mg-panes",role:"tablist",children:[r("diagram",n("Diagram"),"mg-pane-diagram"),r("changes",n("Changes"),"mg-pane-changes"),r("data",n("Data migrations"),"mg-pane-data")]}),e[2]=n,e[3]=r,e[4]=d):d=e[4];let m;e[5]!==i||e[6]!==s?(m=c("div",{className:"flex min-h-0 flex-1 flex-col",children:s==="data"?c("div",{className:"min-h-0 flex-1 overflow-y-auto px-4",children:c(N,{initialShardKey:i})}):c(Ie,{pane:s,shardKey:i})}),e[5]=i,e[6]=s,e[7]=m):m=e[7];let u;return e[8]!==d||e[9]!==m?(u=y("div",{className:"flex min-h-0 flex-1 flex-col pt-4","data-testid":"lunora-migrations-route",children:[d,m]}),e[8]=d,e[9]=m,e[10]=u):u=e[10],u};export{Ue as default};
|