d1s 0.2.6 → 0.2.9
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/README.md +3 -1
- package/dist/.next/.next/BUILD_ID +1 -1
- package/dist/.next/.next/app-build-manifest.json +38 -24
- package/dist/.next/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/.next/build-manifest.json +2 -2
- package/dist/.next/.next/cache/.rscinfo +1 -1
- package/dist/.next/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack.old +0 -0
- package/dist/.next/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/.next/next-server.js.nft.json +1 -1
- package/dist/.next/.next/prerender-manifest.json +1 -1
- package/dist/.next/.next/server/app/_not-found/page.js +1 -1
- package/dist/.next/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/_not-found.html +1 -1
- package/dist/.next/.next/server/app/_not-found.rsc +4 -4
- package/dist/.next/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route.js +28 -3
- package/dist/.next/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js +26 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-data/confirm/route.js +1 -0
- package/dist/.next/.next/server/app/api/pull-data/confirm/route.js.nft.json +1 -0
- package/dist/.next/.next/server/app/api/pull-data/confirm/route_client-reference-manifest.js +1 -0
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js +26 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js +26 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js +28 -3
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js +28 -3
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/query/route.js +27 -2
- package/dist/.next/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/[name]/route.js +4 -4
- package/dist/.next/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/.next/server/app/api/tables/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/update/route.js +5 -0
- package/dist/.next/.next/server/app/api/update/route.js.nft.json +1 -0
- package/dist/.next/.next/server/app/api/update/route_client-reference-manifest.js +1 -0
- package/dist/.next/.next/server/app/index.html +3 -3
- package/dist/.next/.next/server/app/index.rsc +5 -5
- package/dist/.next/.next/server/app/page.js +13 -11
- package/dist/.next/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app-paths-manifest.json +5 -3
- package/dist/.next/.next/server/chunks/226.js +30 -0
- package/dist/.next/.next/server/chunks/336.js +1 -1
- package/dist/.next/.next/server/chunks/391.js +23 -0
- package/dist/.next/.next/server/chunks/452.js +1 -0
- package/dist/.next/.next/server/chunks/627.js +3 -3
- package/dist/.next/.next/server/chunks/638.js +3 -3
- package/dist/.next/.next/server/chunks/992.js +3 -3
- package/dist/.next/.next/server/pages/404.html +1 -1
- package/dist/.next/.next/server/pages/500.html +1 -1
- package/dist/.next/.next/server/pages/_app.js +1 -1
- package/dist/.next/.next/server/pages/_document.js +1 -1
- package/dist/.next/.next/server/pages/_error.js +1 -1
- package/dist/.next/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/.next/static/7XBqETNmhSxMXhw8iUpEa/_buildManifest.js +1 -0
- package/dist/.next/.next/static/chunks/176-9146975ef8699719.js +1 -0
- package/dist/.next/.next/static/chunks/{735-c9144179c6bd7d06.js → 735-b885dfec6353171d.js} +1 -1
- package/dist/.next/.next/static/chunks/app/api/cloudflare/route-b77846f372b01f38.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/databases/route-407794f8145d9a0b.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/migrations/sync/route-9f480f5590369a8f.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/migrations/sync-files/route-92010db279b4dd8e.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/pull-data/confirm/route-a02fe6d3cdd0a535.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/pull-remote/confirm/route-f401a03507d1da50.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/pull-remote/preview/route-3c53814b5cb8b6b0.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/push-remote/confirm/route-8f359249e907c63b.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/push-remote/preview/route-b51bf94f39c17a9d.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/query/route-87bae2d4aebaf859.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/tables/[name]/route-d20ca163b9c03e7c.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/tables/route-0f46f911562abcdf.js +1 -0
- package/dist/.next/.next/static/chunks/app/api/update/route-14edc1917760bce0.js +1 -0
- package/dist/.next/.next/static/chunks/app/page-5990cb23b8bd27c4.js +1 -0
- package/dist/.next/.next/static/css/674bee6608c638e4.css +3 -0
- package/dist/.next/.next/trace +3 -3
- package/dist/.next/.next/types/app/api/pull-data/confirm/route.ts +347 -0
- package/dist/.next/.next/types/app/api/update/route.ts +347 -0
- package/dist/.next/BUILD_ID +1 -1
- package/dist/.next/app-build-manifest.json +36 -22
- package/dist/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/build-manifest.json +2 -2
- package/dist/.next/cache/.rscinfo +1 -1
- package/dist/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/next-server.js.nft.json +1 -1
- package/dist/.next/prerender-manifest.json +1 -1
- package/dist/.next/server/app/_not-found/page.js +1 -1
- package/dist/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/_not-found.html +1 -1
- package/dist/.next/server/app/_not-found.rsc +4 -4
- package/dist/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/server/app/api/databases/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync/route.js +28 -3
- package/dist/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js +26 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-data/confirm/route.js +1 -0
- package/dist/.next/server/app/api/pull-data/confirm/route.js.nft.json +1 -0
- package/dist/.next/server/app/api/pull-data/confirm/route_client-reference-manifest.js +1 -0
- package/dist/.next/server/app/api/pull-remote/confirm/route.js +26 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js +26 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route.js +28 -3
- package/dist/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route.js +28 -3
- package/dist/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/query/route.js +27 -2
- package/dist/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/[name]/route.js +4 -4
- package/dist/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/server/app/api/tables/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/update/route.js +5 -0
- package/dist/.next/server/app/api/update/route.js.nft.json +1 -0
- package/dist/.next/server/app/api/update/route_client-reference-manifest.js +1 -0
- package/dist/.next/server/app/index.html +3 -3
- package/dist/.next/server/app/index.rsc +5 -5
- package/dist/.next/server/app/page.js +13 -11
- package/dist/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app-paths-manifest.json +8 -6
- package/dist/.next/server/chunks/226.js +30 -0
- package/dist/.next/server/chunks/336.js +1 -1
- package/dist/.next/server/chunks/391.js +23 -0
- package/dist/.next/server/chunks/452.js +1 -0
- package/dist/.next/server/chunks/627.js +3 -3
- package/dist/.next/server/chunks/638.js +3 -3
- package/dist/.next/server/chunks/992.js +3 -3
- package/dist/.next/server/pages/404.html +1 -1
- package/dist/.next/server/pages/500.html +1 -1
- package/dist/.next/server/pages/_app.js +1 -1
- package/dist/.next/server/pages/_document.js +1 -1
- package/dist/.next/server/pages/_error.js +1 -1
- package/dist/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/static/MoZBULXFiTFzrY1JVK_Df/_buildManifest.js +1 -0
- package/dist/.next/static/chunks/176-9146975ef8699719.js +1 -0
- package/dist/.next/static/chunks/{735-c9144179c6bd7d06.js → 735-b885dfec6353171d.js} +1 -1
- package/dist/.next/static/chunks/app/api/cloudflare/route-b77846f372b01f38.js +1 -0
- package/dist/.next/static/chunks/app/api/databases/route-407794f8145d9a0b.js +1 -0
- package/dist/.next/static/chunks/app/api/migrations/sync/route-9f480f5590369a8f.js +1 -0
- package/dist/.next/static/chunks/app/api/migrations/sync-files/route-92010db279b4dd8e.js +1 -0
- package/dist/.next/static/chunks/app/api/pull-data/confirm/route-a02fe6d3cdd0a535.js +1 -0
- package/dist/.next/static/chunks/app/api/pull-remote/confirm/route-f401a03507d1da50.js +1 -0
- package/dist/.next/static/chunks/app/api/pull-remote/preview/route-3c53814b5cb8b6b0.js +1 -0
- package/dist/.next/static/chunks/app/api/push-remote/confirm/route-8f359249e907c63b.js +1 -0
- package/dist/.next/static/chunks/app/api/push-remote/preview/route-b51bf94f39c17a9d.js +1 -0
- package/dist/.next/static/chunks/app/api/query/route-87bae2d4aebaf859.js +1 -0
- package/dist/.next/static/chunks/app/api/tables/[name]/route-d20ca163b9c03e7c.js +1 -0
- package/dist/.next/static/chunks/app/api/tables/route-0f46f911562abcdf.js +1 -0
- package/dist/.next/static/chunks/app/api/update/route-14edc1917760bce0.js +1 -0
- package/dist/.next/static/chunks/app/page-5990cb23b8bd27c4.js +1 -0
- package/dist/.next/static/css/674bee6608c638e4.css +3 -0
- package/dist/.next/trace +17 -14
- package/dist/.next/types/app/api/pull-data/confirm/route.ts +347 -0
- package/dist/.next/types/app/api/update/route.ts +347 -0
- package/dist/app/api/cloudflare/route.js +5 -1
- package/dist/app/api/databases/route.js +3 -4
- package/dist/app/api/migrations/sync/route.js +5 -3
- package/dist/app/api/pull-data/confirm/route.js +230 -0
- package/dist/app/api/pull-remote/confirm/route.js +24 -23
- package/dist/app/api/pull-remote/preview/route.js +4 -3
- package/dist/app/api/push-remote/preview/route.js +3 -2
- package/dist/app/api/query/route.js +11 -3
- package/dist/app/api/tables/[name]/route.js +3 -2
- package/dist/app/api/tables/route.js +6 -2
- package/dist/app/api/update/route.js +36 -0
- package/dist/app/app/api/cloudflare/route.js +5 -1
- package/dist/app/app/api/databases/route.js +3 -4
- package/dist/app/app/api/migrations/sync/route.js +5 -3
- package/dist/app/app/api/pull-data/confirm/route.js +230 -0
- package/dist/app/app/api/pull-remote/confirm/route.js +24 -23
- package/dist/app/app/api/pull-remote/preview/route.js +4 -3
- package/dist/app/app/api/push-remote/preview/route.js +3 -2
- package/dist/app/app/api/query/route.js +11 -3
- package/dist/app/app/api/tables/[name]/route.js +3 -2
- package/dist/app/app/api/tables/route.js +6 -2
- package/dist/app/app/api/update/route.js +36 -0
- package/dist/app/app/page.jsx +24 -14
- package/dist/app/page.jsx +24 -14
- package/dist/d1-studio.js +101 -58
- package/dist/lib/database-queue.js +34 -30
- package/dist/lib/find-wrangler-config.js +14 -8
- package/dist/lib/logger.js +44 -5
- package/dist/lib/migrations.js +4 -4
- package/dist/lib/schema-operations.js +4 -1
- package/dist/lib/sql-operations.js +85 -1
- package/package.json +3 -1
- package/scripts/studio.js +101 -58
- package/scripts/test.js +280 -82
- package/src/app/api/cloudflare/route.js +5 -1
- package/src/app/api/databases/route.js +3 -4
- package/src/app/api/migrations/sync/route.js +5 -3
- package/src/app/api/pull-data/confirm/route.js +230 -0
- package/src/app/api/pull-remote/confirm/route.js +24 -23
- package/src/app/api/pull-remote/preview/route.js +4 -3
- package/src/app/api/push-remote/preview/route.js +3 -2
- package/src/app/api/query/route.js +11 -3
- package/src/app/api/tables/[name]/route.js +3 -2
- package/src/app/api/tables/route.js +6 -2
- package/src/app/api/update/route.js +36 -0
- package/src/app/page.jsx +24 -14
- package/src/components/environment-handler.jsx +70 -16
- package/src/components/environment-select.jsx +6 -3
- package/src/components/pull-preview-toast.jsx +90 -63
- package/src/components/sidebar.jsx +25 -24
- package/src/components/update-banner.jsx +62 -0
- package/src/context/database-context.js +4 -4
- package/src/lib/database-queue.js +34 -30
- package/src/lib/find-wrangler-config.js +14 -8
- package/src/lib/logger.js +44 -5
- package/src/lib/migrations.js +4 -4
- package/src/lib/schema-operations.js +4 -1
- package/src/lib/sql-operations.js +85 -1
- package/dist/.next/.next/cache/webpack/client-production/3.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack.old +0 -0
- package/dist/.next/.next/server/chunks/603.js +0 -55
- package/dist/.next/.next/server/chunks/686.js +0 -23
- package/dist/.next/.next/static/HsZ8OanS5v86DqC9rErO-/_buildManifest.js +0 -1
- package/dist/.next/.next/static/chunks/422-6fa3c14fc64ad67b.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/cloudflare/route-3458d78022185d7f.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/databases/route-64255424877a9f72.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/migrations/sync/route-03766b3afcf043ba.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/migrations/sync-files/route-02fa291c8000dadf.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/pull-remote/confirm/route-7e05bb8920127abe.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/pull-remote/preview/route-0fa15f783e8a306c.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/push-remote/confirm/route-96691f1880e4ed14.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/push-remote/preview/route-a798679c67374552.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/query/route-e90d0030a5083e20.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/tables/[name]/route-1efe63e73b480e58.js +0 -1
- package/dist/.next/.next/static/chunks/app/api/tables/route-3772b4f480c4b4a4.js +0 -1
- package/dist/.next/.next/static/chunks/app/page-79049bfa6cc07e11.js +0 -1
- package/dist/.next/.next/static/css/cf41da7a0d47f779.css +0 -3
- package/dist/.next/.next/static/q6WmQmyONe88bMN0_jrC2/_buildManifest.js +0 -1
- package/dist/.next/server/chunks/603.js +0 -55
- package/dist/.next/server/chunks/686.js +0 -23
- package/dist/.next/static/Tk1fnz_CXLavm23ZEeChG/_buildManifest.js +0 -1
- package/dist/.next/static/Tk1fnz_CXLavm23ZEeChG/_ssgManifest.js +0 -1
- package/dist/.next/static/chunks/422-6fa3c14fc64ad67b.js +0 -1
- package/dist/.next/static/chunks/app/api/cloudflare/route-3458d78022185d7f.js +0 -1
- package/dist/.next/static/chunks/app/api/databases/route-64255424877a9f72.js +0 -1
- package/dist/.next/static/chunks/app/api/migrations/sync/route-03766b3afcf043ba.js +0 -1
- package/dist/.next/static/chunks/app/api/migrations/sync-files/route-02fa291c8000dadf.js +0 -1
- package/dist/.next/static/chunks/app/api/pull-remote/confirm/route-7e05bb8920127abe.js +0 -1
- package/dist/.next/static/chunks/app/api/pull-remote/preview/route-0fa15f783e8a306c.js +0 -1
- package/dist/.next/static/chunks/app/api/push-remote/confirm/route-96691f1880e4ed14.js +0 -1
- package/dist/.next/static/chunks/app/api/push-remote/preview/route-a798679c67374552.js +0 -1
- package/dist/.next/static/chunks/app/api/query/route-e90d0030a5083e20.js +0 -1
- package/dist/.next/static/chunks/app/api/tables/[name]/route-1efe63e73b480e58.js +0 -1
- package/dist/.next/static/chunks/app/api/tables/route-3772b4f480c4b4a4.js +0 -1
- package/dist/.next/static/chunks/app/page-79049bfa6cc07e11.js +0 -1
- package/dist/.next/static/css/cf41da7a0d47f779.css +0 -3
- /package/dist/.next/.next/static/{HsZ8OanS5v86DqC9rErO- → 7XBqETNmhSxMXhw8iUpEa}/_ssgManifest.js +0 -0
- /package/dist/.next/{.next/static/q6WmQmyONe88bMN0_jrC2 → static/MoZBULXFiTFzrY1JVK_Df}/_ssgManifest.js +0 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
// lib/find-wrangler-config.js
|
|
2
1
|
import { readFile } from 'fs/promises';
|
|
3
2
|
import { findUp } from 'find-up';
|
|
4
3
|
import { parse as parseToml } from '@iarna/toml';
|
|
5
4
|
import stripJsonComments from 'strip-json-comments';
|
|
6
5
|
import logger from './logger.js';
|
|
7
6
|
|
|
7
|
+
let cachedConfig = null;
|
|
8
|
+
let cachedProjectPath = null;
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Finds and parses the Wrangler configuration file.
|
|
12
|
+
* This function caches the result so that the configuration is read and logged only once per project path.
|
|
10
13
|
*
|
|
11
14
|
* @param {string} userProjectPath - The path where to look for the config file
|
|
12
15
|
* @returns {Promise<{config: object, projectPath: string}|null>}
|
|
@@ -17,8 +20,10 @@ export async function findWranglerConfig(userProjectPath) {
|
|
|
17
20
|
throw new Error('Project path is required and must be a string');
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
//
|
|
21
|
-
|
|
23
|
+
// Return the cached config if available for the same project path.
|
|
24
|
+
if (cachedConfig && cachedProjectPath === userProjectPath) {
|
|
25
|
+
return cachedConfig;
|
|
26
|
+
}
|
|
22
27
|
|
|
23
28
|
// Define the possible configuration file names in priority order.
|
|
24
29
|
const possibleFiles = ['wrangler.toml', 'wrangler.json', 'wrangler.jsonc'];
|
|
@@ -56,13 +61,14 @@ export async function findWranglerConfig(userProjectPath) {
|
|
|
56
61
|
config = JSON.parse(configContent);
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
// Cache the result.
|
|
65
|
+
cachedConfig = { config, projectPath: userProjectPath };
|
|
66
|
+
cachedProjectPath = userProjectPath;
|
|
67
|
+
|
|
68
|
+
return cachedConfig;
|
|
63
69
|
|
|
64
70
|
} catch (error) {
|
|
65
71
|
logger.error(`Error reading Wrangler configuration: ${error.message}`);
|
|
66
72
|
throw error;
|
|
67
73
|
}
|
|
68
|
-
}
|
|
74
|
+
}
|
package/src/lib/logger.js
CHANGED
|
@@ -2,18 +2,57 @@ import winston from 'winston';
|
|
|
2
2
|
|
|
3
3
|
const { combine, timestamp, printf, colorize } = winston.format;
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const isDevelopment = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === undefined;
|
|
6
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
7
|
+
// Check for DEBUG env var which is set by --debug flag
|
|
8
|
+
const isDebug = process.env.DEBUG === 'true';
|
|
9
|
+
|
|
10
|
+
const logFormat = printf(({ level, message, timestamp, ...metadata }) => {
|
|
11
|
+
let msg = `${timestamp} ${level}: ${message}`;
|
|
12
|
+
// Add metadata if present
|
|
13
|
+
if (Object.keys(metadata).length > 0) {
|
|
14
|
+
msg += ` ${JSON.stringify(metadata)}`;
|
|
15
|
+
}
|
|
16
|
+
return msg;
|
|
7
17
|
});
|
|
8
18
|
|
|
9
19
|
const logger = winston.createLogger({
|
|
10
|
-
level
|
|
20
|
+
// Set log level based on environment and debug flag
|
|
21
|
+
level: isDebug ? 'debug' : (isProduction ? 'warn' : 'info'),
|
|
11
22
|
format: combine(
|
|
12
23
|
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
13
24
|
colorize(),
|
|
14
25
|
logFormat
|
|
15
26
|
),
|
|
16
|
-
transports: [
|
|
27
|
+
transports: [
|
|
28
|
+
new winston.transports.Console({
|
|
29
|
+
level: isDebug ? 'debug' : (isProduction ? 'warn' : 'info'),
|
|
30
|
+
silent: process.env.NODE_ENV === 'test'
|
|
31
|
+
})
|
|
32
|
+
]
|
|
17
33
|
});
|
|
18
34
|
|
|
19
|
-
|
|
35
|
+
// Add helper methods
|
|
36
|
+
logger.logRequest = (method, path, params = {}) => {
|
|
37
|
+
logger.debug(`Request: ${method} ${path}`, params);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
logger.logError = (error, source = 'unknown') => {
|
|
41
|
+
logger.error(`Error in ${source}: ${error.message}`, {
|
|
42
|
+
error: error.stack || error.message,
|
|
43
|
+
source
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
logger.shouldLog = (level) => {
|
|
48
|
+
const currentLevel = logger.level;
|
|
49
|
+
const levels = {
|
|
50
|
+
error: 0,
|
|
51
|
+
warn: 1,
|
|
52
|
+
info: 2,
|
|
53
|
+
debug: 3
|
|
54
|
+
};
|
|
55
|
+
return levels[level] <= levels[currentLevel];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default logger;
|
package/src/lib/migrations.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
tableExists
|
|
17
17
|
} from './sql-operations.js';
|
|
18
18
|
import { analyzeDependencies } from '@/lib/schema-operations';
|
|
19
|
+
import logger from './logger.js';
|
|
19
20
|
|
|
20
21
|
const execAsync = promisify(exec);
|
|
21
22
|
|
|
@@ -67,7 +68,7 @@ export async function initMigrationsTable(projectDir, databaseName, environment
|
|
|
67
68
|
);
|
|
68
69
|
}
|
|
69
70
|
} catch (error) {
|
|
70
|
-
|
|
71
|
+
logger.error(`Failed to initialize migrations table in ${environment}:`, error);
|
|
71
72
|
throw error;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -173,7 +174,6 @@ export async function getRemoteMigrations(projectDir, databaseName, env) {
|
|
|
173
174
|
* @param {Object} migrationData { name, checksum }
|
|
174
175
|
* @param {('local'|'remote')} environment
|
|
175
176
|
*/
|
|
176
|
-
// Update tracking function to handle both cases
|
|
177
177
|
export async function trackMigration(projectDir, databaseName, { name, checksum }, environment = 'local') {
|
|
178
178
|
const flag = environment === 'remote' ? '--remote' : '--local';
|
|
179
179
|
|
|
@@ -215,7 +215,7 @@ export async function trackMigration(projectDir, databaseName, { name, checksum
|
|
|
215
215
|
{ cwd: projectDir }
|
|
216
216
|
);
|
|
217
217
|
} catch (error) {
|
|
218
|
-
|
|
218
|
+
logger.error('Failed to track migration:', error);
|
|
219
219
|
throw error;
|
|
220
220
|
}
|
|
221
221
|
}
|
|
@@ -273,7 +273,7 @@ export async function compareMigrations(projectDir, databaseName) {
|
|
|
273
273
|
count: migrationMap.size
|
|
274
274
|
};
|
|
275
275
|
} catch (error) {
|
|
276
|
-
|
|
276
|
+
logger.error('Failed to compare migrations:', error);
|
|
277
277
|
throw error;
|
|
278
278
|
}
|
|
279
279
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// schema-operations.js
|
|
2
|
+
|
|
2
3
|
import { executeSQL, ErrorTypes } from './sql-operations.js';
|
|
4
|
+
import logger from './logger.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Retrieves the current database schema (tables, indexes, triggers),
|
|
@@ -24,6 +26,7 @@ export async function getCurrentSchema(projectDir, databaseName, env = {}, remot
|
|
|
24
26
|
const parsed = JSON.parse(result);
|
|
25
27
|
return parsed[0]?.results || [];
|
|
26
28
|
} catch (error) {
|
|
29
|
+
logger.error('Failed to get current schema:', error);
|
|
27
30
|
throw {
|
|
28
31
|
type: ErrorTypes.EXECUTION_ERROR,
|
|
29
32
|
message: 'Failed to get current schema',
|
|
@@ -100,4 +103,4 @@ export function orderTables(dependencies) {
|
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
return ordered;
|
|
103
|
-
}
|
|
106
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { promisify } from 'util';
|
|
4
4
|
import { exec } from 'child_process';
|
|
5
|
+
import logger from '@/lib/logger';
|
|
5
6
|
|
|
6
7
|
const execAsync = promisify(exec);
|
|
7
8
|
|
|
@@ -293,13 +294,19 @@ export async function executeSQL(projectDir, databaseName, sql, env = {}, remote
|
|
|
293
294
|
const npxCommand = isWindows ? 'npx.cmd' : 'npx';
|
|
294
295
|
const executionFlag = remote ? '--remote' : '--local';
|
|
295
296
|
const command = `${npxCommand} wrangler d1 execute ${databaseName} ${executionFlag} --command="${cleanSQL.replace(/"/g, '\\"')}"`;
|
|
297
|
+
|
|
298
|
+
// Only log in development
|
|
299
|
+
if (logger.shouldLog('debug')) {
|
|
300
|
+
logger.debug('Executing command:', command);
|
|
301
|
+
}
|
|
302
|
+
|
|
296
303
|
const execOptions = {
|
|
297
304
|
cwd: projectDir,
|
|
298
305
|
env: { ...process.env, ...env },
|
|
299
306
|
maxBuffer: 1024 * 1024 * 10,
|
|
300
307
|
shell: true
|
|
301
308
|
};
|
|
302
|
-
console.log('Executing command:', command);
|
|
309
|
+
// console.log('Executing command:', command);
|
|
303
310
|
const { stdout, stderr } = await execAsync(command, execOptions);
|
|
304
311
|
if (stderr && !stderr.includes('🌀')) {
|
|
305
312
|
throw new Error(stderr);
|
|
@@ -335,6 +342,83 @@ export async function executeSQL(projectDir, databaseName, sql, env = {}, remote
|
|
|
335
342
|
}
|
|
336
343
|
}
|
|
337
344
|
|
|
345
|
+
/**
|
|
346
|
+
* Fetches the latest `limit` records for a given table from the remote database.
|
|
347
|
+
*
|
|
348
|
+
* This implementation uses the executeSQL function with the remote flag enabled.
|
|
349
|
+
* It orders the results based on the provided ordering column. If no ordering column is provided,
|
|
350
|
+
* it falls back to the default "id" column.
|
|
351
|
+
*
|
|
352
|
+
* @param {string} projectDir - The project directory.
|
|
353
|
+
* @param {string} databaseName - The D1 database name.
|
|
354
|
+
* @param {string} tableName - The table to fetch records for.
|
|
355
|
+
* @param {object} env - Environment variables (including credentials).
|
|
356
|
+
* @param {number} limit - The number of records to fetch.
|
|
357
|
+
* @param {string} [orderingColumn="id"] - The column to order by.
|
|
358
|
+
* @returns {Promise<Array<object>>} Array of row objects.
|
|
359
|
+
*/
|
|
360
|
+
export async function fetchRemoteTableData(
|
|
361
|
+
projectDir,
|
|
362
|
+
databaseName,
|
|
363
|
+
tableName,
|
|
364
|
+
env,
|
|
365
|
+
limit,
|
|
366
|
+
orderingColumn = "id"
|
|
367
|
+
) {
|
|
368
|
+
// Use the provided ordering column; if not provided, default to "id".
|
|
369
|
+
const query = `SELECT * FROM "${tableName}" ORDER BY "${orderingColumn}" DESC LIMIT ${limit};`;
|
|
370
|
+
try {
|
|
371
|
+
// Execute the SQL command on the remote database.
|
|
372
|
+
const result = await executeSQL(projectDir, databaseName, query, env, true);
|
|
373
|
+
|
|
374
|
+
// ExecuteSQL returns stdout that should contain a JSON array starting from a '['.
|
|
375
|
+
const jsonStart = result.indexOf('[');
|
|
376
|
+
if (jsonStart === -1) {
|
|
377
|
+
throw new Error(`Unexpected result format: ${result}`);
|
|
378
|
+
}
|
|
379
|
+
const jsonStr = result.substring(jsonStart);
|
|
380
|
+
const parsed = JSON.parse(jsonStr);
|
|
381
|
+
// Assuming the structure: parsed[0].results contains the rows.
|
|
382
|
+
const rows = parsed[0]?.results || [];
|
|
383
|
+
return rows;
|
|
384
|
+
} catch (error) {
|
|
385
|
+
logger.error(`Error fetching remote data for table ${tableName}:`, error);
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Generates a bulk insert SQL statement for the specified table and rows.
|
|
392
|
+
*
|
|
393
|
+
* This function constructs a single INSERT statement that inserts multiple rows.
|
|
394
|
+
* It escapes single quotes in string values. You may need to extend this for
|
|
395
|
+
* additional data types (e.g., numbers, dates, booleans) or more complex structures.
|
|
396
|
+
*
|
|
397
|
+
* @param {string} tableName - The table to insert into.
|
|
398
|
+
* @param {Array<object>} rows - An array of objects, each representing a row.
|
|
399
|
+
* @returns {string} The bulk insert SQL statement.
|
|
400
|
+
*/
|
|
401
|
+
export function generateBulkInsertSQL(tableName, rows) {
|
|
402
|
+
if (!rows || rows.length === 0) return '';
|
|
403
|
+
|
|
404
|
+
// Get the list of columns from the first row object.
|
|
405
|
+
const columns = Object.keys(rows[0]);
|
|
406
|
+
const columnList = columns.map(col => `"${col}"`).join(', ');
|
|
407
|
+
|
|
408
|
+
// Build the values list for each row.
|
|
409
|
+
const valuesList = rows.map(row => {
|
|
410
|
+
const values = columns.map(col => {
|
|
411
|
+
const value = row[col];
|
|
412
|
+
if (value === null || value === undefined) return 'NULL';
|
|
413
|
+
// For simplicity, treat the value as a string.
|
|
414
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
415
|
+
}).join(', ');
|
|
416
|
+
return `(${values})`;
|
|
417
|
+
}).join(', ');
|
|
418
|
+
|
|
419
|
+
return `INSERT INTO "${tableName}" (${columnList}) VALUES ${valuesList};`;
|
|
420
|
+
}
|
|
421
|
+
|
|
338
422
|
// ---------------------------------------------------------------------
|
|
339
423
|
// SQL Formatting and Helper Functions
|
|
340
424
|
// ---------------------------------------------------------------------
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
exports.id=603,exports.ids=[603],exports.modules={6487:()=>{},8335:()=>{},9999:(e,t,r)=>{"use strict";r.d(t,{S:()=>u});var a=r(9748),s=r(3149),i=r(2537),n=r(6789),l=r(6399);let{combine:E,timestamp:o,printf:c,colorize:m}=l.format,T=c(({level:e,message:t,timestamp:r})=>`${r} ${e}: ${t}`),d=l.createLogger({level:"info",format:E(o({format:"YYYY-MM-DD HH:mm:ss"}),m(),T),transports:[new l.transports.Console]});async function u(e){try{let t;if(!e||"string"!=typeof e)throw Error("Project path is required and must be a string");let r=null,l=null;for(let t of["wrangler.toml","wrangler.json","wrangler.jsonc"])if(r=await (0,s.dJ)(t,{cwd:e})){l=t;break}if(!r)return d.warn(`No Wrangler configuration file found in: ${e}`),null;d.info(`Found ${l} at: ${r}`);let E=await (0,a.readFile)(r,"utf-8");return l.endsWith(".toml")?t=(0,i.parse)(E):(l.endsWith(".jsonc")&&(E=(0,n.A)(E)),t=JSON.parse(E)),{config:t,projectPath:e}}catch(e){throw d.error(`Error reading Wrangler configuration: ${e.message}`),e}}},961:(e,t,r)=>{"use strict";r.d(t,{CM:()=>p,GS:()=>u,Gc:()=>A,JD:()=>d,Sl:()=>N,ai:()=>R,hI:()=>f,k0:()=>m});var a=r(9748),s=r(8354),i=r(9646),n=r(5511),l=r(3873),E=r(9421),o=r(4218);let c=(0,s.promisify)(i.exec);async function m(e,t,r="local",a=!1){let s="remote"===r?"--remote":"--local",i="remote"===r?`
|
|
2
|
-
CREATE TABLE IF NOT EXISTS d1_migrations (
|
|
3
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4
|
-
name TEXT NOT NULL UNIQUE,
|
|
5
|
-
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
6
|
-
);
|
|
7
|
-
`:`
|
|
8
|
-
CREATE TABLE IF NOT EXISTS d1_migrations (
|
|
9
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
10
|
-
name TEXT NOT NULL UNIQUE,
|
|
11
|
-
checksum TEXT NULL,
|
|
12
|
-
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
13
|
-
);
|
|
14
|
-
`;try{await c(`wrangler d1 execute ${t} ${s} --command="${i.replace(/"/g,'\\"')}"`,{cwd:e}),a&&await c(`wrangler d1 execute ${t} ${s} --command="${"DELETE FROM d1_migrations;".replace(/"/g,'\\"')}"`,{cwd:e})}catch(e){throw console.error(`Failed to initialize migrations table in ${r}:`,e),e}}function T(e){let t=new Date().toISOString().replace(/[^0-9]/g,"").slice(0,-3),r=e.type.toLowerCase().replace(/_/g,"-");if("CREATE_INDEX"===e.type){let r=e.description.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-_]/g,"");return`${t}_create-index_${r}.sql`}{let a=`${t}_${{"create-table":"create-table","alter-table":"alter-table","drop-table":"drop-table","drop-index":"drop-index","create-view":"create-view","drop-view":"drop-view","add-foreign-key":"add-foreign-key","drop-foreign-key":"drop-foreign-key","add-constraint":"add-constraint","drop-constraint":"drop-constraint"}[r]||r}_${e.tableName}`;return"ALTER_TABLE"===e.type&&e.description&&(a+=`_${e.description}`),(a=a.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-_]/g,""))+".sql"}}async function d(e){let t=await (0,a.readFile)(e,"utf8");try{let e=(0,E.By)(t);return(0,E.Gq)(e),{isValid:!0,statement:e}}catch(e){return{isValid:!1,errors:e}}}async function u(e,t,r){try{let a=await (0,E.KK)(e,t,"SELECT name, applied_at FROM d1_migrations ORDER BY applied_at;",r,!0);if("string"==typeof a){let e=a.indexOf("[");if(-1!==e){let t=a.substring(e),r=JSON.parse(t);return r[0]?.results||[]}}return[]}catch(e){throw{type:E.wU.EXECUTION_ERROR,message:"Failed to get remote migrations",details:{error:e.message,suggestions:["Check remote database permissions","Verify credentials and connection"]}}}}async function R(e,t,{name:r,checksum:a},s="local"){let i="remote"===s?"--remote":"--local";if("local"===s&&a)try{await c(`wrangler d1 execute ${t} ${i} --command="SELECT checksum FROM d1_migrations LIMIT 1;"`,{cwd:e}).catch(()=>!1)||await c(`wrangler d1 execute ${t} ${i} --command="ALTER TABLE d1_migrations ADD COLUMN checksum TEXT;"`,{cwd:e})}catch(e){}let n="remote"!==s&&a?`
|
|
15
|
-
INSERT OR REPLACE INTO d1_migrations (name, checksum, applied_at)
|
|
16
|
-
VALUES ('${r}', '${a}', CURRENT_TIMESTAMP);
|
|
17
|
-
`:`
|
|
18
|
-
INSERT OR REPLACE INTO d1_migrations (name, applied_at)
|
|
19
|
-
VALUES ('${r}', CURRENT_TIMESTAMP);
|
|
20
|
-
`;try{await c(`wrangler d1 execute ${t} ${i} --command="${n.replace(/"/g,'\\"')}"`,{cwd:e})}catch(e){throw console.error("Failed to track migration:",e),e}}async function p(e,t,{name:r,checksum:a},s={},i=!1){let n=i||!a?`
|
|
21
|
-
INSERT OR REPLACE INTO d1_migrations (name, applied_at)
|
|
22
|
-
VALUES ('${r}', CURRENT_TIMESTAMP);
|
|
23
|
-
`:`
|
|
24
|
-
INSERT OR REPLACE INTO d1_migrations (name, checksum, applied_at)
|
|
25
|
-
VALUES ('${r}', '${a}', CURRENT_TIMESTAMP);
|
|
26
|
-
`;try{await (0,E.KK)(e,t,n,s,i)}catch(e){throw{type:E.wU.EXECUTION_ERROR,message:`Failed to record migration ${r}`,details:{file:r,error:e.message,suggestions:["Check if migration is already recorded"]}}}}async function f(e,t){try{let r=await u(e,t,{}),a=new Map(r.map(e=>[e.name,e]));return{applied:Array.from(a.keys()),count:a.size}}catch(e){throw console.error("Failed to compare migrations:",e),e}}function N(e){return(0,n.createHash)("sha256").update(e).digest("hex")}async function A(e,t,r){try{let s=l.join(e,"migrations");await (0,a.mkdir)(s,{recursive:!0});let i=[],n=[],c=[];for(let e of r)e.type===E.Pg.DATA_MODIFICATION?c.push(e):n.push(e);let m=new Map,d="__no_table__";for(let e of n){let t=e.tableName?e.tableName.toLowerCase():d;m.has(t)||m.set(t,[]),m.get(t).push(e)}let u=[...m.keys()].filter(e=>e!==d),p=[];if(u.length>0){let e=u.map(e=>m.get(e)[0]);p=(0,o.IC)(e)}for(let r of p){for(let n of m.get(r)||[])try{if(n.type===E.Pg.DROP_TABLE&&!await (0,E.F9)(e,t,{},n.tableName,!1))throw Error(`no such table: ${n.tableName}`);let r=await (0,E.KK)(e,t,n.sql);if(r&&(r.toLowerCase().includes("syntax error")||r.toLowerCase().includes("sqlite_error")))throw Error(r);let o=T(n),c=l.join(s,o),m=(0,E.tn)(n.sql);await (0,a.writeFile)(c,m,"utf8");let d=N(n.sql);await R(e,t,{name:o,checksum:d},"local"),i.push({type:n.type,table:n.tableName,migration:o,checksum:d})}catch(e){throw e}m.delete(r)}if(m.has(d))for(let r of m.get(d))try{await (0,E.KK)(e,t,r.sql);let n=T(r),o=l.join(s,n),c=(0,E.tn)(r.sql);await (0,a.writeFile)(o,c,"utf8");let m=N(r.sql);await R(e,t,{name:n,checksum:m},"local"),i.push({type:r.type,table:r.tableName||null,migration:n,checksum:m})}catch(e){throw e}for(let r of c)try{await (0,E.KK)(e,t,r.sql),i.push({type:r.type,table:r.tableName||null,executed:!0})}catch(e){throw e}return i}catch(e){throw e}}},4218:(e,t,r)=>{"use strict";r.d(t,{IC:()=>i,ZX:()=>s});var a=r(9421);async function s(e,t,r={},i=!1){let n=`
|
|
27
|
-
SELECT name, type, sql
|
|
28
|
-
FROM sqlite_master
|
|
29
|
-
WHERE type IN ('table', 'index', 'trigger')
|
|
30
|
-
AND name NOT LIKE 'sqlite_%'
|
|
31
|
-
AND name != 'd1_migrations';
|
|
32
|
-
`;try{let s=await (0,a.KK)(e,t,n,r,i),l=JSON.parse(s);return l[0]?.results||[]}catch(e){throw{type:a.wU.EXECUTION_ERROR,message:"Failed to get current schema",details:{error:e.message,suggestions:["Check database permissions"]}}}}function i(e){let t=new Map;return e.filter(e=>"DATA_MODIFICATION"!==e.type).forEach(e=>{let r=(e.name||e.tableName).toLowerCase();if(t.has(r)||t.set(r,new Set),"CREATE_TABLE"===e.type){let a=e.sql.match(/FOREIGN\s+KEY\s*\([^)]+\)\s+REFERENCES\s+(\w+)/gi);a&&a.forEach(e=>{let a=e.match(/REFERENCES\s+(\w+)/i)[1].toLowerCase();t.get(r).add(a)})}}),function(e){let t=[],r=new Set,a=new Set;for(let s of e.keys())r.has(s)||function s(i){if(a.has(i))throw Error(`Circular dependency detected for table: ${i}`);if(!r.has(i)){for(let t of(a.add(i),e.get(i)||new Set)){if(!e.has(t))throw Error(`Missing table dependency: ${t}`);s(t)}a.delete(i),r.add(i),t.push(i)}}(s);return t}(t)}},9421:(e,t,r)=>{"use strict";r.d(t,{By:()=>o,F9:()=>R,Gq:()=>c,KK:()=>f,Pg:()=>n,QQ:()=>E,bp:()=>u,mA:()=>p,sP:()=>h,tn:()=>I,wU:()=>l,z6:()=>N});var a=r(8354),s=r(9646);let i=(0,a.promisify)(s.exec),n={CREATE_TABLE:"CREATE_TABLE",ALTER_TABLE:"ALTER_TABLE",DROP_TABLE:"DROP_TABLE",CREATE_INDEX:"CREATE_INDEX",DROP_INDEX:"DROP_INDEX",DATA_MODIFICATION:"DATA_MODIFICATION"},l={VALIDATION_ERROR:"VALIDATION_ERROR",SYNTAX_ERROR:"SYNTAX_ERROR",EXECUTION_ERROR:"EXECUTION_ERROR",DEPENDENCY_ERROR:"DEPENDENCY_ERROR"};function E(e){return e.type!==n.DATA_MODIFICATION}function o(e){let t=e.trim().replace(/\s+/g," "),r=t.toUpperCase();if(r.startsWith("CREATE TABLE"))return{type:n.CREATE_TABLE,tableName:m(t,"CREATE TABLE"),sql:t,description:"create-table"};if(r.startsWith("ALTER TABLE")){let e=m(t,"ALTER TABLE"),a="";if(r.includes("RENAME")){let e=t.match(/RENAME\s+(?:COLUMN\s+)?([\w$]+)\s+TO\s+([\w$]+)/i);e&&(a=`rename-${e[1]}-to-${e[2]}`)}else if(r.includes("ADD COLUMN")){let e=t.match(/ADD\s+COLUMN\s+([\w$]+)(\s+[\w()]+)?/i);if(e){let t=e[1],r=e[2]?e[2].trim().replace(/\s+/g,"-"):"";a=r?`add-${t}-${r}`:`add-${t}`}}else if(r.includes("DROP COLUMN")){let e=t.match(/DROP\s+COLUMN\s+([\w$]+)/i);e&&(a=`drop-${e[1]}`)}else if(r.includes("MODIFY COLUMN")||r.includes("CHANGE COLUMN")){let e=t.match(/(?:MODIFY|CHANGE)\s+COLUMN\s+([\w$]+)(\s+[\w()]+)?/i);if(e){let t=e[1],r=e[2]?e[2].trim().replace(/\s+/g,"-"):"";a=r?`modify-${t}-to-${r}`:`modify-${t}`}}return{type:n.ALTER_TABLE,tableName:e,sql:t,description:a}}if(r.startsWith("DROP TABLE"))return{type:n.DROP_TABLE,tableName:m(t,"DROP TABLE"),sql:t,description:"drop-table"};if(r.startsWith("CREATE INDEX")||r.startsWith("CREATE UNIQUE INDEX")){let e=T(t),r=t.match(/INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?([\w$]+)/i),a=r?r[1]:"",s=t.match(/ON\s+[\w$]+\s*\(([^)]+)\)/i),i=(s?s[1].trim():"").replace(/\s+/g,"").replace(/,/g,"-").toLowerCase(),l=a;return i&&!l.toLowerCase().includes(i)&&(l+=`-${i}`),{type:n.CREATE_INDEX,tableName:e,sql:t,description:l}}if(r.startsWith("DROP INDEX")){let e=T(t),r=t.match(/DROP\s+INDEX\s+(?:IF\s+EXISTS\s+)?([\w$]+)/i),a=r?r[1]:"";return{type:n.DROP_INDEX,tableName:e,sql:t,description:a?`drop-index-${a}`:"drop-index"}}return{type:n.DATA_MODIFICATION,sql:t,description:"data-modification"}}function c(e){if(e.type!==n.DATA_MODIFICATION&&!e.tableName)throw{type:l.VALIDATION_ERROR,message:`Invalid SQL statement: unable to determine table name for "${e.type}".`,details:{sql:e.sql}};return e}function m(e,t){let r=e.match(RegExp(`${t}\\s+(?:IF\\s+(?:NOT\\s+)?EXISTS\\s+)?([\\w_]+)`,"i"));return r?r[1]:null}function T(e){let t=e.match(/ON\s+([\w_]+)/i);return t?t[1]:null}async function d(e){let t=e.match(/^\d+_create[-_]table[_-](.+)\.sql$/i);return t||(t=e.match(/^\d+_create[-](.+)-table\.sql$/i))||(t=e.match(/^\d+_alter[-_]table[_-](.+?)(?:[_-].+)?\.sql$/i))||(t=e.match(/^\d+_alter[-](.+?)-table(?:[_-].+)?\.sql$/i))||(t=e.match(/^\d+_create[-_]index[-_](.+)\.sql$/i))?t[1]:null}function u(e){return e.split("\n").filter(e=>!e.trim().startsWith("--")).join("\n").trim()}async function R(e,t,r,a,s=!1){let i=`SELECT name FROM sqlite_master WHERE type='table' AND name = '${a}' COLLATE NOCASE;`,n=await f(e,t,i,r,s);try{let e=n.indexOf("[");if(-1!==e){let t=n.substring(e),r=JSON.parse(t);return(r[0]?.results||[]).length>0}return!1}catch(e){return console.error("Error parsing tableExists result:",e),!1}}function p(e){return e.replace(/--.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"").trim().split(";").map(e=>e.trim()).filter(e=>e.length>0).map(e=>o(e+";"))}async function f(e,t,r,a={},s=!1){try{let n=r.trim().replace(/\s+/g," "),l=n.toUpperCase();(l.startsWith("CREATE INDEX")||l.startsWith("CREATE UNIQUE INDEX"))&&!l.includes("IF NOT EXISTS")&&(n=l.startsWith("CREATE UNIQUE INDEX")?n.replace(/CREATE\s+UNIQUE\s+INDEX/i,"CREATE UNIQUE INDEX IF NOT EXISTS"):n.replace(/CREATE\s+INDEX/i,"CREATE INDEX IF NOT EXISTS"));let E="win32"===process.platform,o=`${E?"npx.cmd":"npx"} wrangler d1 execute ${t} ${s?"--remote":"--local"} --command="${n.replace(/"/g,'\\"')}"`,c={cwd:e,env:{...process.env,...a},maxBuffer:0xa00000,shell:!0};console.log("Executing command:",o);let{stdout:m,stderr:T}=await i(o,c);if(T&&!T.includes("\uD83C\uDF00"))throw Error(T);try{let e=m.indexOf("[");if(-1!==e)return m.substring(e)}catch(e){console.warn("JSON parse warning:",e)}return m}catch(e){throw console.error("SQL Execution error:",e),{type:l.EXECUTION_ERROR,message:"Failed to execute SQL command",details:{command:e.cmd,stderr:e.stderr,stdout:e.stdout,originalError:e.message,suggestions:["Ensure Node.js and Wrangler are installed","Check npx in PATH","Verify the D1 database exists and is configured","Check wrangler.toml configuration"]}}}}function N(e){let t=e.trim(),r=t.toUpperCase();return r.startsWith("CREATE TABLE")?function(e){let t=e.match(/CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(\w+)\s*\(([\s\S]*)\)/i);if(!t)return e;let[,r,a]=t,s=A(a).map(e=>e.trim()).filter(Boolean);return`CREATE TABLE ${r} (
|
|
33
|
-
${s.join(",\n ")}
|
|
34
|
-
);`}(t):r.startsWith("CREATE INDEX")||r.startsWith("CREATE UNIQUE INDEX")?function(e){let t=e.match(/CREATE\s+(UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?(\w+)\s+ON\s+(\w+)\s*\((.*)\)/i);if(!t)return e;let[,r,a,s,i]=t,n=i.split(",").map(e=>e.trim()).join(", ");return`CREATE ${r||""}INDEX ${a} ON ${s} (${n});`}(t):r.startsWith("ALTER TABLE")?function(e){let t=e.match(/ALTER\s+TABLE\s+(\w+)\s+(.*)/i);if(!t)return e;let[,r,a]=t,s=A(a);return 1===s.length?`ALTER TABLE ${r} ${s[0]};`:`ALTER TABLE ${r}
|
|
35
|
-
${s.map((e,t)=>` ${e}${t<s.length-1?",":";"}`).join("\n")}`}(t):r.startsWith("DROP TABLE")||r.startsWith("DROP INDEX")?function(e){let t=e.match(/DROP\s+(TABLE|INDEX)\s+(?:IF\s+EXISTS\s+)?(\w+)/i);if(!t)return e;let[,r,a]=t;return`DROP ${r} IF EXISTS ${a};`}(t):r.startsWith("INSERT INTO")?function(e){let t=e.match(/INSERT\s+INTO\s+(\w+)\s*(\([^)]+\))?\s*VALUES\s*(.+)/i);if(!t)return e;let[,r,a,s]=t,i=A(s);return`INSERT INTO ${r}${a?` ${a}`:""}
|
|
36
|
-
VALUES
|
|
37
|
-
`+i.map((e,t)=>` ${e}${t<i.length-1?",":";"}`).join("\n")}(t):r.startsWith("UPDATE")?function(e){let t=e.match(/UPDATE\s+(\w+)\s+SET\s+(.+?)(?:\s+WHERE\s+(.+))?$/i);if(!t)return e;let[,r,a,s]=t,i=A(a),n=`UPDATE ${r}
|
|
38
|
-
SET
|
|
39
|
-
${i.map(e=>` ${e.trim()}`).join(",\n")}`;return s&&(n+=`
|
|
40
|
-
WHERE
|
|
41
|
-
${s.trim()}`),n+";"}(t):r.startsWith("DELETE FROM")?function(e){let t=e.match(/DELETE\s+FROM\s+(\w+)(?:\s+WHERE\s+(.+))?$/i);if(!t)return e;let[,r,a]=t,s=`DELETE FROM ${r}`;return a&&(s+=`
|
|
42
|
-
WHERE
|
|
43
|
-
${a.trim()}`),s+";"}(t):r.startsWith("SELECT")?function(e){let t=e.match(/SELECT\s+(.+?)\s+FROM\s+(.+?)(?:\s+WHERE\s+(.+?))?(?:\s+GROUP\s+BY\s+(.+?))?(?:\s+HAVING\s+(.+?))?(?:\s+ORDER\s+BY\s+(.+?))?(?:\s+LIMIT\s+(.+?))?$/i);if(!t)return e;let[,r,a,s,i,n,l,E]=t,o=`SELECT
|
|
44
|
-
${r.split(",").map(e=>e.trim()).join(",\n ")}
|
|
45
|
-
FROM
|
|
46
|
-
${a.trim()}`;return s&&(o+=`
|
|
47
|
-
WHERE
|
|
48
|
-
${s.trim()}`),i&&(o+=`
|
|
49
|
-
GROUP BY
|
|
50
|
-
${i.trim()}`),n&&(o+=`
|
|
51
|
-
HAVING
|
|
52
|
-
${n.trim()}`),l&&(o+=`
|
|
53
|
-
ORDER BY
|
|
54
|
-
${l.trim()}`),E&&(o+=`
|
|
55
|
-
LIMIT ${E.trim()}`),o+";"}(t):t+";"}function A(e){let t=[],r="",a=0,s=!1,i="";for(let n of e)'"'===n&&"\\"!==i&&(s=!s),!s&&("("===n&&a++,")"===n&&a--),","!==n||0!==a||s?r+=n:(t.push(r.trim()),r=""),i=n;return r.trim()&&t.push(r.trim()),t}function I(e){return e.split(";").map(e=>e.trim()).filter(e=>e.length>0).map(e=>N(e)).join("\n\n")+"\n"}async function h(e,t,r,a){try{let s;let i=await d(r);if(i){let r=await f(e,t,`SELECT sql FROM sqlite_master WHERE type='table' AND name='${i}';`,a,!0);try{let e=JSON.parse(r);s=e[0]?.results?.[0]?.sql}catch(e){console.error("Error parsing sqlite_master result:",e)}}if(!s&&r.includes("create-index")){let i=r.match(/create-index[-_]([^_.]+)/);if(i){let r=await f(e,t,`SELECT sql FROM sqlite_master WHERE type='index' AND name='${i[1]}';`,a,!0),n=JSON.parse(r);s=n[0]?.results?.[0]?.sql}}if(!s&&i){let r=await f(e,t,`SELECT sql FROM sqlite_master WHERE name LIKE '%${i}%' LIMIT 1;`,a,!0);try{let e=JSON.parse(r);s=e[0]?.results?.[0]?.sql}catch(e){console.error("Error parsing fallback result:",e)}}if(!s)throw Error(`Could not retrieve SQL content for migration: ${r}`);return s+";"}catch(e){throw{type:l.EXECUTION_ERROR,message:`Failed to get migration file content: ${e.message}`,details:{file:r,error:e.message,suggestions:["Check if the table exists in the remote database","Verify the migration filename follows the expected pattern","Ensure you have permissions to access the remote database"]}}}}}};
|