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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
4
|
import { findWranglerConfig } from '@/lib/find-wrangler-config.js';
|
|
5
|
+
import logger from '@/lib/logger';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Validates the provided Cloudflare credentials by fetching databases.
|
|
@@ -81,6 +82,7 @@ export async function POST(req) {
|
|
|
81
82
|
|
|
82
83
|
// Check if the project directory is set.
|
|
83
84
|
if (!projectDir) {
|
|
85
|
+
logger.error('Project directory not configured');
|
|
84
86
|
return NextResponse.json(
|
|
85
87
|
{ error: 'Project directory not configured' },
|
|
86
88
|
{ status: 500 }
|
|
@@ -93,6 +95,7 @@ export async function POST(req) {
|
|
|
93
95
|
// Retrieve the Wrangler configuration using the centralized helper.
|
|
94
96
|
const wranglerResult = await findWranglerConfig(projectDir);
|
|
95
97
|
if (!wranglerResult || !wranglerResult.config) {
|
|
98
|
+
logger.error('No Wrangler configuration file found in project directory');
|
|
96
99
|
return NextResponse.json(
|
|
97
100
|
{ error: 'No Wrangler configuration file found in project directory' },
|
|
98
101
|
{ status: 404 }
|
|
@@ -130,7 +133,7 @@ export async function POST(req) {
|
|
|
130
133
|
});
|
|
131
134
|
|
|
132
135
|
} catch (error) {
|
|
133
|
-
|
|
136
|
+
logger.error('Cloudflare API error:', error);
|
|
134
137
|
return NextResponse.json(
|
|
135
138
|
{ error: error.message },
|
|
136
139
|
{ status: error.message.includes('Invalid credentials') ? 401 : 500 }
|
|
@@ -144,3 +147,4 @@ export async function POST(req) {
|
|
|
144
147
|
export async function OPTIONS() {
|
|
145
148
|
return new NextResponse(null, { status: 204 });
|
|
146
149
|
}
|
|
150
|
+
|
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
4
|
import { findWranglerConfig } from '@/lib/find-wrangler-config.js';
|
|
5
|
+
import logger from '@/lib/logger';
|
|
5
6
|
|
|
6
7
|
export async function GET() {
|
|
7
8
|
try {
|
|
8
9
|
const projectDir = process.env.D1_PROJECT_DIR;
|
|
9
10
|
|
|
10
11
|
if (!projectDir) {
|
|
11
|
-
|
|
12
|
+
logger.error('D1_PROJECT_DIR environment variable is not set');
|
|
12
13
|
return NextResponse.json(
|
|
13
14
|
{ error: 'Project directory not configured' },
|
|
14
15
|
{ status: 500 }
|
|
15
16
|
);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
// console.log('Looking for Wrangler configuration in:', projectDir);
|
|
19
|
-
|
|
20
19
|
// Use findWranglerConfig helper
|
|
21
20
|
const wranglerResult = await findWranglerConfig(projectDir);
|
|
22
21
|
if (!wranglerResult || !wranglerResult.config) {
|
|
@@ -44,7 +43,7 @@ export async function GET() {
|
|
|
44
43
|
}
|
|
45
44
|
});
|
|
46
45
|
} catch (error) {
|
|
47
|
-
|
|
46
|
+
logger.error('Error reading database configuration:', error);
|
|
48
47
|
|
|
49
48
|
return NextResponse.json(
|
|
50
49
|
{
|
|
@@ -5,14 +5,13 @@ import { findWranglerConfig } from '@/lib/find-wrangler-config.js';
|
|
|
5
5
|
import { readFile } from 'fs/promises';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import {
|
|
8
|
-
initMigrationsTable,
|
|
9
8
|
compareMigrations,
|
|
10
9
|
trackMigration,
|
|
11
|
-
updateMigrationStatus,
|
|
12
10
|
createChecksum
|
|
13
11
|
} from '@/lib/migrations';
|
|
14
12
|
import { promisify } from 'util';
|
|
15
13
|
import { exec } from 'child_process';
|
|
14
|
+
import logger from '@/lib/logger';
|
|
16
15
|
|
|
17
16
|
const execAsync = promisify(exec);
|
|
18
17
|
|
|
@@ -21,11 +20,14 @@ const execAsync = promisify(exec);
|
|
|
21
20
|
* Uses the centralized Wrangler configuration helper to determine the D1 database.
|
|
22
21
|
*/
|
|
23
22
|
export async function POST(req) {
|
|
23
|
+
logger.logRequest('POST', '/api/migrations/sync');
|
|
24
|
+
|
|
24
25
|
try {
|
|
25
26
|
const { accountId, apiToken } = await req.json();
|
|
26
27
|
const projectDir = process.env.D1_PROJECT_DIR;
|
|
27
28
|
|
|
28
29
|
if (!projectDir) {
|
|
30
|
+
logger.error('Project directory not configured');
|
|
29
31
|
return NextResponse.json(
|
|
30
32
|
{ error: 'Project directory not configured' },
|
|
31
33
|
{ status: 500 }
|
|
@@ -156,7 +158,7 @@ export async function POST(req) {
|
|
|
156
158
|
});
|
|
157
159
|
|
|
158
160
|
} catch (error) {
|
|
159
|
-
|
|
161
|
+
logger.logError(error, 'migrations-sync-route');
|
|
160
162
|
return NextResponse.json({
|
|
161
163
|
success: false,
|
|
162
164
|
error: {
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// api/pull-data/confirm/route.js
|
|
2
|
+
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
import { executeSQL } from '@/lib/sql-operations';
|
|
5
|
+
import { getCurrentSchema } from '@/lib/schema-operations';
|
|
6
|
+
import { findWranglerConfig } from '@/lib/find-wrangler-config.js';
|
|
7
|
+
import logger from '@/lib/logger';
|
|
8
|
+
import {
|
|
9
|
+
fetchRemoteTableData as fetchRemoteDataHelper,
|
|
10
|
+
generateBulkInsertSQL
|
|
11
|
+
} from '@/lib/sql-operations';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Helper to extract the ordering column (primary key) from a table's schema.
|
|
15
|
+
* Assumes that each table’s schema object contains a "columns" array with an "isPrimaryKey" flag.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} tableSchema - Schema info for the table.
|
|
18
|
+
* @returns {string} The column name to use for ordering.
|
|
19
|
+
*/
|
|
20
|
+
function getOrderingColumn(tableSchema) {
|
|
21
|
+
const pkColumn = tableSchema.columns?.find(col => col.isPrimaryKey);
|
|
22
|
+
const orderingCol = pkColumn ? pkColumn.name : 'rowid';
|
|
23
|
+
logger.debug(`Determined ordering column for table ${tableSchema.name || 'unknown'}: ${orderingCol}`);
|
|
24
|
+
return orderingCol;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Computes an insertion order for tables based on their foreign key dependencies.
|
|
29
|
+
* The returned array is sorted so that if table A is referenced by table B,
|
|
30
|
+
* then A appears earlier in the list.
|
|
31
|
+
*
|
|
32
|
+
* @param {Array<object>} tableSchemas - Array of table schema objects.
|
|
33
|
+
* @returns {Array<string>} Ordered array of table names.
|
|
34
|
+
*/
|
|
35
|
+
function computeInsertionOrder(tableSchemas) {
|
|
36
|
+
// Build a dependency graph: key = table name, value = set of tables that this table depends on.
|
|
37
|
+
const graph = {};
|
|
38
|
+
tableSchemas.forEach(table => {
|
|
39
|
+
// Initialize graph for this table.
|
|
40
|
+
graph[table.name] = new Set();
|
|
41
|
+
// Use a regex to find FOREIGN KEY references in the table's SQL.
|
|
42
|
+
// This regex assumes the foreign key clause looks like:
|
|
43
|
+
// FOREIGN KEY (...) REFERENCES referencedTable(...)
|
|
44
|
+
const fkRegex = /FOREIGN KEY\s*\([^)]*\)\s+REFERENCES\s+(\w+)/gi;
|
|
45
|
+
let match;
|
|
46
|
+
while ((match = fkRegex.exec(table.sql)) !== null) {
|
|
47
|
+
const referencedTable = match[1];
|
|
48
|
+
graph[table.name].add(referencedTable);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
logger.debug('Computed dependency graph:', graph);
|
|
52
|
+
|
|
53
|
+
// Topological sort (depth-first search) to compute insertion order.
|
|
54
|
+
const sorted = [];
|
|
55
|
+
const visited = {}; // 'temp' = visiting, 'perm' = done
|
|
56
|
+
|
|
57
|
+
function visit(tableName) {
|
|
58
|
+
if (visited[tableName] === 'temp') {
|
|
59
|
+
throw new Error(`Cycle detected in dependencies at table ${tableName}`);
|
|
60
|
+
}
|
|
61
|
+
if (!visited[tableName]) {
|
|
62
|
+
visited[tableName] = 'temp';
|
|
63
|
+
// Visit all tables that this table depends on.
|
|
64
|
+
graph[tableName].forEach(dep => {
|
|
65
|
+
// Only visit if the dependency is in our graph (i.e. among our tables)
|
|
66
|
+
if (graph[dep]) {
|
|
67
|
+
visit(dep);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
visited[tableName] = 'perm';
|
|
71
|
+
sorted.push(tableName);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Object.keys(graph).forEach(tableName => {
|
|
76
|
+
if (!visited[tableName]) {
|
|
77
|
+
visit(tableName);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
logger.debug('Computed insertion order (parent tables first):', sorted);
|
|
82
|
+
return sorted;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Applies the data pull by:
|
|
87
|
+
* 1. Fetching the local schema to determine table names and primary keys.
|
|
88
|
+
* 2. Computing the insertion order so that parent tables are inserted before child tables.
|
|
89
|
+
* 3. For each table (in insertion order), fetching the latest 100 records from the remote database.
|
|
90
|
+
* 4. Generating a bulk insert statement and executing it.
|
|
91
|
+
*
|
|
92
|
+
* This function aborts the entire process if any insert fails.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} projectDir
|
|
95
|
+
* @param {string} accountId
|
|
96
|
+
* @param {string} apiToken
|
|
97
|
+
* @param {string} databaseName
|
|
98
|
+
* @returns {object} Details of data pulled.
|
|
99
|
+
*/
|
|
100
|
+
async function applyDataPull(projectDir, accountId, apiToken, databaseName) {
|
|
101
|
+
logger.debug('Starting data pull process...');
|
|
102
|
+
const env = {
|
|
103
|
+
...process.env,
|
|
104
|
+
CLOUDFLARE_API_TOKEN: apiToken,
|
|
105
|
+
CLOUDFLARE_ACCOUNT_ID: accountId
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
logger.debug('Fetching current schema for data pull...');
|
|
109
|
+
const currentSchema = await getCurrentSchema(projectDir, databaseName, env, false);
|
|
110
|
+
// Filter for table objects that have a name.
|
|
111
|
+
const tableSchemas = currentSchema.filter(obj => obj.type === 'table' && obj.name);
|
|
112
|
+
logger.debug('Local table schema for data pull:', tableSchemas.map(t => t.name));
|
|
113
|
+
|
|
114
|
+
// Compute insertion order based on foreign key dependencies.
|
|
115
|
+
const insertionOrder = computeInsertionOrder(tableSchemas);
|
|
116
|
+
logger.debug('Final computed insertion order:', insertionOrder);
|
|
117
|
+
|
|
118
|
+
// Process each table in the computed insertion order.
|
|
119
|
+
for (const tableName of insertionOrder) {
|
|
120
|
+
const table = tableSchemas.find(t => t.name === tableName);
|
|
121
|
+
if (!table) {
|
|
122
|
+
logger.debug(`Skipping table ${tableName} as it is not in the current schema list.`);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
logger.debug(`Processing table: ${tableName}`);
|
|
126
|
+
const orderingColumn = getOrderingColumn(table);
|
|
127
|
+
logger.debug(`Fetching data for table: ${tableName} ordered by ${orderingColumn}`);
|
|
128
|
+
|
|
129
|
+
// Fetch remote data.
|
|
130
|
+
const rows = await fetchRemoteDataHelper(
|
|
131
|
+
projectDir,
|
|
132
|
+
databaseName,
|
|
133
|
+
tableName,
|
|
134
|
+
env,
|
|
135
|
+
75,
|
|
136
|
+
orderingColumn
|
|
137
|
+
);
|
|
138
|
+
logger.debug(`Fetched ${rows.length} records for table: ${tableName}`);
|
|
139
|
+
|
|
140
|
+
if (rows.length > 0) {
|
|
141
|
+
const insertSQL = generateBulkInsertSQL(tableName, rows);
|
|
142
|
+
logger.debug(`Generated bulk insert SQL for ${tableName}: ${insertSQL}`);
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
// Execute the insert SQL directly.
|
|
146
|
+
await executeSQL(projectDir, databaseName, insertSQL, env, false);
|
|
147
|
+
logger.debug(`Bulk inserted ${rows.length} records into table: ${tableName}`);
|
|
148
|
+
} catch (insertError) {
|
|
149
|
+
logger.error(`Error inserting data into table ${tableName}:`, insertError);
|
|
150
|
+
// Abort the entire process to preserve data integrity.
|
|
151
|
+
throw new Error(`Data pull failed for table ${tableName}: ${insertError.message}`);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
logger.debug(`No data fetched for table: ${tableName}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
logger.debug('Data pull process completed successfully.');
|
|
158
|
+
return { message: 'All data pulled successfully.' };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function POST(req) {
|
|
162
|
+
try {
|
|
163
|
+
logger.debug('Received request for data pull.');
|
|
164
|
+
const { accountId, apiToken } = await req.json();
|
|
165
|
+
const projectDir = process.env.D1_PROJECT_DIR;
|
|
166
|
+
if (!projectDir) {
|
|
167
|
+
return NextResponse.json(
|
|
168
|
+
{
|
|
169
|
+
success: false,
|
|
170
|
+
error: {
|
|
171
|
+
type: 'VALIDATION_ERROR',
|
|
172
|
+
message: 'Project directory not configured'
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{ status: 500 }
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const wranglerResult = await findWranglerConfig(projectDir);
|
|
179
|
+
if (!wranglerResult || !wranglerResult.config) {
|
|
180
|
+
return NextResponse.json(
|
|
181
|
+
{
|
|
182
|
+
success: false,
|
|
183
|
+
error: {
|
|
184
|
+
type: 'VALIDATION_ERROR',
|
|
185
|
+
message: 'Could not find Wrangler configuration'
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{ status: 400 }
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
const config = wranglerResult.config;
|
|
192
|
+
if (!config.d1_databases?.length) {
|
|
193
|
+
return NextResponse.json(
|
|
194
|
+
{
|
|
195
|
+
success: false,
|
|
196
|
+
error: {
|
|
197
|
+
type: 'VALIDATION_ERROR',
|
|
198
|
+
message: 'No D1 databases configured'
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
{ status: 400 }
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const databaseName = config.d1_databases[0].database_name;
|
|
205
|
+
logger.debug(`Initiating data pull for database: ${databaseName}`);
|
|
206
|
+
const result = await applyDataPull(projectDir, accountId, apiToken, databaseName);
|
|
207
|
+
logger.debug('Data pull result:', result);
|
|
208
|
+
return NextResponse.json({
|
|
209
|
+
success: true,
|
|
210
|
+
message: result.message,
|
|
211
|
+
details: result
|
|
212
|
+
});
|
|
213
|
+
} catch (error) {
|
|
214
|
+
logger.error('Pull data confirm error:', error);
|
|
215
|
+
return NextResponse.json(
|
|
216
|
+
{
|
|
217
|
+
success: false,
|
|
218
|
+
error: {
|
|
219
|
+
type: error.type || 'EXECUTION_ERROR',
|
|
220
|
+
message: error.message || 'Failed to apply data pull'
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{ status: 500 }
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export async function OPTIONS() {
|
|
229
|
+
return new NextResponse(null, { status: 204 });
|
|
230
|
+
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '@/lib/sql-operations';
|
|
13
13
|
import { getCurrentSchema, analyzeDependencies } from '@/lib/schema-operations';
|
|
14
14
|
import { initMigrationsTable, recordMigration, getRemoteMigrations } from '@/lib/migrations.js';
|
|
15
|
+
import logger from '@/lib/logger';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Applies the pull migrations by:
|
|
@@ -52,33 +53,33 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
52
53
|
await Promise.all(stagedFilesList.map(file => unlink(path.join(stagingDir, file))));
|
|
53
54
|
|
|
54
55
|
// --- STEP 1: Fetch remote migration metadata ---
|
|
55
|
-
|
|
56
|
+
logger.debug('Fetching remote migration metadata...');
|
|
56
57
|
const remoteMigrations = await getRemoteMigrations(projectDir, databaseName, env);
|
|
57
|
-
|
|
58
|
+
logger.debug('Remote migration metadata:', remoteMigrations);
|
|
58
59
|
|
|
59
60
|
// --- STEP 2: For each remote migration, fetch its file content ---
|
|
60
|
-
|
|
61
|
+
logger.debug('Fetching migration file content from remote...');
|
|
61
62
|
const stagedFiles = new Map();
|
|
62
63
|
for (const migration of remoteMigrations) {
|
|
63
64
|
try {
|
|
64
65
|
const migrationFileName = migration.name; // Use the remote migration's name.
|
|
65
66
|
const content = await getMigrationFileContent(projectDir, databaseName, migrationFileName, env);
|
|
66
67
|
stagedFiles.set(migrationFileName, content);
|
|
67
|
-
|
|
68
|
+
logger.debug(`Staged migration file: ${migrationFileName}`);
|
|
68
69
|
await writeFile(path.join(stagingDir, migrationFileName), content, 'utf8');
|
|
69
70
|
} catch (fileError) {
|
|
70
|
-
|
|
71
|
+
logger.error(`Error fetching content for migration ${migration.name}:`, fileError);
|
|
71
72
|
throw new Error(`Failed to fetch migration file content for ${migration.name}`);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
// --- STEP 3: Fetch local schema for destructive update ---
|
|
76
|
-
|
|
77
|
+
logger.debug('Fetching local schema for destructive update...');
|
|
77
78
|
const currentSchema = await getCurrentSchema(projectDir, databaseName, env, false);
|
|
78
79
|
const tableSchema = currentSchema.filter(obj =>
|
|
79
80
|
obj.type === 'table' && obj.name && obj.name.toLowerCase() !== 'if'
|
|
80
81
|
);
|
|
81
|
-
|
|
82
|
+
logger.debug('Local table schema:', tableSchema);
|
|
82
83
|
const dropOrder = tableSchema.length > 0
|
|
83
84
|
? analyzeDependencies(
|
|
84
85
|
tableSchema.map(obj => ({
|
|
@@ -88,18 +89,18 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
88
89
|
}))
|
|
89
90
|
)
|
|
90
91
|
: [];
|
|
91
|
-
|
|
92
|
+
logger.debug('Computed drop order:', dropOrder);
|
|
92
93
|
|
|
93
94
|
// --- STEP 4: Destructive update (all-or-nothing) ---
|
|
94
|
-
|
|
95
|
+
logger.debug('Beginning destructive update...');
|
|
95
96
|
try {
|
|
96
|
-
|
|
97
|
+
logger.debug('Disabling foreign keys...');
|
|
97
98
|
await executeSQL(projectDir, databaseName, 'PRAGMA foreign_keys=OFF;', env, false);
|
|
98
99
|
|
|
99
100
|
// Drop triggers.
|
|
100
101
|
const triggers = currentSchema.filter(obj => obj.type === 'trigger');
|
|
101
102
|
for (const trigger of triggers) {
|
|
102
|
-
|
|
103
|
+
logger.debug(`Dropping trigger: ${trigger.name}`);
|
|
103
104
|
await executeSQL(
|
|
104
105
|
projectDir,
|
|
105
106
|
databaseName,
|
|
@@ -111,7 +112,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
111
112
|
// Drop indexes.
|
|
112
113
|
const indexes = currentSchema.filter(obj => obj.type === 'index');
|
|
113
114
|
for (const index of indexes) {
|
|
114
|
-
|
|
115
|
+
logger.debug(`Dropping index: ${index.name}`);
|
|
115
116
|
await executeSQL(
|
|
116
117
|
projectDir,
|
|
117
118
|
databaseName,
|
|
@@ -122,7 +123,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
122
123
|
}
|
|
123
124
|
// Drop tables in reverse dependency order.
|
|
124
125
|
for (const tableName of dropOrder.reverse()) {
|
|
125
|
-
|
|
126
|
+
logger.debug(`Dropping table: ${tableName}`);
|
|
126
127
|
await executeSQL(
|
|
127
128
|
projectDir,
|
|
128
129
|
databaseName,
|
|
@@ -131,7 +132,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
131
132
|
false
|
|
132
133
|
);
|
|
133
134
|
}
|
|
134
|
-
|
|
135
|
+
logger.debug('Re-enabling foreign keys...');
|
|
135
136
|
await executeSQL(projectDir, databaseName, 'PRAGMA foreign_keys=ON;', env, false);
|
|
136
137
|
} catch (dropError) {
|
|
137
138
|
throw new Error(`Error dropping existing objects: ${dropError.message}`);
|
|
@@ -139,7 +140,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
139
140
|
|
|
140
141
|
// --- STEP 5: Reset the local migrations table ---
|
|
141
142
|
try {
|
|
142
|
-
|
|
143
|
+
logger.debug('Resetting local migrations table...');
|
|
143
144
|
await initMigrationsTable(projectDir, databaseName, 'local', true);
|
|
144
145
|
} catch (initError) {
|
|
145
146
|
throw new Error(`Error resetting migrations table: ${initError.message}`);
|
|
@@ -152,7 +153,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
152
153
|
try {
|
|
153
154
|
for (const [filename, content] of stagedFiles.entries()) {
|
|
154
155
|
currentFilename = filename;
|
|
155
|
-
|
|
156
|
+
logger.debug(`Applying migration: ${filename}`);
|
|
156
157
|
// Write the migration file to the main migrations folder.
|
|
157
158
|
await writeFile(path.join(migrationsDir, filename), content, 'utf8');
|
|
158
159
|
|
|
@@ -162,7 +163,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
162
163
|
.update(content)
|
|
163
164
|
.digest('hex');
|
|
164
165
|
|
|
165
|
-
|
|
166
|
+
logger.debug(`Recording migration: ${filename} with checksum ${checksum}`);
|
|
166
167
|
await recordMigration(
|
|
167
168
|
projectDir,
|
|
168
169
|
databaseName,
|
|
@@ -181,26 +182,26 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
// --- STEP 7: Replace main migrations folder with staged files ---
|
|
184
|
-
|
|
185
|
+
logger.debug('Replacing main migrations folder with staged files...');
|
|
185
186
|
const mainFiles = await readdir(migrationsDir).catch(() => []);
|
|
186
187
|
if (mainFiles.length) {
|
|
187
188
|
for (const file of mainFiles) {
|
|
188
|
-
|
|
189
|
+
logger.debug(`Deleting local migration file: ${file}`);
|
|
189
190
|
await unlink(path.join(migrationsDir, file));
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
for (const [filename, content] of stagedFiles.entries()) {
|
|
193
|
-
|
|
194
|
+
logger.debug(`Copying staged file ${filename} to main migrations folder`);
|
|
194
195
|
await writeFile(path.join(migrationsDir, filename), content, 'utf8');
|
|
195
196
|
}
|
|
196
197
|
|
|
197
|
-
|
|
198
|
+
logger.debug('Pull migration applied successfully.');
|
|
198
199
|
return {
|
|
199
200
|
appliedMigrations: Array.from(stagedFiles.keys()),
|
|
200
201
|
details: appliedPreview
|
|
201
202
|
};
|
|
202
203
|
} catch (error) {
|
|
203
|
-
|
|
204
|
+
logger.error('Pull migration error:', error);
|
|
204
205
|
throw error;
|
|
205
206
|
}
|
|
206
207
|
}
|
|
@@ -251,7 +252,7 @@ export async function POST(req) {
|
|
|
251
252
|
details: result
|
|
252
253
|
});
|
|
253
254
|
} catch (error) {
|
|
254
|
-
|
|
255
|
+
logger.error('Pull remote confirm error:', error);
|
|
255
256
|
return NextResponse.json({
|
|
256
257
|
success: false,
|
|
257
258
|
error: {
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
4
|
import { findWranglerConfig } from '@/lib/find-wrangler-config.js';
|
|
5
|
-
import { ErrorTypes
|
|
5
|
+
import { ErrorTypes } from '@/lib/sql-operations';
|
|
6
6
|
import { getCurrentSchema, analyzeDependencies } from '@/lib/schema-operations';
|
|
7
7
|
import { getRemoteMigrations } from '@/lib/migrations.js';
|
|
8
|
+
import logger from '@/lib/logger';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Generates a preview for pulling remote migrations.
|
|
@@ -64,7 +65,7 @@ async function generatePullPreview(projectDir, accountId, apiToken, databaseName
|
|
|
64
65
|
|
|
65
66
|
return preview;
|
|
66
67
|
} catch (error) {
|
|
67
|
-
|
|
68
|
+
logger.error('Pull preview generation error:', error);
|
|
68
69
|
throw error;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
@@ -123,7 +124,7 @@ export async function POST(req) {
|
|
|
123
124
|
details: preview
|
|
124
125
|
});
|
|
125
126
|
} catch (error) {
|
|
126
|
-
|
|
127
|
+
logger.error('Pull remote preview error:', error);
|
|
127
128
|
return NextResponse.json({
|
|
128
129
|
success: false,
|
|
129
130
|
error: {
|
|
@@ -6,6 +6,7 @@ import path from 'path';
|
|
|
6
6
|
import { findWranglerConfig } from '@/lib/find-wrangler-config.js';
|
|
7
7
|
import { executeSQL, ErrorTypes } from '@/lib/sql-operations';
|
|
8
8
|
import { validateMigrationFile } from '@/lib/migrations.js';
|
|
9
|
+
import logger from '@/lib/logger';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Pushes migration preview to remote.
|
|
@@ -100,7 +101,7 @@ async function pushToRemote(projectDir, accountId, apiToken, databaseName, previ
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
logger.debug("Push Preview Result (server):", results);
|
|
104
105
|
return { success: true, preview: true, applied: results.applied.length, skipped: results.skipped.length, details: results };
|
|
105
106
|
} catch (error) {
|
|
106
107
|
throw {
|
|
@@ -157,7 +158,7 @@ export async function POST(req) {
|
|
|
157
158
|
details: result
|
|
158
159
|
});
|
|
159
160
|
} catch (error) {
|
|
160
|
-
|
|
161
|
+
logger.error('Push to remote preview error:', error);
|
|
161
162
|
return NextResponse.json({
|
|
162
163
|
success: false,
|
|
163
164
|
error: {
|
|
@@ -11,15 +11,19 @@ import {
|
|
|
11
11
|
import { handleSchemaChange } from '@/lib/migrations';
|
|
12
12
|
import { isSchemaChange } from '@/lib/sql-operations';
|
|
13
13
|
import { parseSQLError } from '@/lib/parse-sql-error';
|
|
14
|
+
import logger from '@/lib/logger';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* API POST handler to execute SQL queries against the configured D1 database.
|
|
17
18
|
*/
|
|
18
19
|
export async function POST(req) {
|
|
20
|
+
logger.logRequest('POST', '/api/query');
|
|
21
|
+
|
|
19
22
|
try {
|
|
20
23
|
// Ensure that the project directory is set.
|
|
21
24
|
const projectDir = process.env.D1_PROJECT_DIR;
|
|
22
25
|
if (!projectDir) {
|
|
26
|
+
logger.error('Project directory not configured');
|
|
23
27
|
return NextResponse.json(
|
|
24
28
|
{ error: 'Project directory not configured' },
|
|
25
29
|
{ status: 500 }
|
|
@@ -28,7 +32,10 @@ export async function POST(req) {
|
|
|
28
32
|
|
|
29
33
|
// Extract the SQL query from the request body.
|
|
30
34
|
const { query } = await req.json();
|
|
31
|
-
|
|
35
|
+
|
|
36
|
+
if (logger.shouldLog('debug')) {
|
|
37
|
+
logger.debug('Received query:', query);
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
if (!query?.trim()) {
|
|
34
41
|
return NextResponse.json(
|
|
@@ -40,6 +47,7 @@ export async function POST(req) {
|
|
|
40
47
|
// Retrieve the Wrangler configuration using the centralized helper.
|
|
41
48
|
const wranglerResult = await findWranglerConfig(projectDir);
|
|
42
49
|
if (!wranglerResult || !wranglerResult.config) {
|
|
50
|
+
logger.error('No Wrangler configuration file found');
|
|
43
51
|
return NextResponse.json(
|
|
44
52
|
{ success: false, error: { message: 'No Wrangler configuration file found' } },
|
|
45
53
|
{ status: 404 }
|
|
@@ -94,7 +102,7 @@ export async function POST(req) {
|
|
|
94
102
|
// Process schema changes and capture migrations.
|
|
95
103
|
// The handleSchemaChange helper is responsible for executing the DDL statements.
|
|
96
104
|
const migrations = await handleSchemaChange(projectDir, databaseName, statements);
|
|
97
|
-
console.log('Schema changes processed:', migrations);
|
|
105
|
+
// console.log('Schema changes processed:', migrations);
|
|
98
106
|
|
|
99
107
|
result = {
|
|
100
108
|
success: true,
|
|
@@ -127,7 +135,7 @@ export async function POST(req) {
|
|
|
127
135
|
return NextResponse.json(result);
|
|
128
136
|
|
|
129
137
|
} catch (error) {
|
|
130
|
-
|
|
138
|
+
logger.logError(error, 'query-route');
|
|
131
139
|
const parsedError = parseSQLError(error);
|
|
132
140
|
|
|
133
141
|
const statusCode =
|
|
@@ -5,6 +5,7 @@ import { promisify } from 'util';
|
|
|
5
5
|
import { exec } from 'child_process';
|
|
6
6
|
import { findWranglerConfig } from '@/lib/find-wrangler-config.js';
|
|
7
7
|
import { dbQueue } from '@/lib/database-queue';
|
|
8
|
+
import logger from '@/lib/logger';
|
|
8
9
|
|
|
9
10
|
const execAsync = promisify(exec);
|
|
10
11
|
|
|
@@ -35,7 +36,7 @@ async function executeD1Query(command, projectDir, databaseName) {
|
|
|
35
36
|
const result = JSON.parse(stdout);
|
|
36
37
|
return result[0]?.results || [];
|
|
37
38
|
} catch (error) {
|
|
38
|
-
|
|
39
|
+
logger.error('Query execution error:', error);
|
|
39
40
|
throw error;
|
|
40
41
|
} finally {
|
|
41
42
|
isProcessing = false;
|
|
@@ -145,7 +146,7 @@ export async function GET(request, context) {
|
|
|
145
146
|
});
|
|
146
147
|
|
|
147
148
|
} catch (error) {
|
|
148
|
-
|
|
149
|
+
logger.error('Error handling request:', error);
|
|
149
150
|
return NextResponse.json({
|
|
150
151
|
success: false,
|
|
151
152
|
error: {
|