@theobourgeois/ytdb 0.2.7 → 0.2.8
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/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +2 -2
- package/.next/server/app/[connectionId]/[schema]/[table]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/[connectionId]/diff/page_client-reference-manifest.js +1 -1
- package/.next/server/app/[connectionId]/migrations/page.js +1 -1
- package/.next/server/app/[connectionId]/migrations/page_client-reference-manifest.js +1 -1
- package/.next/server/app/[connectionId]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/[connectionId]/query/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +2 -2
- package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/static/chunks/app/[connectionId]/migrations/page-a5b61ff9ef6a087b.js +1 -0
- package/.next/static/css/{01dd602f244d6cdd.css → c36a068647b766f7.css} +1 -1
- package/README.md +5 -2
- package/package.json +1 -1
- package/.next/static/chunks/app/[connectionId]/migrations/page-38c4a8b544c5feb1.js +0 -1
- /package/.next/static/{9W2YYPI40LU71rn2JeMpC → FSwOIUlobain5tMrHGgSI}/_buildManifest.js +0 -0
- /package/.next/static/{9W2YYPI40LU71rn2JeMpC → FSwOIUlobain5tMrHGgSI}/_ssgManifest.js +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[820],{2125:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},6059:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("git-compare",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]])},18986:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]])},33807:(e,t,n)=>{"use strict";n.d(t,{J:()=>a});var r=n(95155);n(12115);var s=n(40980);function a({className:e,...t}){return(0,r.jsx)("label",{"data-slot":"label",className:(0,s.cn)("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",e),...t})}},34263:(e,t,n)=>{"use strict";n.d(t,{En:()=>p,Pc:()=>d,fx:()=>c,jl:()=>o});var r=n(1934),s=n(31692),a=n(40980),i=n(63307);let l="ytdb:queries";(0,i.q)("db-studio:queries",l);let o=144,d=800,c=80;function u(e){return e.trim().replace(/\s+/g," ").slice(0,c)}let p=(0,r.v)()((0,s.Zr)((e,t)=>({drafts:{},editorHeight:224,history:[],folders:[],saved:[],activeSaved:{},setDraft:(t,n)=>e(e=>({drafts:{...e.drafts,[t]:n}})),setEditorHeight:t=>e({editorHeight:Math.min(d,Math.max(o,Math.round(t)))}),record:(t,n)=>e(e=>{let r=n.trim();if(!r)return e;let s=e.history.find(e=>e.connectionId===t&&e.sql===r),i={id:s?.id??(0,a.z)(),connectionId:t,sql:r,executedAt:Date.now()},l=0,o=0;return{history:[i,...e.history.filter(e=>e.id!==i.id)].filter(e=>!(l>=200)&&!(o+e.sql.length>1e6)&&(l+=1,o+=e.sql.length,!0))}}),remove:t=>e(e=>({history:e.history.filter(e=>e.id!==t)})),createFolder:(t,n)=>{let r=(0,a.z)(),s=u(n)||"Untitled folder";return e(e=>({folders:[...e.folders,{id:r,connectionId:t,name:s,collapsed:!1,createdAt:Date.now()}]})),r},renameFolder:(t,n)=>{let r=u(n);r&&e(e=>({folders:e.folders.map(e=>e.id===t?{...e,name:r}:e)}))},toggleFolder:t=>e(e=>({folders:e.folders.map(e=>e.id===t?{...e,collapsed:!e.collapsed}:e)})),removeFolder:t=>e(e=>({folders:e.folders.filter(e=>e.id!==t),saved:e.saved.map(e=>e.folderId===t?{...e,folderId:null}:e)})),saveQuery:(t,n)=>{let r=(0,a.z)(),s=Date.now();return e(e=>({saved:[...e.saved,{id:r,connectionId:t,folderId:n.folderId,name:u(n.name)||"Untitled query",sql:n.sql,createdAt:s,updatedAt:s}],activeSaved:{...e.activeSaved,[t]:r}})),r},updateSaved:(t,n)=>e(e=>({saved:e.saved.map(e=>{if(e.id!==t)return e;let r=void 0===n.name?e.name:u(n.name)||e.name;return{...e,name:r,sql:n.sql??e.sql,folderId:void 0===n.folderId?e.folderId:n.folderId,updatedAt:void 0!==n.sql&&n.sql!==e.sql?Date.now():e.updatedAt}})})),removeSaved:t=>e(e=>({saved:e.saved.filter(e=>e.id!==t),activeSaved:function(e,t){let n={...e};for(let[e,r]of Object.entries(n))t.has(r)&&delete n[e];return n}(e.activeSaved,new Set([t]))})),setActiveSaved:(n,r)=>{let{activeSaved:s}=t();(s[n]??null)!==r&&e(e=>{let t={...e.activeSaved};return null===r?delete t[n]:t[n]=r,{activeSaved:t}})}}),{name:l}))},35942:(e,t,n)=>{"use strict";n.d(t,{F:()=>c});var r=n(95155);n(12115);var s=n(76166),a=n(13220),i=n(84588),l=n(66784),o=n(64084),d=n(40980);function c({className:e,children:t,...n}){return(0,r.jsxs)(s.V,{"data-slot":"scroll-area",className:(0,d.cn)("relative",e),...n,children:[(0,r.jsx)(a.B,{"data-slot":"scroll-area-viewport",className:"size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1",children:t}),(0,r.jsx)(u,{}),(0,r.jsx)(i.I,{})]})}function u({className:e,orientation:t="vertical",...n}){return(0,r.jsx)(l.V,{"data-slot":"scroll-area-scrollbar","data-orientation":t,orientation:t,className:(0,d.cn)("flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent",e),...n,children:(0,r.jsx)(o.l,{"data-slot":"scroll-area-thumb",className:"relative flex-1 rounded-full bg-border"})})}},36565:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]])},36619:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("play",[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]])},59680:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]])},68376:(e,t,n)=>{Promise.resolve().then(n.bind(n,80292))},72194:(e,t,n)=>{"use strict";n.d(t,{F:()=>i});var r=n(95155),s=n(40980),a=n(32538);function i({connection:e,className:t}){return(0,r.jsx)("span",{"aria-hidden":!0,className:(0,s.cn)("size-2.5 shrink-0 rounded-full",t),style:{background:(0,a.Mq)(e)}})}},72278:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("layers-2",[["path",{d:"M13 13.74a2 2 0 0 1-2 0L2.5 8.87a1 1 0 0 1 0-1.74L11 2.26a2 2 0 0 1 2 0l8.5 4.87a1 1 0 0 1 0 1.74z",key:"15q6uc"}],["path",{d:"m20 14.285 1.5.845a1 1 0 0 1 0 1.74L13 21.74a2 2 0 0 1-2 0l-8.5-4.87a1 1 0 0 1 0-1.74l1.5-.845",key:"byia6g"}]])},80292:(e,t,n)=>{"use strict";n.d(t,{MigrationsView:()=>eP});var r=n(95155),s=n(98500),a=n.n(s),i=n(73321),l=n(12115),o=n(82749),d=n(99537);let c=(0,d.A)("folder-up",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}],["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"m9 13 3-3 3 3",key:"1pxg3c"}]]);var u=n(59680);let p=(0,d.A)("clipboard-check",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"m9 14 2 2 4-4",key:"df797q"}]]),m=(0,d.A)("undo",[["path",{d:"M3 7v6h6",key:"1v2h90"}],["path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13",key:"1r6uu6"}]]),h=(0,d.A)("table",[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]]);var x=n(36619),f=n(72278),g=n(65342),v=n(2125),y=n(18986);let j=(0,d.A)("triangle-alert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);var k=n(36331),b=n(89239),N=n(72264),w=n(30374),$=n(35942),A=n(87364),S=n(27529),C=n(40980);let M=/^[ \t]*--+[ \t]*ytdb:[ \t]*no-?transaction\b/im,z=new Set(["begin","start"]),q=new Set(["commit","end"]),R=new Set(["rollback"]);function I(e){return void 0!==e&&(e>="A"&&e<="Z"||e>="a"&&e<="z"||"_"===e)||void 0!==e&&e>="0"&&e<="9"}function D(e){if(M.test(e))return{mode:"unwrapped",sql:e,atomic:!1};let t=function(e){let t=[],n=0,r=0,s=r=>{let s=function(e,t){let n=t;for(;n<e.length;){let t=e[n];if(" "===t||" "===t||"\n"===t||"\r"===t){n+=1;continue}if("-"===t&&"-"===e[n+1]){for(;n<e.length&&"\n"!==e[n];)n+=1;continue}if("/"===t&&"*"===e[n+1]){let t=e.indexOf("*/",n+2);n=-1===t?e.length:t+2;continue}break}return n}(e,n);if(s>=r)return;let a=s;for(;a<e.length&&I(e[a]);)a+=1;t.push({at:s,end:r,keyword:e.slice(s,a).toLowerCase()})};for(;r<e.length;){let t=e[r];if("-"===t&&"-"===e[r+1]){for(;r<e.length&&"\n"!==e[r];)r+=1;continue}if("/"===t&&"*"===e[r+1]){let t=e.indexOf("*/",r+2);r=-1===t?e.length:t+2;continue}if("'"===t||'"'===t){r=function(e,t,n){let r=t+1;for(;r<e.length;){if(e[r]===n){if(e[r+1]===n){r+=2;continue}return r+1}r+=1}return r}(e,r,t);continue}if("$"===t){let t=function(e,t){if("$"!==e[t])return null;let n=t+1;for(;n<e.length&&I(e[n]);)n+=1;return"$"!==e[n]?null:e.slice(t,n+1)}(e,r);if(t){let n=e.indexOf(t,r+t.length);r=-1===n?e.length:n+t.length;continue}}if(";"===t){s(r+1),r+=1,n=r;continue}r+=1}return s(e.length),t}(e),n=t.filter(e=>z.has(e.keyword)||q.has(e.keyword)||R.has(e.keyword));if(0===n.length)return{mode:"wrapped-by-ytdb",sql:e,atomic:!0};let r=t[0],s=t[t.length-1];return 2===n.length&&n[0]===r&&n[1]===s&&z.has(r.keyword)&&q.has(s.keyword)?{mode:"self-wrapped",sql:e.slice(0,r.at)+e.slice(r.end,s.at)+e.slice(s.end),atomic:!0}:{mode:"self-managed",sql:e,atomic:!1}}let L=new Set(["apply","up","forward"]),_=new Set(["revert","down","rollback","undo"]),F=[".up",".apply",".forward"],O=[".down",".revert",".rollback",".undo"];function T(e){return e.split("/").filter(e=>e.length>0)}function B(e){return e.replace(/[-_]+/g," ").trim()}function E(e,t){let n=/(\d+)|(\D+)/g,r=e.match(n)??[],s=t.match(n)??[],a=Math.min(r.length,s.length);for(let e=0;e<a;e+=1){let t=r[e],n=s[e],a=/^\d+$/.test(t)&&/^\d+$/.test(n)?Number(t)-Number(n):t.localeCompare(n);if(0!==a)return a}return r.length-s.length}function P(e){let t=e.replace(/\r\n/g,"\n").trim(),n=0x811c9dc5,r=0x1000193;for(let e=0;e<t.length;e+=1){let s=t.charCodeAt(e);n=Math.imul(n^s,0x1000193)>>>0,r=Math.imul(r+s,0x85ebca6b)>>>0}return`${n.toString(16).padStart(8,"0")}${r.toString(16).padStart(8,"0")}`}function H(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}let Q={steps:[],blockedBy:null};function V(e){let t=new Map;for(let n of e?.entries??[])t.set(n.version,n);return t}function U(e,t){return t?t.entries.find(t=>t.version===e.version)??null:null}function Z(e,t){if(!t)return"unknown";let n=U(e,t);return n?n.checksum&&n.checksum!==e.checksum?"drifted":"applied":"pending"}function W(e,t){let n={total:e?.steps.length??0,applied:0,drifted:0,pending:0,foreign:0};if(!e)return n;for(let r of e.steps){let e=Z(r,t);"applied"===e?n.applied+=1:"drifted"===e?n.drifted+=1:"pending"===e&&(n.pending+=1)}return n.foreign=Y(e,t).length,n}function Y(e,t){if(!t)return[];let n=new Set((e?.steps??[]).map(e=>e.version));return t.entries.filter(e=>!n.has(e.version)).sort((e,t)=>E(e.version,t.version))}function G(e,t,n){if(!e||!t)return Q;let r=[];for(let s of e.steps)if("pending"===Z(s,t)&&r.push(s),void 0!==n&&s.version===n)break;return{steps:r,blockedBy:null}}function J(e,t,n){if(!e||!t)return Q;let r=V(t),s=[];for(let t of[...e.steps].reverse()){if(void 0!==n&&0>E(t.version,n))break;if(r.has(t.version)){if(!t.revertSql)return{steps:s,blockedBy:t};s.push(t)}}return{steps:s,blockedBy:null}}let K="maintenance",X="ytdb_migrations";function ee(e){return"string"==typeof e&&e.length>0&&e.length<=63&&/^[A-Za-z_][A-Za-z0-9_$]*$/.test(e)}var et=n(74590),en=n(1934),er=n(31692),es=n(42256);let ea=(0,en.v)()((0,er.Zr)((e,t)=>({sets:[],activeSet:{},history:[],ledgerSchema:K,setLedgerSchema:t=>{ee(t)&&e({ledgerSchema:t})},createSet:t=>{let n={id:(0,C.z)(),name:t.trim().replace(/\s+/g," ").slice(0,80)||"Migrations",importedAt:Date.now(),steps:[],skipped:[]};return e(e=>({sets:[...e.sets,n]})),n.id},addFiles:(n,r)=>{let s=t().sets.find(e=>e.id===n),a=function(e){let t={applies:new Map,reverts:new Map,skipped:[],errors:[]},n=e.filter(e=>{var t;let n=T(t=e.path).at(-1)??t;return!n.startsWith(".")&&/\.sql$/i.test(n)});if(0===n.length)return t.errors.push("No .sql files in there."),t;let r=n.reduce((e,t)=>e+t.text.length,0);if(r>4e6)return t.errors.push(`That is ${H(r)} of SQL, over the ${H(4e6)} limit.`),t;for(let e of n){if(e.text.length>5e5){t.skipped.push(`${e.path} — over ${H(5e5)}`);continue}if(e.text.includes("\0")){t.skipped.push(`${e.path} — not text`);continue}if(!e.text.trim()){t.skipped.push(`${e.path} — empty`);continue}let{direction:n,stem:r}=function(e){let t=T(e),n=(t.at(-1)??e).replace(/\.sql$/i,"");for(let e of t.slice(0,-1)){let t=e.toLowerCase();if(_.has(t))return{direction:"revert",stem:n};if(L.has(t))return{direction:"apply",stem:n}}let r=n.toLowerCase();for(let e of O)if(r.endsWith(e))return{direction:"revert",stem:n.slice(0,-e.length)};for(let e of F)if(r.endsWith(e))return{direction:"apply",stem:n.slice(0,-e.length)};return{direction:"apply",stem:n}}(e.path),{version:s,name:a}=function(e){let t=/^[Vv](\d+(?:[._]\d+)*)__(.*)$/.exec(e);if(t)return{version:t[1].replace(/_/g,"."),name:B(t[2])};let n=/^(\d+)(?:[-_.\s]+(.*))?$/.exec(e);return n?{version:n[1],name:B(n[2]??"")}:{version:e,name:B(e)}}(r),i=("apply"===n?t.applies:t.reverts).get(s);if(i){t.skipped.push(`${e.path} — ${i.path} is already version ${s}`);continue}"apply"===n?t.applies.set(s,{path:e.path,sql:e.text,name:a}):t.reverts.set(s,{path:e.path,sql:e.text})}return 0===t.applies.size&&0===t.reverts.size&&t.errors.push("None of those .sql files could be read as a migration."),t}(r),i=function(e,t){let n=new Map(e.map(e=>[e.version,{...e}])),r=[...t.skipped],s=0,a=0,i=0;for(let[e,i]of t.applies){let t=n.get(e);if(t){t.applySql!==i.sql&&(a+=1),t.name=i.name||t.name,t.applyPath=i.path,t.applySql=i.sql,t.checksum=P(i.sql),t.transaction=D(i.sql).mode;continue}if(n.size>=500){r.push(`${i.path} — over 500 migrations`);continue}n.set(e,{version:e,name:i.name||e,applyPath:i.path,applySql:i.sql,checksum:P(i.sql),transaction:D(i.sql).mode}),s+=1}for(let[e,s]of t.reverts){let t=n.get(e);if(!t){r.push(`${s.path} — no migration ${e} to revert`);continue}t.revertPath=s.path,t.revertSql=s.sql,i+=1}return{steps:[...n.values()].sort((e,t)=>E(e.version,t.version)),added:s,updated:a,reverts:i,skipped:r}}(s?.steps??[],a);return s&&e(e=>({sets:e.sets.map(e=>e.id===n?{...e,steps:i.steps,skipped:i.skipped,importedAt:Date.now()}:e)})),(0,es.L)("migrations.import",{name:s?.name,added:i.added,updated:i.updated,reverts:i.reverts,skipped:i.skipped.length}),i},renameSet:(t,n)=>{let r=n.trim().replace(/\s+/g," ").slice(0,80);r&&e(e=>({sets:e.sets.map(e=>e.id===t?{...e,name:r}:e)}))},removeStep:(t,n)=>e(e=>({sets:e.sets.map(e=>e.id===t?{...e,steps:e.steps.filter(e=>e.version!==n)}:e)})),removeSet:n=>{let r=t().sets.find(e=>e.id===n);e(e=>{let t={...e.activeSet};for(let[e,r]of Object.entries(t))r===n&&delete t[e];return{sets:e.sets.filter(e=>e.id!==n),activeSet:t}}),(0,es.L)("migrations.remove",{name:r?.name})},setActive:(t,n)=>e(e=>({activeSet:{...e.activeSet,[t]:n}})),record:t=>e(e=>({history:[{...t,id:(0,C.z)(),ranAt:Date.now()},...e.history].slice(0,300)})),clearHistory:t=>e(e=>({history:t?e.history.filter(e=>e.setId!==t):[]}))}),{name:"ytdb:migrations"}));var ei=n(34263),el=n(6059),eo=n(72194),ed=n(64577),ec=n(36565),eu=n(76721);let ep=(0,d.A)("clipboard-x",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"m14.5 11.5-5 5",key:"1eaq8h"}],["path",{d:"m9.5 11.5 5 5",key:"1exjew"}]]),em=(0,d.A)("file-up",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"m15 15-3-3-3 3",key:"15xj92"}]]);var eh=n(94179),ex=n(99314),ef=n(40891);let eg="w-24",ev="w-[104px]",ey={applied:"applied",drifted:"applied, but the file changed since",pending:"not applied",unknown:"not read yet"};function ej({status:e}){return"applied"===e?(0,r.jsx)(ed.A,{className:"size-4 text-emerald-600 dark:text-emerald-400"}):"drifted"===e?(0,r.jsx)(j,{className:"size-3.5 text-amber-600 dark:text-amber-400"}):"unknown"===e?(0,r.jsx)("span",{className:"size-1.5 rounded-full bg-muted-foreground/30"}):(0,r.jsx)(ec.A,{className:"size-3.5 text-muted-foreground/40"})}function ek({step:e,environments:t,targetId:n,status:s,isNewestApplied:a,expanded:i,busy:o,onToggle:d,actions:c}){var h;let[x,f]=(0,l.useState)("apply"),[g,v]=(0,l.useState)(!1),y="revert"===x?e.revertSql??"":e.applySql,k="unwrapped"===(h=e.transaction)?"no transaction":"self-managed"===h?"self-managed":null,$=function(e){switch(e){case"unwrapped":return"Marked `-- ytdb:no-transaction`, so it runs with no transaction. A failure partway leaves the statements before it applied.";case"self-managed":return"This file commits more than once, so YTDB runs it as written and records it afterwards. A failure partway can leave it half applied and unrecorded.";default:return null}}(e.transaction),A=[];async function S(){await (0,ef.mw)(y),v(!0),window.setTimeout(()=>v(!1),1500)}return"drifted"===s&&A.push("This file changed after it was applied here, so it is no longer the migration that ran."),$&&A.push($),(0,r.jsxs)("div",{className:"border-b last:border-b-0",children:[(0,r.jsxs)("div",{className:(0,C.cn)("flex h-10 items-center transition-colors hover:bg-muted/40",o&&"opacity-60"),children:[(0,r.jsxs)("button",{type:"button","aria-expanded":i,"aria-label":i?`Hide SQL for ${e.version}`:`Show SQL for ${e.version}`,onClick:d,className:"flex h-8 min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md px-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring/60",children:[(0,r.jsx)(eu.A,{className:(0,C.cn)("size-3.5 shrink-0 text-muted-foreground/70 transition-transform",i&&"rotate-90")}),(0,r.jsx)("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:e.version}),(0,r.jsx)("span",{className:"min-w-0 truncate text-sm",children:e.name}),k&&(0,r.jsx)("span",{className:"shrink-0 rounded border border-amber-600/25 bg-amber-500/10 px-1.5 text-[10px] text-amber-700 dark:text-amber-400",children:k})]}),t.map(t=>{let s=t.connection.id===n;return(0,r.jsx)("span",{title:t.error?`${t.connection.name}: ${t.error}`:`${e.version} is ${ey[t.status]} on ${t.connection.name}${t.entry?` — ${function(e){if(!e)return"";let t=new Date(e.appliedAt);return Number.isNaN(t.getTime())?e.appliedAt:t.toLocaleString()}(t.entry)}`:""}`,className:(0,C.cn)("flex h-10 shrink-0 items-center justify-center",eg,s&&"bg-foreground/[0.04]"),children:(0,r.jsx)(ej,{status:t.status})},t.connection.id)}),(0,r.jsxs)("div",{className:(0,C.cn)("flex shrink-0 items-center justify-end gap-1 pr-2 pl-1",ev),children:["pending"===s&&(0,r.jsx)(b.$,{size:"xs",variant:"outline",disabled:o,onClick:c.onApplyThrough,children:"Apply"}),a&&e.revertSql&&(0,r.jsxs)(b.$,{size:"xs",variant:"ghost",disabled:o,onClick:c.onRevertThrough,children:[(0,r.jsx)(m,{"data-icon":"inline-start"}),"Revert"]}),(0,r.jsxs)(N.rI,{children:[(0,r.jsx)(N.ty,{render:(0,r.jsx)(b.$,{size:"icon-xs",variant:"ghost","aria-label":`Actions for ${e.version}`}),className:"cursor-pointer",children:(0,r.jsx)(u.A,{})}),(0,r.jsxs)(N.SQ,{align:"end",className:"min-w-56",children:[(0,r.jsx)(N._2,{disabled:o||"applied"===s,onClick:c.onApplyThrough,children:"Apply everything through here"}),(0,r.jsx)(N._2,{disabled:o||"applied"===s,onClick:c.onApplyOne,children:"Apply only this one"}),(0,r.jsx)(N._2,{disabled:o||"pending"===s||!e.revertSql,onClick:c.onRevertThrough,children:"Revert back through here"}),(0,r.jsx)(N.mB,{}),(0,r.jsxs)(N._2,{disabled:o||"applied"===s,onClick:c.onMarkApplied,children:[(0,r.jsx)(p,{}),"Mark as already applied"]}),(0,r.jsxs)(N._2,{disabled:o||"pending"===s,onClick:c.onMarkPending,children:[(0,r.jsx)(ep,{}),"Mark as not applied"]}),(0,r.jsx)(N.mB,{}),(0,r.jsxs)(N._2,{onClick:c.onAttachRevert,children:[(0,r.jsx)(em,{}),e.revertSql?"Replace revert file…":"Add a revert file…"]}),(0,r.jsxs)(N._2,{onClick:()=>c.onOpenInEditor(y),children:[(0,r.jsx)(eh.A,{}),"Open ",x," SQL in editor"]}),(0,r.jsxs)(N._2,{onClick:()=>void S(),children:[(0,r.jsx)(ex.A,{}),"Copy ",x," SQL"]}),(0,r.jsx)(N.mB,{}),(0,r.jsx)(N._2,{variant:"destructive",onClick:c.onRemove,children:"Remove from this set"})]})]})]})]}),i&&(0,r.jsxs)("div",{className:"border-t bg-muted/25",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5",children:[(0,r.jsx)(w.x,{label:`SQL for ${e.version}`,value:x,onChange:f,options:[{value:"apply",label:"Apply"},{value:"revert",label:"Revert"}]}),(0,r.jsx)("span",{className:"min-w-0 truncate font-mono text-[11px] text-muted-foreground",children:"revert"===x?e.revertPath??"no revert file":e.applyPath}),(0,r.jsxs)(b.$,{size:"xs",variant:"ghost",className:"ml-auto",onClick:()=>void S(),children:[g?(0,r.jsx)(ed.A,{"data-icon":"inline-start"}):(0,r.jsx)(ex.A,{"data-icon":"inline-start"}),g?"Copied":"Copy"]})]}),A.length>0&&(0,r.jsx)("ul",{className:"space-y-1 px-3 pb-2",children:A.map(e=>(0,r.jsxs)("li",{className:"flex gap-1.5 text-[11px] text-amber-700 dark:text-amber-400",children:[(0,r.jsx)(j,{className:"mt-px size-3 shrink-0"}),(0,r.jsx)("span",{children:e})]},e))}),y?(0,r.jsx)(ef.os,{sql:y,className:"max-h-72 overflow-auto px-3 pb-3"}):(0,r.jsxs)("div",{className:"flex items-center gap-2 px-3 pb-3 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{children:"No revert file, so this one cannot be undone from here."}),(0,r.jsxs)(b.$,{size:"xs",variant:"outline",onClick:c.onAttachRevert,children:[(0,r.jsx)(em,{"data-icon":"inline-start"}),"Add one"]})]})]})]})}function eb({environments:e,targetId:t,onSelect:n}){let s=e.find(e=>e.connection.id===t);return s?(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"Running against"}),(0,r.jsxs)(N.rI,{children:[(0,r.jsxs)(N.ty,{disabled:e.length<2,className:"flex h-7 cursor-pointer items-center gap-1.5 rounded-lg border bg-background px-2 text-xs font-medium outline-none hover:bg-muted/60 focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-default data-open:bg-muted/60",children:[(0,r.jsx)(eo.F,{connection:s.connection}),(0,r.jsx)("span",{className:"max-w-32 truncate",children:s.connection.name})]}),(0,r.jsx)(N.SQ,{align:"start",className:"min-w-52",children:e.map(e=>(0,r.jsxs)(N._2,{onClick:()=>n(e.connection.id),className:e.connection.id===t?"font-medium":void 0,children:[(0,r.jsx)(eo.F,{connection:e.connection}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.connection.name}),(0,r.jsxs)("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:[e.summary.applied,"/",e.summary.total]})]},e.connection.id))})]})]}):null}function eN({environments:e,targetId:t,caption:n,loading:s,onSelect:a,onCompare:i}){return(0,r.jsxs)("div",{className:"flex h-11 shrink-0 items-center border-b bg-muted/20",children:[(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate px-3 text-xs text-muted-foreground",children:n}),e.map(e=>{let{connection:n,summary:i,ledger:l,error:o}=e,d=n.id===t;return(0,r.jsxs)("button",{type:"button",disabled:d,"aria-current":d?"true":void 0,title:d?`${n.name} is what Apply and Revert run against`:`Run against ${n.name} instead`,onClick:()=>a(n.id),className:(0,C.cn)("flex h-11 shrink-0 flex-col items-center justify-center gap-0.5 border-l text-[11px] outline-none",eg,d?"cursor-default bg-foreground/[0.04] font-medium":"cursor-pointer text-muted-foreground hover:bg-muted/60 hover:text-foreground",s&&"opacity-60"),children:[(0,r.jsxs)("span",{className:"flex max-w-full items-center gap-1",children:[(0,r.jsx)(eo.F,{connection:n,className:"size-1.5"}),(0,r.jsx)("span",{className:"truncate",children:n.name})]}),o?(0,r.jsx)("span",{className:"text-destructive",children:"unreachable"}):l?(0,r.jsxs)("span",{className:"tabular-nums text-muted-foreground/80",children:[i.applied,"/",i.total,i.drifted>0&&(0,r.jsx)("span",{className:"text-amber-600 dark:text-amber-400",children:" !"})]}):(0,r.jsx)("span",{className:"text-muted-foreground/70",children:"reading…"})]},n.id)}),(0,r.jsx)("div",{className:(0,C.cn)("flex shrink-0 items-center justify-end border-l pr-2 pl-1",ev),children:e.length>1&&(0,r.jsx)(b.$,{size:"icon-xs",variant:"ghost",title:"Compare the two schemas","aria-label":"Compare schemas",onClick:()=>{let n=e.find(e=>e.connection.id!==t);n&&i(n.connection.id)},children:(0,r.jsx)(el.A,{})})})]})}var ew=n(42763),e$=n(60529),eA=n(33807);function eS({schema:e,found:t,onOpenChange:n,onSave:s}){let[a,i]=(0,l.useState)(e),o=a.trim(),d=ee(o),c=t.filter(e=>e.schema!==o);function u(){d&&(s(o),n(!1))}return(0,r.jsx)(ew.lG,{open:!0,onOpenChange:n,children:(0,r.jsxs)(ew.Cf,{className:"sm:max-w-md",children:[(0,r.jsxs)(ew.c7,{children:[(0,r.jsx)(ew.L3,{children:"Where the ledger lives"}),(0,r.jsx)(ew.rr,{children:"Each database records what it has run in its own table. This is the schema that table goes in, for every connection — dev and prod have to look in the same place for their columns to mean anything."})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,r.jsx)(eA.J,{htmlFor:"ledger-schema",children:"Schema"}),(0,r.jsx)(e$.p,{id:"ledger-schema",value:a,spellCheck:!1,autoComplete:"off","aria-invalid":o.length>0&&!d,onChange:e=>i(e.target.value),onKeyDown:e=>"Enter"===e.key&&u()}),(0,r.jsx)("p",{className:"font-mono text-xs text-muted-foreground",children:d?`${o}.${X}`:"\xa0"}),o.length>0&&!d&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:"Letters, digits and underscores only, starting with a letter or underscore."})]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"The schema is created on the first apply, so the connection needs permission to create it. Nothing is created just by reading a ledger."}),c.length>0&&(0,r.jsxs)("p",{className:"rounded-md border border-amber-600/25 bg-amber-500/8 px-3 py-2 text-xs",children:[c.map(e=>`${e.name} already keeps its ledger in ${e.schema}`).join("; "),". Those keep being used where they are, so nothing already applied is forgotten."]}),(0,r.jsxs)(ew.Es,{children:[o!==K&&(0,r.jsx)(b.$,{variant:"ghost",onClick:()=>i(K),children:"Reset"}),(0,r.jsx)(b.$,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),(0,r.jsx)(b.$,{disabled:!d,onClick:u,children:"Save"})]})]})})}var eC=n(9005);function eM({record:e}){let t="failed"===e.status;return(0,r.jsxs)("div",{className:"flex items-start gap-2 border-b px-4 py-2 text-xs last:border-b-0",children:[t?(0,r.jsx)(eC.A,{className:"mt-0.5 size-3.5 shrink-0 text-destructive"}):(0,r.jsx)(ed.A,{className:"mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"}),(0,r.jsx)("span",{className:(0,C.cn)("mt-px shrink-0 rounded-md px-1.5 text-[11px]",e.recorded?"bg-muted text-muted-foreground/80 italic":"revert"===e.direction?"bg-amber-500/15 text-amber-700 dark:text-amber-400":"bg-muted text-muted-foreground"),children:e.recorded?"apply"===e.direction?"marked":"unmarked":e.direction}),(0,r.jsx)("span",{className:"shrink-0 font-mono text-muted-foreground",children:e.version}),(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,r.jsx)("span",{className:"truncate",children:e.name}),t&&e.error&&(0,r.jsx)("span",{className:"mt-1 block font-mono text-[11px] whitespace-pre-wrap text-destructive",children:e.error})]}),(0,r.jsx)("span",{className:"shrink-0 text-muted-foreground",children:e.connectionName}),(0,r.jsx)("span",{className:"hidden max-w-32 shrink-0 truncate text-muted-foreground/60 lg:inline",children:e.setName}),(0,r.jsxs)("span",{className:"shrink-0 tabular-nums text-muted-foreground/70",children:[e.durationMs," ms"]}),(0,r.jsx)("span",{className:"shrink-0 text-muted-foreground/70",children:new Date(e.ranAt).toLocaleString()})]})}function ez({connectionIds:e}){let t=ea(e=>e.history),n=ea(e=>e.clearHistory),s=new Set(e),a=t.filter(e=>0===s.size||s.has(e.connectionId));return 0===a.length?(0,r.jsx)("p",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Nothing has been applied or reverted from here yet. Runs show up here with their duration and any error, including the failures the ledger never keeps."}):(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-1.5",children:[(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a.length," run",1===a.length?"":"s",", newest first"]}),(0,r.jsx)(b.$,{size:"xs",variant:"ghost",onClick:()=>n(),children:"Clear"})]}),(0,r.jsx)("div",{className:"border-t",children:a.map(e=>(0,r.jsx)(eM,{record:e},e.id))})]})}var eq=n(92571);let eR=(0,d.A)("folder-open",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);function eI(e){let t=e.createReader?.();return t?new Promise((e,n)=>{let r=[],s=()=>{t.readEntries(t=>{0===t.length||r.length>=2e3?e(r):(r.push(...t),s())},n)};s()}):Promise.resolve([])}async function eD(e,t,n,r){if(r.length>=2e3||n>6||e.name.startsWith("."))return;let s=t?`${t}/${e.name}`:e.name;if(e.isFile){if(!/\.sql$/i.test(e.name))return;let t=await new Promise((t,n)=>{e.file?e.file(t,n):n(Error(`Could not read ${e.name}`))});r.push({path:s,text:await t.text()});return}if(e.isDirectory)for(let t of(await eI(e)))await eD(t,s,n+1,r)}async function eL(e){let t=[];for(let n of Array.from(e.items)){if("file"!==n.kind)continue;let e=n.webkitGetAsEntry?.();e&&t.push(e)}if(0===t.length){let t=Array.from(e.files).filter(e=>/\.sql$/i.test(e.name));return 0===t.length?null:{name:"Migrations",files:await Promise.all(t.map(async e=>({path:e.name,text:await e.text()})))}}let n=1===t.length&&t[0].isDirectory?t[0]:null,r=[];if(n){for(let e of(await eI(n)))await eD(e,"",1,r);return{name:n.name,files:r}}for(let e of t)await eD(e,"",0,r);return r.length>0?{name:"Migrations",files:r}:null}async function e_(e){let t,n=Array.from(e).filter(e=>/\.sql$/i.test(e.name));if(0===n.length)return null;let r=new Set(n.map(e=>(e.webkitRelativePath||e.name).split("/")[0])),s=1===r.size&&((t=n[0]).webkitRelativePath||t.name).includes("/")?[...r][0]:null;return{name:s??"Migrations",files:await Promise.all(n.slice(0,2e3).map(async e=>{let t=e.webkitRelativePath||e.name;return{path:s?t.slice(s.length+1):t,text:await e.text()}}))}}function eF(e){let[t,n]=(0,l.useState)(!1),[r,s]=(0,l.useState)(null);return{importFrom:(0,l.useCallback)(async t=>{n(!0),s(null);try{let n=t instanceof FileList?await e_(t):await eL(t);if(!n||0===n.files.length)return void s("No .sql files in there.");e(n)}catch(e){s(e instanceof Error?e.message:"Couldn’t read that folder.")}finally{n(!1)}},[e]),busy:t,error:r,clearError:()=>s(null)}}function eO({onFiles:e,hint:t,className:n,compact:s=!1}){let{importFrom:a,busy:i,error:o}=eF(e),[d,u]=(0,l.useState)(!1),p=(0,l.useRef)(null),m=(0,l.useRef)(null);return(0,l.useEffect)(()=>{p.current?.setAttribute("webkitdirectory",""),p.current?.setAttribute("directory","")},[]),(0,r.jsxs)("div",{onDragOver:e=>{e.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:e=>{e.preventDefault(),u(!1),a(e.dataTransfer)},className:(0,C.cn)("flex flex-col items-center justify-center gap-3 rounded-lg border border-dashed text-center transition-colors",s?"gap-2 px-4 py-6":"px-6 py-10",d?"border-primary bg-primary/5":"border-border",n),children:[i?(0,r.jsx)(eq.A,{className:"size-5 animate-spin text-muted-foreground"}):(0,r.jsx)(c,{className:"size-5 text-muted-foreground"}),(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:"Drop migrations here"}),(0,r.jsx)("p",{className:"max-w-md text-xs text-muted-foreground",children:t??"A folder of .sql files, or one split into apply/ and revert/ (or up/ and down/). Revert files are optional, and you can add more files later."})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)(b.$,{size:"sm",variant:"outline",disabled:i,onClick:()=>p.current?.click(),children:[(0,r.jsx)(eR,{"data-icon":"inline-start"}),"Choose folder"]}),(0,r.jsx)(b.$,{size:"sm",variant:"ghost",disabled:i,onClick:()=>m.current?.click(),children:"Choose files"})]}),o&&(0,r.jsx)("p",{className:"max-w-sm text-xs text-destructive",children:o}),(0,r.jsx)("input",{ref:p,type:"file",multiple:!0,className:"sr-only",onChange:e=>{let{files:t}=e.target;t&&t.length>0&&a(t),e.target.value=""}}),(0,r.jsx)("input",{ref:m,type:"file",multiple:!0,accept:".sql",className:"sr-only",onChange:e=>{let{files:t}=e.target;t&&t.length>0&&a(t),e.target.value=""}})]})}let eT=(0,d.A)("circle-dashed",[["path",{d:"M10.1 2.182a10 10 0 0 1 3.8 0",key:"5ilxe3"}],["path",{d:"M13.9 21.818a10 10 0 0 1-3.8 0",key:"11zvb9"}],["path",{d:"M17.609 3.721a10 10 0 0 1 2.69 2.7",key:"1iw5b2"}],["path",{d:"M2.182 13.9a10 10 0 0 1 0-3.8",key:"c0bmvh"}],["path",{d:"M20.279 17.609a10 10 0 0 1-2.7 2.69",key:"1ruxm7"}],["path",{d:"M21.818 10.1a10 10 0 0 1 0 3.8",key:"qkgqxc"}],["path",{d:"M3.721 6.391a10 10 0 0 1 2.7-2.69",key:"1mcia2"}],["path",{d:"M6.391 20.279a10 10 0 0 1-2.69-2.7",key:"1fvljs"}]]);function eB({status:e}){switch(e){case"running":return(0,r.jsx)(eq.A,{className:"size-3.5 shrink-0 animate-spin text-primary"});case"ok":return(0,r.jsx)(ed.A,{className:"size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"});case"failed":return(0,r.jsx)(eC.A,{className:"size-3.5 shrink-0 text-destructive"});case"skipped":return(0,r.jsx)(ec.A,{className:"size-3.5 shrink-0 text-muted-foreground/60"});default:return(0,r.jsx)(eT,{className:"size-3.5 shrink-0 text-muted-foreground/60"})}}function eE({open:e,direction:t,connection:n,steps:s,blockedBy:a,progress:i,running:l,recordOnly:o,onRun:d,onStop:c,onClose:u}){let p=o?"apply"===t?"Mark as applied":"Mark as not applied":"apply"===t?"Apply":"Revert",m=o?"Marked":"apply"===t?"Applied":"Reverted",h=s.length,x=s.filter(e=>{var t;return"wrapped-by-ytdb"!==(t=e.transaction)&&"self-wrapped"!==t}),f=i?.find(e=>"failed"===e.status)??null,g=null!==i&&!l,v=i?.filter(e=>"ok"===e.status).length??0,y=i??s.map(e=>({version:e.version,name:e.name,status:"waiting"}));return(0,r.jsx)(ew.lG,{open:e,onOpenChange:e=>!e&&!l&&u(),children:(0,r.jsxs)(ew.Cf,{className:"sm:max-w-lg",children:[(0,r.jsxs)(ew.c7,{children:[(0,r.jsx)(ew.L3,{children:0===h&&a?"Nothing here can be reverted":g?f?`${p} stopped after ${v} of ${h}`:`${m} ${v} migration${1===v?"":"s"}`:o?`${"Mark as applied"===p?"Mark":"Unmark"} ${h} migration${1===h?"":"s"} on ${n.name}?`:`${p} ${h} migration${1===h?"":"s"}?`}),(0,r.jsx)(ew.rr,{children:(0,r.jsxs)("span",{className:"flex flex-wrap items-center gap-1.5",children:[(0,r.jsx)("span",{children:o?g?"Recorded on":"Records on":g?"Ran against":"Runs against"}),(0,r.jsx)(eo.F,{connection:n}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:n.name}),(0,r.jsx)("span",{className:"font-mono text-[11px]",children:function(e){try{let t=new URL(e),n=t.username?`${decodeURIComponent(t.username)}@`:"",r=t.port?`:${t.port}`:"";return`${n}${t.hostname}${r}${t.pathname}`}catch{return"this connection"}}(n.url)})]})})]}),y.length>0&&(0,r.jsx)("div",{className:"max-h-64 overflow-y-auto rounded-md border",children:y.map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-2 border-b px-3 py-1.5 text-xs last:border-b-0",children:[(0,r.jsx)(eB,{status:e.status}),(0,r.jsx)("span",{className:"shrink-0 font-mono text-muted-foreground",children:e.version}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name}),void 0!==e.durationMs&&(0,r.jsxs)("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:[e.durationMs," ms"]})]},e.version))}),f?.error&&(0,r.jsx)("p",{className:"max-h-32 overflow-auto rounded-md border border-destructive/25 bg-destructive/5 px-3 py-2 font-mono text-[11px] whitespace-pre-wrap text-destructive",children:f.error}),!i&&a&&(0,r.jsxs)("p",{className:"flex gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(j,{className:"mt-px size-3.5 shrink-0 text-amber-600 dark:text-amber-400"}),(0,r.jsx)("span",{children:0===h?`${a.version} ${a.name} is the newest one applied and has no revert file, so nothing below it can be reached.`:`Stops at ${a.version} ${a.name}, which has no revert file.`})]}),!i&&o&&(0,r.jsxs)("p",{className:"rounded-md border border-amber-600/25 bg-amber-500/8 px-3 py-2 text-xs",children:[(0,r.jsx)("span",{className:"font-medium",children:"No SQL runs."})," This only changes what"," ",n.name," says it has already had — use it when the schema is already in place, for instance after migrating by hand."]}),!i&&!o&&x.length>0&&(0,r.jsxs)("p",{className:"flex gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(j,{className:"mt-px size-3.5 shrink-0 text-amber-600 dark:text-amber-400"}),(0,r.jsx)("span",{children:1===x.length?`${x[0].version} runs outside a transaction, so a failure partway leaves it half applied.`:`${x.length} of these run outside a transaction, so a failure partway leaves them half applied.`})]}),!i&&!o&&"revert"===t&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"Reverting runs newest first and can drop data the migrations created."}),(0,r.jsx)(ew.Es,{children:l?(0,r.jsx)(b.$,{variant:"outline",onClick:c,children:"Stop after this one"}):g?(0,r.jsx)(b.$,{onClick:u,children:"Close"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(b.$,{variant:"outline",onClick:u,children:0===h?"Close":"Cancel"}),h>0&&(0,r.jsx)(b.$,{variant:o||"revert"!==t?"default":"destructive",onClick:d,children:o?`${p} (${h})`:`${p} ${1===h?"migration":`${h} migrations`}`})]})})]})})}function eP(){let e=(0,i.useRouter)(),{connection:t,tables:n}=(0,k.k)(),s=ea(e=>e.sets),d=ea(e=>e.createSet),f=ea(e=>e.addFiles),g=ea(e=>e.renameSet),v=ea(e=>e.removeSet),y=ea(e=>e.removeStep),j=ea(e=>e.setActive),w=ea(e=>e.record),M=ea(e=>e.ledgerSchema),z=ea(e=>e.setLedgerSchema),q=function(e){let t=ea(e=>e.sets),n=ea(t=>t.activeSet[e]);if(0===t.length)return null;let r=t.find(e=>e.id===n);return r||([...t].sort((e,t)=>t.importedAt-e.importedAt)[0]??null)}(t.id),R=(0,et.gz)(t.id),I=(0,ei.En)(e=>e.setDraft),D=(0,ei.En)(e=>e.setActiveSaved),[L,_]=(0,l.useState)("migrations"),[F,O]=(0,l.useState)([]),[T,B]=(0,l.useState)(null),[E,P]=(0,l.useState)(null),[H,Q]=(0,l.useState)(!1),[K,ee]=(0,l.useState)(!1),[en,er]=(0,l.useState)(null),[es,el]=(0,l.useState)(null),[eo,ed]=(0,l.useState)(!1),ec=(0,l.useRef)(null),eu=(0,l.useRef)(!1),ep=(0,l.useMemo)(()=>[t,...R],[t,R]),em=ep.map(e=>e.url).join("|"),eh=(0,A.Y)(`ledgers:${M}:${em}`,async e=>Object.fromEntries(await Promise.all(ep.map(async t=>{try{return[t.id,{ledger:await S.F.ledger(t.url,M,e),error:null}]}catch(n){if(e.aborted)throw n;return[t.id,{ledger:null,error:n instanceof Error?n.message:String(n)}]}})))),ex=eh.data?.[t.id]??null,ef=ex?.ledger??null,eg=(0,l.useMemo)(()=>ep.map(e=>{let t=eh.data?.[e.id]??null;return{connection:e,ledger:t?.ledger??null,error:t?.error??null,summary:W(q,t?.ledger??null)}}),[ep,eh.data,q]),ev=(0,l.useMemo)(()=>new Set(ep.map(e=>e.id)),[ep]),ey=ea(e=>e.history.filter(e=>ev.has(e.connectionId)).length),ej=W(q,ef),ew=(0,l.useMemo)(()=>Y(q,ef),[q,ef]),e$=function(e,t){if(!e||!t)return null;let n=V(t);for(let t of[...e.steps].reverse())if(n.has(t.version))return t;return null}(q,ef),eA=(0,l.useCallback)(e=>{let n=q?.id??d(e.name),r=f(n,e.files);j(t.id,n),er(r),_("migrations")},[q?.id,d,f,j,t.id]),eC=eF(eA);function eM(e,t,n=!1){(0!==t.steps.length||t.blockedBy)&&(P(null),B({...t,direction:e,recordOnly:n}))}function eq(e){return{steps:e,blockedBy:null}}async function eR(){if(!T||!q)return;eu.current=!1,Q(!0);let e=T.steps.map(e=>({version:e.version,name:e.name,status:"waiting"}));P(e);let r=(t,n)=>{P(e=e.map((e,r)=>r===t?{...e,...n}:e))},s=t=>{P(e=e.map((e,n)=>n>=t&&"waiting"===e.status?{...e,status:"skipped"}:e))};for(let[e,n]of T.steps.entries()){if(eu.current){s(e);break}let a="apply"===T.direction?n.applySql:n.revertSql;if(!a&&!T.recordOnly){r(e,{status:"failed",error:"No revert file for this migration."}),s(e+1);break}r(e,{status:"running"});try{let s=await S.F.migrate(t.url,{direction:T.direction,version:n.version,name:n.name,checksum:n.checksum,setName:q.name,sql:a??"",ledgerSchema:M,recordOnly:T.recordOnly});r(e,{status:"ok",durationMs:s.durationMs}),w({setId:q.id,setName:q.name,connectionId:t.id,connectionName:t.name,direction:T.direction,version:n.version,name:n.name,status:"ok",recorded:T.recordOnly,durationMs:s.durationMs})}catch(i){let a=i instanceof Error?i.message:String(i);r(e,{status:"failed",error:a}),s(e+1),w({setId:q.id,setName:q.name,connectionId:t.id,connectionName:t.name,direction:T.direction,version:n.version,name:n.name,status:"failed",durationMs:0,error:a});break}}Q(!1),eh.reload(),n.reload()}function eI(n){I(t.id,n),D(t.id,null),e.push(`/${encodeURIComponent(t.id)}/query`)}function eD(n){n!==t.id&&e.push(`/${encodeURIComponent(n)}/migrations`)}async function eL(e){let t=e?.[0];el(null),t&&es&&q&&er(f(q.id,[{path:`revert/${es}_${t.name}`,text:await t.text()}]))}if(0===s.length)return(0,r.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col",children:[(0,r.jsx)(eQ,{}),"history"===L?(0,r.jsx)($.F,{className:"min-h-0 flex-1",children:(0,r.jsx)(ez,{connectionIds:ep.map(e=>e.id)})}):(0,r.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-4 p-6",children:[(0,r.jsx)(eO,{onFiles:eA,className:"w-full max-w-xl"}),(0,r.jsxs)("p",{className:"max-w-xl text-center text-xs text-muted-foreground",children:["YTDB records every migration it runs in"," ",(0,r.jsxs)("code",{className:"font-mono",children:[M,".",X]})," ","in the database it ran against, so each environment answers for itself what it has and has not had."]})]}),(0,r.jsx)(eH,{caption:"No migrations imported yet",pane:L,onPaneChange:_,historyCount:ey})]});let e_=G(q,ef),eT=J(q,ef),eB=H||eh.loading;return(0,r.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",onDragOver:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),ee(!0))},children:[(0,r.jsxs)(eQ,{children:[(0,r.jsx)(eV,{activeName:q?.name??"No folder",sets:s.map(e=>({id:e.id,name:e.name,steps:e.steps.length})),activeId:q?.id??null,onSelect:e=>j(t.id,e),onCreate:function(){let e=window.prompt("Name this migration set","Migrations");if(null===e)return;let n=d(e.trim()||"Migrations");j(t.id,n),er(null)},onRename:function(){if(!q)return;let e=window.prompt("Rename this migration set",q.name);null!==e&&g(q.id,e)},onRemove:e=>v(e)}),(0,r.jsx)(eb,{environments:eg,targetId:t.id,onSelect:eD}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,r.jsxs)(b.$,{size:"sm",variant:"ghost",disabled:eh.loading,title:"Re-read every environment's ledger",onClick:()=>eh.reload(),children:[(0,r.jsx)(o.A,{"data-icon":"inline-start",className:(0,C.cn)(eh.loading&&"animate-spin")}),"Refresh"]}),(0,r.jsxs)(b.$,{size:"sm",variant:"ghost",onClick:()=>ee(!0),children:[(0,r.jsx)(c,{"data-icon":"inline-start"}),"Import"]}),(0,r.jsxs)(N.rI,{children:[(0,r.jsx)(N.ty,{render:(0,r.jsx)(b.$,{size:"icon-sm",variant:"ghost","aria-label":"More migration actions"}),className:"cursor-pointer",children:(0,r.jsx)(u.A,{})}),(0,r.jsxs)(N.SQ,{align:"end",className:"min-w-64",children:[(0,r.jsxs)(N._2,{disabled:eB||0===e_.steps.length,onClick:()=>eM("apply",eq(e_.steps),!0),children:[(0,r.jsx)(p,{}),"Mark ",e_.steps.length," as already applied"]}),(0,r.jsx)(N.mB,{}),(0,r.jsxs)(N._2,{disabled:eB||0===eT.steps.length,onClick:()=>eM("revert",eT),children:[(0,r.jsx)(m,{}),"Revert everything on ",t.name]}),(0,r.jsx)(N.mB,{}),(0,r.jsxs)(N._2,{onClick:()=>ed(!0),children:[(0,r.jsx)(h,{}),"Ledger table: ",M,".",X]})]})]}),(0,r.jsxs)(b.$,{size:"sm",disabled:eB||0===e_.steps.length,onClick:()=>eM("apply",e_),children:[(0,r.jsx)(x.A,{"data-icon":"inline-start"}),0===e_.steps.length?"Nothing pending":`Apply ${e_.steps.length} to ${t.name}`]})]})]}),0===R.length&&(0,r.jsxs)("p",{className:"border-b bg-muted/30 px-4 py-1.5 text-xs text-muted-foreground",children:["Only ",t.name," is tracked here."," ",(0,r.jsx)(a(),{href:"/",className:"text-foreground underline underline-offset-4",children:"Link it to the same database in another environment"})," ","to track both side by side."]}),en&&(0,r.jsx)(eU,{report:en,onDismiss:()=>er(null)}),eC.error&&(0,r.jsx)("p",{className:"border-b bg-destructive/5 px-4 py-1.5 text-xs text-destructive",children:eC.error}),(0,r.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:["history"===L?(0,r.jsx)($.F,{className:"min-h-0 flex-1",children:(0,r.jsx)(ez,{connectionIds:ep.map(e=>e.id)})}):ex?.error?(0,r.jsx)("p",{className:"flex-1 px-4 py-6 font-mono text-xs text-destructive",children:ex.error}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eN,{environments:eg,targetId:t.id,caption:function(e,t){if(t&&0===e.total)return"Reading…";let n=`${e.total} migration${1===e.total?"":"s"}`;return e.foreign>0?`${n} \xb7 ${e.foreign} more applied but missing from this folder`:n}(ej,eh.loading),loading:eh.loading,onSelect:eD,onCompare:function(n){et.lz.getState().setCompareTarget(t.id,n),e.push(`/${encodeURIComponent(t.id)}/diff`)}}),(0,r.jsxs)($.F,{className:(0,C.cn)("min-h-0 flex-1",eh.loading&&"opacity-70"),children:[(q?.steps.length??0)===0&&(0,r.jsx)("div",{className:"p-6",children:(0,r.jsx)(eO,{onFiles:eA,compact:!0,hint:"Drop .sql files here to fill this set. They can arrive a folder at a time or one at a time."})}),(q?.steps??[]).map(e=>(0,r.jsx)(ek,{step:e,targetId:t.id,status:Z(e,ef),environments:eg.map(t=>({connection:t.connection,status:Z(e,t.ledger),entry:U(e,t.ledger),error:t.error})),isNewestApplied:e$?.version===e.version,expanded:F.includes(e.version),busy:eB,onToggle:()=>{var t;return t=e.version,void O(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},actions:{onApplyThrough:()=>eM("apply",G(q,ef,e.version)),onApplyOne:()=>eM("apply",{steps:[e],blockedBy:null}),onRevertThrough:()=>eM("revert",J(q,ef,e.version)),onMarkApplied:()=>eM("apply",eq([e]),!0),onMarkPending:()=>eM("revert",eq([e]),!0),onAttachRevert:()=>{el(e.version),window.requestAnimationFrame(()=>ec.current?.click())},onRemove:()=>q&&y(q.id,e.version),onOpenInEditor:eI}},e.version)),ew.length>0&&(0,r.jsx)(eZ,{entries:ew,connectionName:t.name})]})]}),K&&(0,r.jsx)("div",{className:"absolute inset-0 z-20 flex items-center justify-center bg-background/85 p-6",onDragOver:e=>e.preventDefault(),onDragLeave:()=>ee(!1),onDrop:e=>{e.preventDefault(),ee(!1),eC.importFrom(e.dataTransfer)},children:(0,r.jsx)(eO,{onFiles:eA,className:"w-full max-w-xl bg-background"})})]}),(0,r.jsx)(eH,{pane:L,onPaneChange:_,historyCount:ey,caption:function({name:e,connectionName:t,summary:n,initialized:r,loading:s,foundIn:a,configuredSchema:i}){if(s&&null===r)return"Reading ledgers…";if(!1===r)return`${t} has never had a migration run by YTDB, so all ${n.total} are pending`;let l=[];return 0===n.pending?l.push(`${t} is up to date with ${e}`):l.push(`${n.pending} of ${n.total} still to apply to ${t}`),n.drifted>0&&l.push(`${n.drifted} file${1===n.drifted?"":"s"} changed since it ran`),a&&a!==i&&l.push(`ledger kept in ${a}, not ${i}`),l.join(" \xb7 ")}({name:q?.name??"",connectionName:t.name,summary:ej,initialized:ef?.initialized??null,loading:eh.loading,foundIn:ef?.initialized?ef.schema:null,configuredSchema:M})}),(0,r.jsx)("input",{ref:ec,type:"file",accept:".sql",className:"sr-only",onChange:e=>{eL(e.target.files),e.target.value=""}}),eo&&(0,r.jsx)(eS,{schema:M,found:eg.filter(e=>e.ledger?.initialized).map(e=>({name:e.connection.name,schema:e.ledger?.schema??M})),onOpenChange:ed,onSave:e=>{z(e),eh.reload()}}),T&&(0,r.jsx)(eE,{open:!0,direction:T.direction,connection:t,steps:T.steps,blockedBy:T.blockedBy,progress:E,running:H,recordOnly:T.recordOnly??!1,onRun:()=>void eR(),onStop:()=>{eu.current=!0},onClose:function(){H||(B(null),P(null))}})]})}function eH({caption:e,pane:t,onPaneChange:n,historyCount:s}){return(0,r.jsxs)("footer",{className:"flex shrink-0 items-center gap-2 border-t px-4 py-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"min-w-0 truncate",children:e}),(0,r.jsx)("div",{className:"ml-auto",children:(0,r.jsx)(w.x,{label:"Migrations pane",value:t,onChange:n,options:[{value:"migrations",label:"Migrations"},{value:"history",label:s>0?`History (${s})`:"History"}]})})]})}function eQ({children:e}){return(0,r.jsxs)("header",{className:"flex h-11 shrink-0 items-center gap-2 border-b px-3",children:[(0,r.jsx)(f.A,{className:"size-4 shrink-0 text-muted-foreground"}),(0,r.jsx)("span",{className:"font-medium",children:"Migrations"}),e]})}function eV({activeId:e,activeName:t,sets:n,onSelect:s,onCreate:a,onRename:i,onRemove:l}){return(0,r.jsxs)(N.rI,{children:[(0,r.jsxs)(N.ty,{className:"flex h-7 min-w-0 cursor-pointer items-center gap-1.5 rounded-lg bg-muted/70 px-2 text-xs outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 data-open:bg-muted",children:[(0,r.jsx)("span",{className:"max-w-40 truncate font-medium",children:t}),(0,r.jsx)(g.A,{className:"size-3 shrink-0 text-muted-foreground"})]}),(0,r.jsxs)(N.SQ,{align:"start",className:"min-w-56",children:[n.map(t=>(0,r.jsxs)(N._2,{onClick:()=>s(t.id),className:t.id===e?"font-medium":void 0,children:[(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate",children:t.name}),(0,r.jsx)("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:t.steps})]},t.id)),n.length>0&&(0,r.jsx)(N.mB,{}),(0,r.jsxs)(N._2,{onClick:a,children:[(0,r.jsx)(v.A,{}),"New empty set"]}),e&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(N._2,{onClick:i,children:[(0,r.jsx)(y.A,{}),"Rename"]}),(0,r.jsx)(N._2,{variant:"destructive",onClick:()=>l(e),children:"Forget this set"})]})]})]})}function eU({report:e,onDismiss:t}){let n=[];return e.added>0&&n.push(`added ${e.added}`),e.updated>0&&n.push(`updated ${e.updated}`),e.reverts>0&&n.push(`${e.reverts} revert file${1===e.reverts?"":"s"}`),(0,r.jsxs)("div",{className:"flex items-start gap-2 border-b bg-muted/30 px-4 py-1.5 text-xs",children:[(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[n.length>0?`Imported: ${n.join(", ")}`:"Nothing new in those files",e.skipped.length>0&&(0,r.jsxs)("span",{className:"text-muted-foreground",children:[" ","\xb7 skipped ",e.skipped.slice(0,2).join(", "),e.skipped.length>2&&` and ${e.skipped.length-2} more`]})]}),(0,r.jsx)(b.$,{size:"xs",variant:"ghost",onClick:t,children:"Dismiss"})]})}function eZ({entries:e,connectionName:t}){return(0,r.jsxs)("div",{className:"border-t bg-muted/20",children:[(0,r.jsxs)("p",{className:"flex items-center gap-2 px-4 py-2 text-xs text-muted-foreground",children:[(0,r.jsx)(j,{className:"size-3.5 shrink-0 text-amber-600 dark:text-amber-400"}),"Applied on ",t," but not in this folder — the folder may be out of date."]}),e.map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-1.5 text-xs opacity-70",children:[(0,r.jsx)(ej,{status:"applied"}),(0,r.jsx)("span",{className:"shrink-0 font-mono text-muted-foreground",children:e.version}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name||"—"}),(0,r.jsx)("span",{className:"shrink-0 text-muted-foreground/70",children:new Date(e.appliedAt).toLocaleString()})]},e.version))]})}},82749:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("refresh-cw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]])},92571:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]])},94179:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("square-terminal",[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]])},99314:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});let r=(0,n(99537).A)("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]])}},e=>{e.O(0,[603,842,500,9,469,444,441,794,358],()=>e(e.s=68376)),_N_E=e.O()}]);
|
|
File without changes
|
|
File without changes
|