turbine-orm 0.93.1 → 0.94.0
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 +49 -23
- package/dist/adapters/cockroachdb.d.ts +3 -3
- package/dist/adapters/cockroachdb.js +7 -11
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/yugabytedb.js +1 -1
- package/dist/better-sqlite3.d.ts +132 -0
- package/dist/better-sqlite3.js +303 -0
- package/dist/catalog-metadata.d.ts +250 -0
- package/dist/catalog-metadata.js +730 -0
- package/dist/cjs/adapters/cockroachdb.d.ts +3 -3
- package/dist/cjs/adapters/cockroachdb.js +7 -11
- package/dist/cjs/adapters/index.d.ts +1 -1
- package/dist/cjs/adapters/yugabytedb.js +1 -1
- package/dist/cjs/better-sqlite3.d.ts +132 -0
- package/dist/cjs/better-sqlite3.js +311 -0
- package/dist/cjs/catalog-metadata.d.ts +250 -0
- package/dist/cjs/catalog-metadata.js +747 -0
- package/dist/cjs/cli/compile-query.d.ts +6 -3
- package/dist/cjs/cli/compile-query.js +24 -3
- package/dist/cjs/cli/config.d.ts +35 -10
- package/dist/cjs/cli/config.js +173 -42
- package/dist/cjs/cli/d1-config.d.ts +14 -0
- package/dist/cjs/cli/d1-config.js +9 -0
- package/dist/cjs/cli/d1-local.d.ts +31 -0
- package/dist/cjs/cli/d1-local.js +298 -0
- package/dist/cjs/cli/d1-migrations.d.ts +16 -0
- package/dist/cjs/cli/d1-migrations.js +156 -0
- package/dist/cjs/cli/d1-project.d.ts +23 -0
- package/dist/cjs/cli/d1-project.js +314 -0
- package/dist/cjs/cli/d1-seed.d.ts +35 -0
- package/dist/cjs/cli/d1-seed.js +220 -0
- package/dist/cjs/cli/destructive.js +1 -2
- package/dist/cjs/cli/error-catalog.d.ts +3 -3
- package/dist/cjs/cli/error-catalog.js +21 -3
- package/dist/cjs/cli/index.d.ts +13 -8
- package/dist/cjs/cli/index.js +503 -71
- package/dist/cjs/cli/libsql-migrate-command.d.ts +5 -0
- package/dist/cjs/cli/libsql-migrate-command.js +82 -0
- package/dist/cjs/cli/libsql-migrate-status.d.ts +33 -0
- package/dist/cjs/cli/libsql-migrate-status.js +189 -0
- package/dist/cjs/cli/libsql-migrate.d.ts +14 -0
- package/dist/cjs/cli/libsql-migrate.js +522 -0
- package/dist/cjs/cli/libsql-project-config.d.ts +11 -0
- package/dist/cjs/cli/libsql-project-config.js +59 -0
- package/dist/cjs/cli/libsql-project.d.ts +52 -0
- package/dist/cjs/cli/libsql-project.js +409 -0
- package/dist/cjs/cli/libsql-seed-command.d.ts +29 -0
- package/dist/cjs/cli/libsql-seed-command.js +93 -0
- package/dist/cjs/cli/loader.d.ts +6 -5
- package/dist/cjs/cli/loader.js +53 -9
- package/dist/cjs/cli/mcp.d.ts +16 -1
- package/dist/cjs/cli/mcp.js +219 -125
- package/dist/cjs/cli/migrate.d.ts +2 -2
- package/dist/cjs/cli/migrate.js +29 -14
- package/dist/cjs/cli/mssql-doctor.d.ts +44 -0
- package/dist/cjs/cli/mssql-doctor.js +277 -0
- package/dist/cjs/cli/mssql-migrate-command.d.ts +9 -0
- package/dist/cjs/cli/mssql-migrate-command.js +230 -0
- package/dist/cjs/cli/mssql-migrate-connection.d.ts +51 -0
- package/dist/cjs/cli/mssql-migrate-connection.js +255 -0
- package/dist/cjs/cli/mssql-migrate-sql.d.ts +12 -0
- package/dist/cjs/cli/mssql-migrate-sql.js +282 -0
- package/dist/cjs/cli/mssql-migrate.d.ts +45 -0
- package/dist/cjs/cli/mssql-migrate.js +296 -0
- package/dist/cjs/cli/mssql-project.d.ts +34 -0
- package/dist/cjs/cli/mssql-project.js +171 -0
- package/dist/cjs/cli/mssql-seed.d.ts +7 -0
- package/dist/cjs/cli/mssql-seed.js +78 -0
- package/dist/cjs/cli/mssql-tools.d.ts +37 -0
- package/dist/cjs/cli/mssql-tools.js +354 -0
- package/dist/cjs/cli/mysql-doctor.d.ts +48 -0
- package/dist/cjs/cli/mysql-doctor.js +323 -0
- package/dist/cjs/cli/mysql-migrate-command.d.ts +7 -0
- package/dist/cjs/cli/mysql-migrate-command.js +290 -0
- package/dist/cjs/cli/mysql-migrate-sql.d.ts +18 -0
- package/dist/cjs/cli/mysql-migrate-sql.js +166 -0
- package/dist/cjs/cli/mysql-migrate.d.ts +77 -0
- package/dist/cjs/cli/mysql-migrate.js +619 -0
- package/dist/cjs/cli/mysql-project.d.ts +49 -0
- package/dist/cjs/cli/mysql-project.js +284 -0
- package/dist/cjs/cli/mysql-push-command.d.ts +7 -0
- package/dist/cjs/cli/mysql-push-command.js +94 -0
- package/dist/cjs/cli/mysql-push.d.ts +15 -0
- package/dist/cjs/cli/mysql-push.js +98 -0
- package/dist/cjs/cli/mysql-schema-command.d.ts +5 -0
- package/dist/cjs/cli/mysql-schema-command.js +58 -0
- package/dist/cjs/cli/mysql-schema-ddl.d.ts +37 -0
- package/dist/cjs/cli/mysql-schema-ddl.js +234 -0
- package/dist/cjs/cli/mysql-schema-snapshot.d.ts +21 -0
- package/dist/cjs/cli/mysql-schema-snapshot.js +127 -0
- package/dist/cjs/cli/mysql-schema.d.ts +27 -0
- package/dist/cjs/cli/mysql-schema.js +206 -0
- package/dist/cjs/cli/mysql-seed-loader.cjs +58 -0
- package/dist/cjs/cli/mysql-seed-loader.d.cts +3 -0
- package/dist/cjs/cli/mysql-seed.d.ts +6 -0
- package/dist/cjs/cli/mysql-seed.js +83 -0
- package/dist/cjs/cli/mysql-tools.d.ts +44 -0
- package/dist/cjs/cli/mysql-tools.js +336 -0
- package/dist/cjs/cli/no-follow.d.ts +29 -0
- package/dist/cjs/cli/no-follow.js +73 -0
- package/dist/cjs/cli/pii-predicate-guard.d.ts +1 -1
- package/dist/cjs/cli/pii-predicate-guard.js +2 -2
- package/dist/cjs/cli/pii-tags.d.ts +2 -2
- package/dist/cjs/cli/pii-tags.js +1 -1
- package/dist/cjs/cli/prisma-schema.js +2 -2
- package/dist/cjs/cli/sql-statements.d.ts +1 -1
- package/dist/cjs/cli/sql-statements.js +1 -1
- package/dist/cjs/cli/sqlite-doctor.d.ts +35 -0
- package/dist/cjs/cli/sqlite-doctor.js +400 -0
- package/dist/cjs/cli/sqlite-migrate-command.d.ts +4 -0
- package/dist/cjs/cli/sqlite-migrate-command.js +175 -0
- package/dist/cjs/cli/sqlite-migrate.d.ts +61 -0
- package/dist/cjs/cli/sqlite-migrate.js +692 -0
- package/dist/cjs/cli/sqlite-project.d.ts +42 -0
- package/dist/cjs/cli/sqlite-project.js +254 -0
- package/dist/cjs/cli/sqlite-schema-command.d.ts +4 -0
- package/dist/cjs/cli/sqlite-schema-command.js +82 -0
- package/dist/cjs/cli/sqlite-schema-ddl.d.ts +25 -0
- package/dist/cjs/cli/sqlite-schema-ddl.js +252 -0
- package/dist/cjs/cli/sqlite-schema.d.ts +25 -0
- package/dist/cjs/cli/sqlite-schema.js +334 -0
- package/dist/cjs/cli/sqlite-seed.d.ts +4 -0
- package/dist/cjs/cli/sqlite-seed.js +94 -0
- package/dist/cjs/cli/sqlite-tools.d.ts +24 -0
- package/dist/cjs/cli/sqlite-tools.js +169 -0
- package/dist/cjs/cli/studio.js +9 -9
- package/dist/cjs/cli/tool-capabilities.d.ts +72 -0
- package/dist/cjs/cli/tool-capabilities.js +120 -0
- package/dist/cjs/cli/tool-command.d.ts +11 -0
- package/dist/cjs/cli/tool-command.js +49 -0
- package/dist/cjs/cli/ui.d.ts +1 -1
- package/dist/cjs/cli/ui.js +1 -1
- package/dist/cjs/client.d.ts +20 -20
- package/dist/cjs/client.js +65 -344
- package/dist/cjs/connection-url.d.ts +1 -1
- package/dist/cjs/connection-url.js +1 -1
- package/dist/cjs/core.d.ts +58 -0
- package/dist/cjs/core.js +225 -0
- package/dist/cjs/d1/catalog-metadata.d.ts +5 -0
- package/dist/cjs/d1/catalog-metadata.js +230 -0
- package/dist/cjs/d1/catalog.d.ts +15 -0
- package/dist/cjs/d1/catalog.js +88 -0
- package/dist/cjs/d1/generate.d.ts +8 -0
- package/dist/cjs/d1/generate.js +163 -0
- package/dist/cjs/d1/introspect.d.ts +21 -0
- package/dist/cjs/d1/introspect.js +74 -0
- package/dist/cjs/d1/migrate.d.ts +29 -0
- package/dist/cjs/d1/migrate.js +222 -0
- package/dist/cjs/d1/migrations/sql.d.ts +2 -0
- package/dist/cjs/d1/migrations/sql.js +109 -0
- package/dist/cjs/d1/pool.d.ts +14 -0
- package/dist/cjs/d1/pool.js +90 -0
- package/dist/cjs/d1/sql.d.ts +5 -0
- package/dist/cjs/d1/sql.js +140 -0
- package/dist/cjs/d1/sqlite-dialect.d.ts +16 -0
- package/dist/cjs/d1/sqlite-dialect.js +579 -0
- package/dist/cjs/d1/types.d.ts +29 -0
- package/dist/cjs/d1/types.js +2 -0
- package/dist/cjs/d1.d.ts +53 -0
- package/dist/cjs/d1.js +220 -0
- package/dist/cjs/dialect.d.ts +33 -5
- package/dist/cjs/dialect.js +8 -6
- package/dist/cjs/errors.d.ts +38 -1
- package/dist/cjs/errors.js +72 -18
- package/dist/cjs/generate.d.ts +19 -3
- package/dist/cjs/generate.js +330 -97
- package/dist/cjs/global-filters-config.js +4 -4
- package/dist/cjs/index-advisor.js +6 -6
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/introspect.d.ts +59 -356
- package/dist/cjs/introspect.js +158 -984
- package/dist/cjs/libsql/bindings.d.ts +2 -0
- package/dist/cjs/libsql/bindings.js +78 -0
- package/dist/cjs/libsql/dialect.d.ts +3 -0
- package/dist/cjs/libsql/dialect.js +48 -0
- package/dist/cjs/libsql/generate.d.ts +4 -0
- package/dist/cjs/libsql/generate.js +56 -0
- package/dist/cjs/libsql/introspect.d.ts +16 -0
- package/dist/cjs/libsql/introspect.js +295 -0
- package/dist/cjs/libsql/pool.d.ts +42 -0
- package/dist/cjs/libsql/pool.js +275 -0
- package/dist/cjs/libsql/seed-cleanup.d.ts +2 -0
- package/dist/cjs/libsql/seed-cleanup.js +19 -0
- package/dist/cjs/libsql/values.d.ts +20 -0
- package/dist/cjs/libsql/values.js +75 -0
- package/dist/cjs/libsql-seed.d.ts +19 -0
- package/dist/cjs/libsql-seed.js +50 -0
- package/dist/cjs/libsql.d.ts +28 -0
- package/dist/cjs/libsql.js +88 -0
- package/dist/cjs/live-query.d.ts +33 -0
- package/dist/cjs/live-query.js +172 -0
- package/dist/cjs/log-codes.d.ts +1 -1
- package/dist/cjs/log-codes.js +4 -0
- package/dist/cjs/mssql-seed.d.ts +27 -0
- package/dist/cjs/mssql-seed.js +118 -0
- package/dist/cjs/mssql.d.ts +7 -7
- package/dist/cjs/mssql.js +365 -53
- package/dist/cjs/mysql-seed.d.ts +25 -0
- package/dist/cjs/mysql-seed.js +169 -0
- package/dist/cjs/mysql.d.ts +18 -6
- package/dist/cjs/mysql.js +602 -94
- package/dist/cjs/neon-http/client.d.ts +95 -0
- package/dist/cjs/neon-http/client.js +291 -0
- package/dist/cjs/neon-http/sql.d.ts +3 -0
- package/dist/cjs/neon-http/sql.js +116 -0
- package/dist/cjs/neon-http.d.ts +5 -0
- package/dist/cjs/neon-http.js +8 -0
- package/dist/cjs/neon-ws/load-driver.cjs +44 -0
- package/dist/cjs/neon-ws/load-driver.d.cts +9 -0
- package/dist/cjs/neon-ws/recovery.d.ts +14 -0
- package/dist/cjs/neon-ws/recovery.js +69 -0
- package/dist/cjs/neon-ws/snapshot.d.ts +3 -0
- package/dist/cjs/neon-ws/snapshot.js +17 -0
- package/dist/cjs/neon-ws/transport.d.ts +112 -0
- package/dist/cjs/neon-ws/transport.js +290 -0
- package/dist/cjs/neon-ws.d.ts +26 -0
- package/dist/cjs/neon-ws.js +189 -0
- package/dist/cjs/nested-write.d.ts +34 -3
- package/dist/cjs/nested-write.js +117 -24
- package/dist/cjs/notification-hub/consumer.d.ts +22 -0
- package/dist/cjs/notification-hub/consumer.js +111 -0
- package/dist/cjs/notification-hub.d.ts +41 -0
- package/dist/cjs/notification-hub.js +373 -0
- package/dist/cjs/pg-catalog-text.d.ts +96 -0
- package/dist/cjs/pg-catalog-text.js +213 -0
- package/dist/cjs/pg-types.d.ts +46 -2
- package/dist/cjs/pipeline-submittable.d.ts +15 -5
- package/dist/cjs/pipeline-submittable.js +103 -48
- package/dist/cjs/pipeline.d.ts +5 -2
- package/dist/cjs/pipeline.js +111 -41
- package/dist/cjs/plan-divergence.d.ts +1 -1
- package/dist/cjs/plan-divergence.js +1 -1
- package/dist/cjs/powdb-introspect.d.ts +1 -1
- package/dist/cjs/powdb-introspect.js +5 -5
- package/dist/cjs/powdb-shared.d.ts +5 -5
- package/dist/cjs/powdb-shared.js +6 -5
- package/dist/cjs/powdb.d.ts +28 -10
- package/dist/cjs/powdb.js +80 -28
- package/dist/cjs/powql.d.ts +50 -28
- package/dist/cjs/powql.js +47 -33
- package/dist/cjs/prisma-compat.js +4 -5
- package/dist/cjs/prisma-schema-fingerprint.d.ts +1 -1
- package/dist/cjs/prisma-schema-fingerprint.js +1 -1
- package/dist/cjs/query/aggregates.d.ts +0 -13
- package/dist/cjs/query/aggregates.js +105 -238
- package/dist/cjs/query/batched-loader.d.ts +1 -1
- package/dist/cjs/query/batched-loader.js +18 -20
- package/dist/cjs/query/builder.d.ts +108 -144
- package/dist/cjs/query/builder.js +592 -893
- package/dist/cjs/query/compound-unique.d.ts +18 -3
- package/dist/cjs/query/compound-unique.js +110 -43
- package/dist/cjs/query/cursor-tuple.d.ts +17 -0
- package/dist/cjs/query/cursor-tuple.js +121 -0
- package/dist/cjs/query/expr.d.ts +2 -0
- package/dist/cjs/query/expr.js +40 -23
- package/dist/cjs/query/filters.d.ts +39 -7
- package/dist/cjs/query/filters.js +77 -19
- package/dist/cjs/query/normalize-args.d.ts +1 -1
- package/dist/cjs/query/normalize-args.js +7 -5
- package/dist/cjs/query/option-surface.d.ts +1 -1
- package/dist/cjs/query/option-surface.js +5 -3
- package/dist/cjs/query/pg-type-parsers.d.ts +126 -0
- package/dist/cjs/query/pg-type-parsers.js +306 -0
- package/dist/cjs/query/relation-names.d.ts +4 -2
- package/dist/cjs/query/relation-names.js +21 -12
- package/dist/cjs/query/relations.d.ts +19 -7
- package/dist/cjs/query/relations.js +329 -260
- package/dist/cjs/query/row-lock.js +3 -3
- package/dist/cjs/query/sql-comment.js +3 -3
- package/dist/cjs/query/stream-idle.d.ts +11 -1
- package/dist/cjs/query/stream-idle.js +53 -13
- package/dist/cjs/query/stream-signal.d.ts +21 -0
- package/dist/cjs/query/stream-signal.js +132 -0
- package/dist/cjs/query/temporal-parsers.d.ts +101 -0
- package/dist/cjs/query/temporal-parsers.js +362 -0
- package/dist/cjs/query/types.d.ts +67 -20
- package/dist/cjs/query/utils.d.ts +2 -878
- package/dist/cjs/query/utils.js +25 -2058
- package/dist/cjs/query/warn-registry.d.ts +1 -1
- package/dist/cjs/query/warn-registry.js +1 -1
- package/dist/cjs/query/where-compile.d.ts +4 -1
- package/dist/cjs/query/where-compile.js +18 -14
- package/dist/cjs/query/where.d.ts +14 -7
- package/dist/cjs/query/where.js +244 -436
- package/dist/cjs/query/writes.d.ts +33 -2
- package/dist/cjs/query/writes.js +104 -77
- package/dist/cjs/query-utils.d.ts +687 -0
- package/dist/cjs/query-utils.js +1444 -0
- package/dist/cjs/realtime.d.ts +1 -1
- package/dist/cjs/realtime.js +3 -3
- package/dist/cjs/schema-builder.js +2 -2
- package/dist/cjs/schema-metadata.d.ts +13 -3
- package/dist/cjs/schema-metadata.js +33 -5
- package/dist/cjs/schema-sql.d.ts +15 -24
- package/dist/cjs/schema-sql.js +53 -63
- package/dist/cjs/schema.d.ts +37 -2
- package/dist/cjs/schema.js +29 -2
- package/dist/cjs/seed.js +5 -5
- package/dist/cjs/serverless.d.ts +24 -71
- package/dist/cjs/serverless.js +24 -71
- package/dist/cjs/sql.d.ts +111 -0
- package/dist/cjs/sql.js +335 -0
- package/dist/cjs/sqlite-seed.d.ts +17 -0
- package/dist/cjs/sqlite-seed.js +31 -0
- package/dist/cjs/sqlite.d.ts +32 -19
- package/dist/cjs/sqlite.js +865 -652
- package/dist/cjs/supplied-pool-types.js +10 -9
- package/dist/cjs/transaction-control.js +6 -1
- package/dist/cjs/transaction-outcome.d.ts +61 -0
- package/dist/cjs/transaction-outcome.js +239 -0
- package/dist/cjs/transaction-state.d.ts +82 -13
- package/dist/cjs/transaction-state.js +222 -56
- package/dist/cjs/transaction-transport.d.ts +38 -0
- package/dist/cjs/transaction-transport.js +157 -0
- package/dist/cjs/typed-sql.d.ts +1 -1
- package/dist/cjs/typed-sql.js +1 -1
- package/dist/cli/compile-query.d.ts +6 -3
- package/dist/cli/compile-query.js +25 -4
- package/dist/cli/config.d.ts +35 -10
- package/dist/cli/config.js +170 -43
- package/dist/cli/d1-config.d.ts +14 -0
- package/dist/cli/d1-config.js +6 -0
- package/dist/cli/d1-local.d.ts +31 -0
- package/dist/cli/d1-local.js +285 -0
- package/dist/cli/d1-migrations.d.ts +16 -0
- package/dist/cli/d1-migrations.js +151 -0
- package/dist/cli/d1-project.d.ts +23 -0
- package/dist/cli/d1-project.js +304 -0
- package/dist/cli/d1-seed.d.ts +35 -0
- package/dist/cli/d1-seed.js +213 -0
- package/dist/cli/destructive.js +1 -2
- package/dist/cli/error-catalog.d.ts +3 -3
- package/dist/cli/error-catalog.js +21 -3
- package/dist/cli/index.d.ts +13 -8
- package/dist/cli/index.js +500 -71
- package/dist/cli/libsql-migrate-command.d.ts +5 -0
- package/dist/cli/libsql-migrate-command.js +77 -0
- package/dist/cli/libsql-migrate-status.d.ts +33 -0
- package/dist/cli/libsql-migrate-status.js +182 -0
- package/dist/cli/libsql-migrate.d.ts +14 -0
- package/dist/cli/libsql-migrate.js +516 -0
- package/dist/cli/libsql-project-config.d.ts +11 -0
- package/dist/cli/libsql-project-config.js +55 -0
- package/dist/cli/libsql-project.d.ts +52 -0
- package/dist/cli/libsql-project.js +391 -0
- package/dist/cli/libsql-seed-command.d.ts +29 -0
- package/dist/cli/libsql-seed-command.js +85 -0
- package/dist/cli/loader.d.ts +6 -5
- package/dist/cli/loader.js +50 -9
- package/dist/cli/mcp.d.ts +16 -1
- package/dist/cli/mcp.js +220 -127
- package/dist/cli/migrate.d.ts +2 -2
- package/dist/cli/migrate.js +29 -14
- package/dist/cli/mssql-doctor.d.ts +44 -0
- package/dist/cli/mssql-doctor.js +237 -0
- package/dist/cli/mssql-migrate-command.d.ts +9 -0
- package/dist/cli/mssql-migrate-command.js +192 -0
- package/dist/cli/mssql-migrate-connection.d.ts +51 -0
- package/dist/cli/mssql-migrate-connection.js +245 -0
- package/dist/cli/mssql-migrate-sql.d.ts +12 -0
- package/dist/cli/mssql-migrate-sql.js +275 -0
- package/dist/cli/mssql-migrate.d.ts +45 -0
- package/dist/cli/mssql-migrate.js +290 -0
- package/dist/cli/mssql-project.d.ts +34 -0
- package/dist/cli/mssql-project.js +160 -0
- package/dist/cli/mssql-seed.d.ts +7 -0
- package/dist/cli/mssql-seed.js +73 -0
- package/dist/cli/mssql-tools.d.ts +37 -0
- package/dist/cli/mssql-tools.js +341 -0
- package/dist/cli/mysql-doctor.d.ts +48 -0
- package/dist/cli/mysql-doctor.js +316 -0
- package/dist/cli/mysql-migrate-command.d.ts +7 -0
- package/dist/cli/mysql-migrate-command.js +285 -0
- package/dist/cli/mysql-migrate-sql.d.ts +18 -0
- package/dist/cli/mysql-migrate-sql.js +162 -0
- package/dist/cli/mysql-migrate.d.ts +77 -0
- package/dist/cli/mysql-migrate.js +606 -0
- package/dist/cli/mysql-project.d.ts +49 -0
- package/dist/cli/mysql-project.js +272 -0
- package/dist/cli/mysql-push-command.d.ts +7 -0
- package/dist/cli/mysql-push-command.js +89 -0
- package/dist/cli/mysql-push.d.ts +15 -0
- package/dist/cli/mysql-push.js +95 -0
- package/dist/cli/mysql-schema-command.d.ts +5 -0
- package/dist/cli/mysql-schema-command.js +54 -0
- package/dist/cli/mysql-schema-ddl.d.ts +37 -0
- package/dist/cli/mysql-schema-ddl.js +227 -0
- package/dist/cli/mysql-schema-snapshot.d.ts +21 -0
- package/dist/cli/mysql-schema-snapshot.js +119 -0
- package/dist/cli/mysql-schema.d.ts +27 -0
- package/dist/cli/mysql-schema.js +200 -0
- package/dist/cli/mysql-seed-loader.cjs +25 -0
- package/dist/cli/mysql-seed-loader.d.cts +3 -0
- package/dist/cli/mysql-seed.d.ts +6 -0
- package/dist/cli/mysql-seed.js +75 -0
- package/dist/cli/mysql-tools.d.ts +44 -0
- package/dist/cli/mysql-tools.js +290 -0
- package/dist/cli/no-follow.d.ts +29 -0
- package/dist/cli/no-follow.js +67 -0
- package/dist/cli/pii-predicate-guard.d.ts +1 -1
- package/dist/cli/pii-predicate-guard.js +2 -2
- package/dist/cli/pii-tags.d.ts +2 -2
- package/dist/cli/pii-tags.js +1 -1
- package/dist/cli/prisma-schema.js +2 -2
- package/dist/cli/sql-statements.d.ts +1 -1
- package/dist/cli/sql-statements.js +1 -1
- package/dist/cli/sqlite-doctor.d.ts +35 -0
- package/dist/cli/sqlite-doctor.js +392 -0
- package/dist/cli/sqlite-migrate-command.d.ts +4 -0
- package/dist/cli/sqlite-migrate-command.js +171 -0
- package/dist/cli/sqlite-migrate.d.ts +61 -0
- package/dist/cli/sqlite-migrate.js +681 -0
- package/dist/cli/sqlite-project.d.ts +42 -0
- package/dist/cli/sqlite-project.js +244 -0
- package/dist/cli/sqlite-schema-command.d.ts +4 -0
- package/dist/cli/sqlite-schema-command.js +79 -0
- package/dist/cli/sqlite-schema-ddl.d.ts +25 -0
- package/dist/cli/sqlite-schema-ddl.js +248 -0
- package/dist/cli/sqlite-schema.d.ts +25 -0
- package/dist/cli/sqlite-schema.js +330 -0
- package/dist/cli/sqlite-seed.d.ts +4 -0
- package/dist/cli/sqlite-seed.js +57 -0
- package/dist/cli/sqlite-tools.d.ts +24 -0
- package/dist/cli/sqlite-tools.js +163 -0
- package/dist/cli/studio.js +9 -9
- package/dist/cli/tool-capabilities.d.ts +72 -0
- package/dist/cli/tool-capabilities.js +114 -0
- package/dist/cli/tool-command.d.ts +11 -0
- package/dist/cli/tool-command.js +45 -0
- package/dist/cli/ui.d.ts +1 -1
- package/dist/cli/ui.js +1 -1
- package/dist/client.d.ts +20 -20
- package/dist/client.js +62 -341
- package/dist/connection-url.d.ts +1 -1
- package/dist/connection-url.js +1 -1
- package/dist/core.d.ts +58 -0
- package/dist/core.js +220 -0
- package/dist/d1/catalog-metadata.d.ts +5 -0
- package/dist/d1/catalog-metadata.js +227 -0
- package/dist/d1/catalog.d.ts +15 -0
- package/dist/d1/catalog.js +82 -0
- package/dist/d1/generate.d.ts +8 -0
- package/dist/d1/generate.js +160 -0
- package/dist/d1/introspect.d.ts +21 -0
- package/dist/d1/introspect.js +71 -0
- package/dist/d1/migrate.d.ts +29 -0
- package/dist/d1/migrate.js +217 -0
- package/dist/d1/migrations/sql.d.ts +2 -0
- package/dist/d1/migrations/sql.js +106 -0
- package/dist/d1/pool.d.ts +14 -0
- package/dist/d1/pool.js +86 -0
- package/dist/d1/sql.d.ts +5 -0
- package/dist/d1/sql.js +135 -0
- package/dist/d1/sqlite-dialect.d.ts +16 -0
- package/dist/d1/sqlite-dialect.js +572 -0
- package/dist/d1/types.d.ts +29 -0
- package/dist/d1/types.js +1 -0
- package/dist/d1.d.ts +53 -0
- package/dist/d1.js +215 -0
- package/dist/dialect.d.ts +33 -5
- package/dist/dialect.js +6 -4
- package/dist/errors.d.ts +38 -1
- package/dist/errors.js +68 -17
- package/dist/generate.d.ts +19 -3
- package/dist/generate.js +330 -97
- package/dist/global-filters-config.js +2 -2
- package/dist/index-advisor.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/introspect.d.ts +59 -356
- package/dist/introspect.js +116 -943
- package/dist/libsql/bindings.d.ts +2 -0
- package/dist/libsql/bindings.js +75 -0
- package/dist/libsql/dialect.d.ts +3 -0
- package/dist/libsql/dialect.js +45 -0
- package/dist/libsql/generate.d.ts +4 -0
- package/dist/libsql/generate.js +53 -0
- package/dist/libsql/introspect.d.ts +16 -0
- package/dist/libsql/introspect.js +289 -0
- package/dist/libsql/pool.d.ts +42 -0
- package/dist/libsql/pool.js +270 -0
- package/dist/libsql/seed-cleanup.d.ts +2 -0
- package/dist/libsql/seed-cleanup.js +15 -0
- package/dist/libsql/values.d.ts +20 -0
- package/dist/libsql/values.js +68 -0
- package/dist/libsql-seed.d.ts +19 -0
- package/dist/libsql-seed.js +46 -0
- package/dist/libsql.d.ts +28 -0
- package/dist/libsql.js +79 -0
- package/dist/live-query.d.ts +33 -0
- package/dist/live-query.js +169 -0
- package/dist/log-codes.d.ts +1 -1
- package/dist/log-codes.js +4 -0
- package/dist/mssql-seed.d.ts +27 -0
- package/dist/mssql-seed.js +114 -0
- package/dist/mssql.d.ts +7 -7
- package/dist/mssql.js +366 -54
- package/dist/mysql-seed.d.ts +25 -0
- package/dist/mysql-seed.js +165 -0
- package/dist/mysql.d.ts +18 -6
- package/dist/mysql.js +603 -95
- package/dist/neon-http/client.d.ts +95 -0
- package/dist/neon-http/client.js +286 -0
- package/dist/neon-http/sql.d.ts +3 -0
- package/dist/neon-http/sql.js +112 -0
- package/dist/neon-http.d.ts +5 -0
- package/dist/neon-http.js +2 -0
- package/dist/neon-ws/load-driver.cjs +11 -0
- package/dist/neon-ws/load-driver.d.cts +9 -0
- package/dist/neon-ws/recovery.d.ts +14 -0
- package/dist/neon-ws/recovery.js +66 -0
- package/dist/neon-ws/snapshot.d.ts +3 -0
- package/dist/neon-ws/snapshot.js +15 -0
- package/dist/neon-ws/transport.d.ts +112 -0
- package/dist/neon-ws/transport.js +286 -0
- package/dist/neon-ws.d.ts +26 -0
- package/dist/neon-ws.js +182 -0
- package/dist/nested-write.d.ts +34 -3
- package/dist/nested-write.js +114 -22
- package/dist/notification-hub/consumer.d.ts +22 -0
- package/dist/notification-hub/consumer.js +106 -0
- package/dist/notification-hub.d.ts +41 -0
- package/dist/notification-hub.js +370 -0
- package/dist/pg-catalog-text.d.ts +96 -0
- package/dist/pg-catalog-text.js +208 -0
- package/dist/pg-types.d.ts +46 -2
- package/dist/pipeline-submittable.d.ts +15 -5
- package/dist/pipeline-submittable.js +105 -50
- package/dist/pipeline.d.ts +5 -2
- package/dist/pipeline.js +113 -43
- package/dist/plan-divergence.d.ts +1 -1
- package/dist/plan-divergence.js +1 -1
- package/dist/powdb-introspect.d.ts +1 -1
- package/dist/powdb-introspect.js +5 -5
- package/dist/powdb-shared.d.ts +5 -5
- package/dist/powdb-shared.js +6 -5
- package/dist/powdb.d.ts +28 -10
- package/dist/powdb.js +80 -28
- package/dist/powql.d.ts +50 -28
- package/dist/powql.js +49 -35
- package/dist/prisma-compat.js +4 -5
- package/dist/prisma-schema-fingerprint.d.ts +1 -1
- package/dist/prisma-schema-fingerprint.js +1 -1
- package/dist/query/aggregates.d.ts +0 -13
- package/dist/query/aggregates.js +97 -230
- package/dist/query/batched-loader.d.ts +1 -1
- package/dist/query/batched-loader.js +5 -7
- package/dist/query/builder.d.ts +108 -144
- package/dist/query/builder.js +563 -864
- package/dist/query/compound-unique.d.ts +18 -3
- package/dist/query/compound-unique.js +99 -33
- package/dist/query/cursor-tuple.d.ts +17 -0
- package/dist/query/cursor-tuple.js +114 -0
- package/dist/query/expr.d.ts +2 -0
- package/dist/query/expr.js +32 -16
- package/dist/query/filters.d.ts +39 -7
- package/dist/query/filters.js +69 -14
- package/dist/query/normalize-args.d.ts +1 -1
- package/dist/query/normalize-args.js +4 -2
- package/dist/query/option-surface.d.ts +1 -1
- package/dist/query/option-surface.js +4 -2
- package/dist/query/pg-type-parsers.d.ts +126 -0
- package/dist/query/pg-type-parsers.js +296 -0
- package/dist/query/relation-names.d.ts +4 -2
- package/dist/query/relation-names.js +15 -7
- package/dist/query/relations.d.ts +19 -7
- package/dist/query/relations.js +293 -227
- package/dist/query/row-lock.js +1 -1
- package/dist/query/sql-comment.js +1 -1
- package/dist/query/stream-idle.d.ts +11 -1
- package/dist/query/stream-idle.js +51 -13
- package/dist/query/stream-signal.d.ts +21 -0
- package/dist/query/stream-signal.js +125 -0
- package/dist/query/temporal-parsers.d.ts +101 -0
- package/dist/query/temporal-parsers.js +354 -0
- package/dist/query/types.d.ts +67 -20
- package/dist/query/utils.d.ts +2 -878
- package/dist/query/utils.js +5 -2003
- package/dist/query/warn-registry.d.ts +1 -1
- package/dist/query/warn-registry.js +1 -1
- package/dist/query/where-compile.d.ts +4 -1
- package/dist/query/where-compile.js +14 -10
- package/dist/query/where.d.ts +14 -7
- package/dist/query/where.js +236 -430
- package/dist/query/writes.d.ts +33 -2
- package/dist/query/writes.js +90 -65
- package/dist/query-utils.d.ts +687 -0
- package/dist/query-utils.js +1390 -0
- package/dist/realtime.d.ts +1 -1
- package/dist/realtime.js +3 -3
- package/dist/schema-builder.js +2 -2
- package/dist/schema-metadata.d.ts +13 -3
- package/dist/schema-metadata.js +33 -5
- package/dist/schema-sql.d.ts +15 -24
- package/dist/schema-sql.js +50 -60
- package/dist/schema.d.ts +37 -2
- package/dist/schema.js +29 -2
- package/dist/seed.js +5 -5
- package/dist/serverless.d.ts +24 -71
- package/dist/serverless.js +24 -71
- package/dist/sql.d.ts +111 -0
- package/dist/sql.js +321 -0
- package/dist/sqlite-seed.d.ts +17 -0
- package/dist/sqlite-seed.js +27 -0
- package/dist/sqlite.d.ts +32 -19
- package/dist/sqlite.js +859 -648
- package/dist/supplied-pool-types.js +2 -1
- package/dist/transaction-control.js +6 -1
- package/dist/transaction-outcome.d.ts +61 -0
- package/dist/transaction-outcome.js +234 -0
- package/dist/transaction-state.d.ts +82 -13
- package/dist/transaction-state.js +220 -57
- package/dist/transaction-transport.d.ts +38 -0
- package/dist/transaction-transport.js +153 -0
- package/dist/typed-sql.d.ts +1 -1
- package/dist/typed-sql.js +1 -1
- package/package.json +239 -13
- package/skills/turbine-orm/SKILL.md +6 -5
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/** Scoped SQLite diagnostics. Reads catalog structure, never repairs a database. */
|
|
2
|
+
import { closeSync, existsSync, openSync, readSync } from 'node:fs';
|
|
3
|
+
import { guardCheckout } from '../connection-guard.js';
|
|
4
|
+
import { ValidationError } from '../errors.js';
|
|
5
|
+
import { sqliteDialect } from '../sqlite.js';
|
|
6
|
+
import { normalizeSqlitePath } from './config.js';
|
|
7
|
+
import { createSqliteToolPool, introspectSqliteToolClient, sqliteToolIndexSummary, sqliteToolRuntime, } from './sqlite-tools.js';
|
|
8
|
+
const quote = sqliteDialect.quoteIdentifier;
|
|
9
|
+
const HISTORY_LIMIT = 100;
|
|
10
|
+
const LIMITATIONS = [
|
|
11
|
+
'Catalog and connection observations only; no integrity scan, user-row scan, repair or settings change.',
|
|
12
|
+
'Child-index coverage describes complete prefixes of equality-constrained columns only, not query plans, collations, parent-key validity or data integrity.',
|
|
13
|
+
'Connection foreign_keys is not evidence that historical rows satisfy foreign keys or that other connections enable enforcement.',
|
|
14
|
+
'Migration history has no native dirty marker; dirty state, pending files and checksum correctness are unknown.',
|
|
15
|
+
'Expression, default and predicate SQL, stored migration values and filesystem paths are withheld.',
|
|
16
|
+
'Collection requires an active read-only SQLite tool checkout and a caller-owned snapshot; no timeout or cancellation is imposed on native catalog reads.',
|
|
17
|
+
];
|
|
18
|
+
function report(checks) {
|
|
19
|
+
return {
|
|
20
|
+
formatVersion: 1,
|
|
21
|
+
engine: 'sqlite',
|
|
22
|
+
ok: checks.every((check) => check.status === 'pass'),
|
|
23
|
+
checks,
|
|
24
|
+
limitations: [...LIMITATIONS],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function unknown(code, facts = {}) {
|
|
28
|
+
// Native messages can contain schema SQL and literal values. Never echo them.
|
|
29
|
+
return { code, severity: 'warning', status: 'unknown', facts: { reason: 'unreadable-or-incomplete', ...facts } };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Collect within the caller's existing snapshot. Only registered SQLite tool
|
|
33
|
+
* clients are accepted; arbitrary pg-compatible executors never receive SQL.
|
|
34
|
+
* Does not release handles, alter settings or start/end a transaction.
|
|
35
|
+
*/
|
|
36
|
+
export async function collectSqliteDoctorReport(client) {
|
|
37
|
+
const runtime = sqliteToolRuntime();
|
|
38
|
+
const checks = [
|
|
39
|
+
{
|
|
40
|
+
code: 'SQLITE_RUNTIME',
|
|
41
|
+
severity: runtime.available ? 'info' : 'error',
|
|
42
|
+
status: runtime.available ? 'pass' : 'fail',
|
|
43
|
+
facts: { node: process.versions.node, minimumNode: runtime.minimumNode, nativeAvailable: runtime.available },
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
if (!runtime.available)
|
|
47
|
+
return report(checks);
|
|
48
|
+
let metadata;
|
|
49
|
+
try {
|
|
50
|
+
// Also checks the tool adapter's native ownership registration before any
|
|
51
|
+
// SQL is passed to the client's query interface.
|
|
52
|
+
metadata = introspectSqliteToolClient(client, {});
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
checks.push(unknown('SQLITE_CATALOG'));
|
|
56
|
+
return report(checks);
|
|
57
|
+
}
|
|
58
|
+
checks.push({
|
|
59
|
+
code: 'SQLITE_READ_ONLY',
|
|
60
|
+
severity: 'info',
|
|
61
|
+
status: 'pass',
|
|
62
|
+
facts: { enforcement: 'database-open-read-only', handleOwner: 'caller', collectorReleasesHandle: false },
|
|
63
|
+
});
|
|
64
|
+
try {
|
|
65
|
+
const version = (await client.query('SELECT sqlite_version() AS version')).rows[0]?.version;
|
|
66
|
+
checks[0].facts.databaseVersion = typeof version === 'string' ? version : null;
|
|
67
|
+
if (typeof version !== 'string')
|
|
68
|
+
checks[0] = unknown('SQLITE_RUNTIME', checks[0].facts);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
checks[0] = unknown('SQLITE_RUNTIME', checks[0].facts);
|
|
72
|
+
}
|
|
73
|
+
for (const [code, sql, key] of [
|
|
74
|
+
['SQLITE_JOURNAL_MODE', 'PRAGMA main.journal_mode', 'journal_mode'],
|
|
75
|
+
['SQLITE_FOREIGN_KEYS', 'PRAGMA foreign_keys', 'foreign_keys'],
|
|
76
|
+
]) {
|
|
77
|
+
try {
|
|
78
|
+
const value = (await client.query(sql)).rows[0]?.[key];
|
|
79
|
+
const valid = key === 'foreign_keys' ? value === 0 || value === 1 : typeof value === 'string';
|
|
80
|
+
checks.push(!valid
|
|
81
|
+
? unknown(code)
|
|
82
|
+
: {
|
|
83
|
+
code,
|
|
84
|
+
severity: key === 'foreign_keys' && value === 0 ? 'warning' : 'info',
|
|
85
|
+
status: key === 'foreign_keys' && value === 0 ? 'warn' : 'pass',
|
|
86
|
+
facts: { value, scope: key === 'foreign_keys' ? 'current-connection' : 'main-database', changed: false },
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
checks.push(unknown(code));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const tables = (await client.query('PRAGMA main.table_list')).rows
|
|
95
|
+
.filter((table) => table.schema === 'main' && !table.name.startsWith('sqlite_'))
|
|
96
|
+
.sort((a, b) => compare(a.name, b.name));
|
|
97
|
+
checks.push({
|
|
98
|
+
code: 'SQLITE_CATALOG',
|
|
99
|
+
severity: 'info',
|
|
100
|
+
status: 'pass',
|
|
101
|
+
facts: { tablesObserved: tables.filter((table) => table.type === 'table').length, scope: 'main' },
|
|
102
|
+
});
|
|
103
|
+
for (const table of tables) {
|
|
104
|
+
if (table.name.toLowerCase() === '_turbine_migrations' || table.type === 'view')
|
|
105
|
+
continue;
|
|
106
|
+
if (table.type !== 'table' || !Object.hasOwn(metadata.tables, table.name)) {
|
|
107
|
+
checks.push(unknown('SQLITE_FK_CHILD_INDEX', { table: table.name, reason: 'opaque-table' }));
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const foreignKeys = (await client.query(`PRAGMA main.foreign_key_list(${quote(table.name)})`))
|
|
112
|
+
.rows;
|
|
113
|
+
const indexes = (await client.query(`PRAGMA main.index_list(${quote(table.name)})`)).rows;
|
|
114
|
+
const keys = new Map();
|
|
115
|
+
let incomplete = false;
|
|
116
|
+
for (const index of indexes) {
|
|
117
|
+
try {
|
|
118
|
+
const rows = (await client.query(`PRAGMA main.index_xinfo(${quote(index.name)})`)).rows;
|
|
119
|
+
const ordered = rows.filter((key) => key.key === 1).sort((a, b) => a.seqno - b.seqno);
|
|
120
|
+
if (!ordered.length || ordered.some((key, i) => key.seqno !== i))
|
|
121
|
+
incomplete = true;
|
|
122
|
+
else
|
|
123
|
+
keys.set(index.name, ordered);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
incomplete = true;
|
|
127
|
+
}
|
|
128
|
+
const native = metadata.tables[table.name].indexes.find((entry) => entry.name === index.name);
|
|
129
|
+
if (!native || !sqliteToolIndexSummary(native))
|
|
130
|
+
incomplete = true;
|
|
131
|
+
}
|
|
132
|
+
// A rowid-alias primary key has no index_list entry. General metadata
|
|
133
|
+
// marks it generated; verify native INTEGER/PK shape as well.
|
|
134
|
+
const columns = (await client.query(`PRAGMA main.table_xinfo(${quote(table.name)})`)).rows;
|
|
135
|
+
const pk = columns.filter((column) => column.pk > 0);
|
|
136
|
+
const rowidAlias = pk.length === 1 &&
|
|
137
|
+
pk[0].type.toUpperCase() === 'INTEGER' &&
|
|
138
|
+
!indexes.some((index) => index.origin === 'pk') &&
|
|
139
|
+
metadata.tables[table.name].columns.some((column) => column.name === pk[0].name && column.isGenerated)
|
|
140
|
+
? pk[0].name
|
|
141
|
+
: undefined;
|
|
142
|
+
const groups = new Map();
|
|
143
|
+
for (const fk of foreignKeys)
|
|
144
|
+
groups.set(fk.id, [...(groups.get(fk.id) ?? []), fk]);
|
|
145
|
+
for (const [id, group] of [...groups].sort(([a], [b]) => a - b)) {
|
|
146
|
+
group.sort((a, b) => a.seq - b.seq);
|
|
147
|
+
const child = group.map((fk) => fk.from);
|
|
148
|
+
const facts = { table: table.name, foreignKeyId: id, parentTable: group[0].table, columns: child };
|
|
149
|
+
if (!columns.length ||
|
|
150
|
+
new Set(child).size !== child.length ||
|
|
151
|
+
group.some((fk, i) => fk.seq !== i || !columns.some((column) => column.name === fk.from))) {
|
|
152
|
+
checks.push(unknown('SQLITE_FK_CHILD_INDEX', facts));
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const covering = indexes
|
|
156
|
+
.filter((index) => {
|
|
157
|
+
const ordered = keys.get(index.name);
|
|
158
|
+
const prefix = ordered?.slice(0, child.length).map((key) => key.name);
|
|
159
|
+
// FK probes constrain every child column by equality. Their order
|
|
160
|
+
// within the complete leading prefix does not change coverage.
|
|
161
|
+
return index.partial === 0 && child.every((name) => prefix?.includes(name));
|
|
162
|
+
})
|
|
163
|
+
.map((index) => index.name)
|
|
164
|
+
.sort(compare);
|
|
165
|
+
const rowidCoverage = child.length === 1 && child[0] === rowidAlias;
|
|
166
|
+
if (covering.length || rowidCoverage) {
|
|
167
|
+
checks.push({
|
|
168
|
+
code: 'SQLITE_FK_CHILD_INDEX',
|
|
169
|
+
severity: 'info',
|
|
170
|
+
status: 'pass',
|
|
171
|
+
facts: { ...facts, coverage: 'structural-left-prefix', indexes: covering, rowidAlias: rowidCoverage },
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else if (incomplete ||
|
|
175
|
+
indexes.some((index) => index.partial !== 0 ||
|
|
176
|
+
keys
|
|
177
|
+
.get(index.name)
|
|
178
|
+
?.some((key, i, all) => key.cid < 0 || all.slice(0, i).some((previous) => previous.name === key.name)))) {
|
|
179
|
+
checks.push(unknown('SQLITE_FK_CHILD_INDEX', { ...facts, coverage: 'unknown' }));
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
checks.push({
|
|
183
|
+
code: 'SQLITE_FK_CHILD_INDEX',
|
|
184
|
+
severity: 'warning',
|
|
185
|
+
status: 'warn',
|
|
186
|
+
facts: {
|
|
187
|
+
...facts,
|
|
188
|
+
coverage: 'no-structural-left-prefix',
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
checks.push(unknown('SQLITE_FK_CHILD_INDEX', { table: table.name }));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
checks.push(unknown('SQLITE_CATALOG'));
|
|
201
|
+
}
|
|
202
|
+
checks.push(await migrationTracking(client));
|
|
203
|
+
return report(checks);
|
|
204
|
+
}
|
|
205
|
+
function compare(a, b) {
|
|
206
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
207
|
+
}
|
|
208
|
+
async function migrationTracking(client) {
|
|
209
|
+
const code = 'SQLITE_MIGRATION_TRACKING';
|
|
210
|
+
try {
|
|
211
|
+
const entries = (await client.query('SELECT name, type FROM main.sqlite_schema WHERE name = $1 COLLATE NOCASE', ['_turbine_migrations'])).rows;
|
|
212
|
+
if (!entries.length) {
|
|
213
|
+
return { code, severity: 'info', status: 'pass', facts: { visibility: 'absent', dirtyState: 'unknown' } };
|
|
214
|
+
}
|
|
215
|
+
const entry = entries[0];
|
|
216
|
+
const kind = (await client.query('PRAGMA main.table_list')).rows.find((table) => table.name === entry.name);
|
|
217
|
+
if (entry.type !== 'table' || kind?.type !== 'table')
|
|
218
|
+
return unknown(code, { visibility: 'opaque' });
|
|
219
|
+
const columns = (await client.query(`PRAGMA main.table_xinfo(${quote(entry.name)})`)).rows;
|
|
220
|
+
const canonical = columns.length === 4 &&
|
|
221
|
+
columns.every((column) => {
|
|
222
|
+
if (column.hidden !== 0)
|
|
223
|
+
return false;
|
|
224
|
+
return column.name === 'id'
|
|
225
|
+
? column.type.toUpperCase() === 'INTEGER' && column.pk === 1
|
|
226
|
+
: ['name', 'checksum', 'applied_at'].includes(column.name) &&
|
|
227
|
+
column.type.toUpperCase() === 'TEXT' &&
|
|
228
|
+
column.notnull === 1 &&
|
|
229
|
+
column.pk === 0;
|
|
230
|
+
});
|
|
231
|
+
if (!canonical)
|
|
232
|
+
return unknown(code, { visibility: 'noncanonical', dirtyState: 'unknown' });
|
|
233
|
+
// Match the migration reader's structural admission before inspecting rows.
|
|
234
|
+
const indexes = (await client.query(`PRAGMA main.index_list(${quote(entry.name)})`)).rows;
|
|
235
|
+
let uniqueName = false;
|
|
236
|
+
for (const index of indexes) {
|
|
237
|
+
if (index.unique !== 1 || index.partial !== 0)
|
|
238
|
+
continue;
|
|
239
|
+
const keys = (await client.query(`PRAGMA main.index_info(${quote(index.name)})`)).rows;
|
|
240
|
+
if (keys.length === 1 && keys[0].name === 'name')
|
|
241
|
+
uniqueName = true;
|
|
242
|
+
}
|
|
243
|
+
const triggers = (await client.query("SELECT 1 FROM main.sqlite_schema WHERE type = 'trigger' AND tbl_name = $1 COLLATE NOCASE LIMIT 1", [entry.name])).rows;
|
|
244
|
+
if (!uniqueName || triggers.length)
|
|
245
|
+
return unknown(code, { visibility: 'noncanonical', dirtyState: 'unknown' });
|
|
246
|
+
const tables = (await client.query("SELECT name FROM main.sqlite_schema WHERE type = 'table'"))
|
|
247
|
+
.rows;
|
|
248
|
+
for (const table of tables) {
|
|
249
|
+
const foreignKeys = (await client.query(`PRAGMA main.foreign_key_list(${quote(table.name)})`))
|
|
250
|
+
.rows;
|
|
251
|
+
if (foreignKeys.some((fk) => fk.table.toLowerCase() === '_turbine_migrations'))
|
|
252
|
+
return unknown(code, { visibility: 'noncanonical', dirtyState: 'unknown' });
|
|
253
|
+
}
|
|
254
|
+
// Bounded tracking-row inspection only. Never return names/checksums/times.
|
|
255
|
+
const rows = (await client.query(`SELECT (typeof(id) = 'integer' AND id > 0 AND typeof(name) = 'text' AND length(name) > 0 AND typeof(checksum) = 'text' AND typeof(applied_at) = 'text') AS valid FROM main.${quote(entry.name)} ORDER BY id LIMIT ${HISTORY_LIMIT + 1}`)).rows;
|
|
256
|
+
const truncated = rows.length > HISTORY_LIMIT;
|
|
257
|
+
const invalid = rows.slice(0, HISTORY_LIMIT).filter((row) => row.valid !== 1).length;
|
|
258
|
+
return {
|
|
259
|
+
code,
|
|
260
|
+
severity: invalid ? 'warning' : truncated ? 'warning' : 'info',
|
|
261
|
+
status: invalid ? 'warn' : truncated ? 'unknown' : 'pass',
|
|
262
|
+
facts: {
|
|
263
|
+
visibility: 'readable',
|
|
264
|
+
rowsInspected: Math.min(rows.length, HISTORY_LIMIT),
|
|
265
|
+
historyComplete: !truncated,
|
|
266
|
+
invalidStorageRows: invalid,
|
|
267
|
+
dirtyState: 'unknown',
|
|
268
|
+
checksumsVerified: false,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return unknown(code, { dirtyState: 'unknown' });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/** Preflight before any SQLite open, including an MCP snapshot checkout. */
|
|
277
|
+
export function assertSqliteDoctorFile(url) {
|
|
278
|
+
if (!sqliteToolRuntime().available)
|
|
279
|
+
throw new ValidationError(sqliteToolRuntime().reason);
|
|
280
|
+
// SQLite may create WAL/SHM files even for a readOnly database open. Require
|
|
281
|
+
// existing sidecars for a WAL-format file; never create them just to diagnose.
|
|
282
|
+
const path = normalizeSqlitePath(url);
|
|
283
|
+
try {
|
|
284
|
+
const fd = openSync(path, 'r');
|
|
285
|
+
try {
|
|
286
|
+
const header = Buffer.alloc(20);
|
|
287
|
+
readSync(fd, header, 0, header.length, 0);
|
|
288
|
+
if ((header[18] === 2 || header[19] === 2) && (!existsSync(`${path}-wal`) || !existsSync(`${path}-shm`))) {
|
|
289
|
+
throw new ValidationError('SQLite doctor requires existing WAL and SHM files for a WAL database; no sidecars were created. Use an owned read-only snapshot.');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
finally {
|
|
293
|
+
closeSync(fd);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
if (error instanceof ValidationError)
|
|
298
|
+
throw error;
|
|
299
|
+
throw new ValidationError('SQLite doctor requires an accessible existing database file.', { cause: error });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** Own a single existing file checkout and a stable read snapshot. */
|
|
303
|
+
export async function runSqliteDoctor(options) {
|
|
304
|
+
if (options.schema !== undefined && options.schema !== 'main') {
|
|
305
|
+
throw new ValidationError('SQLite doctor requires schema "main".');
|
|
306
|
+
}
|
|
307
|
+
assertSqliteDoctorFile(options.url);
|
|
308
|
+
const pool = createSqliteToolPool(options.url, options.schema ?? 'main');
|
|
309
|
+
let client;
|
|
310
|
+
let checkout;
|
|
311
|
+
let result;
|
|
312
|
+
const errors = [];
|
|
313
|
+
try {
|
|
314
|
+
client = await pool.connect();
|
|
315
|
+
checkout = guardCheckout(client);
|
|
316
|
+
await client.query('BEGIN');
|
|
317
|
+
result = await collectSqliteDoctorReport(client);
|
|
318
|
+
await client.query('COMMIT');
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
errors.push(error);
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
client?.release();
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
errors.push(error);
|
|
328
|
+
}
|
|
329
|
+
checkout?.detach();
|
|
330
|
+
try {
|
|
331
|
+
await pool.end();
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
errors.push(error);
|
|
335
|
+
}
|
|
336
|
+
if (errors.length) {
|
|
337
|
+
throw Object.assign(new AggregateError(errors, 'SQLite doctor failed; owned cleanup was attempted.'), {
|
|
338
|
+
report: result,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
/** Reject PostgreSQL-only options before the lazy SQLite transport opens. */
|
|
344
|
+
export function assertSqliteDoctorArguments(args, argv = []) {
|
|
345
|
+
const supported = new Set(['command', 'positional', 'engine', 'url', 'schema', 'json', 'verbose', 'help']);
|
|
346
|
+
for (const key of Object.keys(args)) {
|
|
347
|
+
if (!supported.has(key))
|
|
348
|
+
throw new ValidationError(`SQLite doctor does not support option "${key}".`);
|
|
349
|
+
}
|
|
350
|
+
if (args.subcommand !== undefined || args.positional.length) {
|
|
351
|
+
throw new ValidationError('SQLite doctor takes no positional arguments.');
|
|
352
|
+
}
|
|
353
|
+
const flags = new Set(['--engine', '--url', '-u', '--schema', '-s', '--json', '--verbose', '-v', '--help', '-h']);
|
|
354
|
+
for (let i = 1; i < argv.length; i++) {
|
|
355
|
+
const flag = argv[i];
|
|
356
|
+
if (!flags.has(flag))
|
|
357
|
+
throw new ValidationError(`SQLite doctor does not support argument "${flag}".`);
|
|
358
|
+
if (['--engine', '--url', '-u', '--schema', '-s'].includes(flag)) {
|
|
359
|
+
const value = argv[++i];
|
|
360
|
+
if (!value?.trim() || value.startsWith('-'))
|
|
361
|
+
throw new ValidationError(`SQLite doctor ${flag} requires a value.`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/** CLI presentation adapter; the PostgreSQL command keeps its own output. */
|
|
366
|
+
export async function cmdSqliteDoctor(args, config, argv = process.argv.slice(2)) {
|
|
367
|
+
assertSqliteDoctorArguments(args, argv);
|
|
368
|
+
if (config.engine !== 'sqlite' ||
|
|
369
|
+
config.schema !== 'main' ||
|
|
370
|
+
config.adapter ||
|
|
371
|
+
config.include.length ||
|
|
372
|
+
config.exclude.length) {
|
|
373
|
+
throw new ValidationError('SQLite doctor requires engine "sqlite", schema "main", no adapter and no table filters.');
|
|
374
|
+
}
|
|
375
|
+
const result = await runSqliteDoctor(config);
|
|
376
|
+
if (args.json)
|
|
377
|
+
console.log(JSON.stringify(result, null, 2));
|
|
378
|
+
else {
|
|
379
|
+
console.log('SQLite doctor (read-only catalog observations)');
|
|
380
|
+
for (const check of result.checks)
|
|
381
|
+
console.log(`${check.status} ${check.code} ${JSON.stringify(check.facts)}`);
|
|
382
|
+
for (const limitation of result.limitations)
|
|
383
|
+
console.log(`Limitation: ${limitation}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/** Engine-specific help does not open a file or require a native runtime. */
|
|
387
|
+
export function showSqliteDoctorHelp() {
|
|
388
|
+
console.log('turbine doctor --engine sqlite --url ./app.sqlite [--json]');
|
|
389
|
+
console.log('Read-only runtime, connection, catalog, child-index and migration tracking observations.');
|
|
390
|
+
console.log('Unknown results are explicit; no integrity scan, automatic repair, SQL input or settings change.');
|
|
391
|
+
console.log('Requires an existing stable file set; WAL databases need existing WAL and SHM sidecars.');
|
|
392
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResolvedConfig } from './config.js';
|
|
2
|
+
import type { CliArgs } from './index.js';
|
|
3
|
+
export declare function showSqliteHelp(): void;
|
|
4
|
+
export declare function cmdSqliteMigrate(args: CliArgs, config: ResolvedConfig, confirmDestructive: (report: string) => Promise<boolean>): Promise<void>;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/** SQLite command integration; the PostgreSQL CLI keeps its existing runner and output. */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { MigrationError, ValidationError } from '../errors.js';
|
|
4
|
+
import { printableCatalogName as shown } from '../introspect.js';
|
|
5
|
+
import { createMigration, formatChecksumMismatchError, listIgnoredSqlFiles, parseMigrationContent, statusGateProblems, summarizeMigrationStatus, } from './migrate.js';
|
|
6
|
+
import { assertSqliteMigrationFiles, inspectSqliteMigrationDeploy, migrateSqliteDeploy, migrateSqliteDown, migrateSqliteStatus, migrateSqliteUp, planSqliteMigrationRollback, scanSqliteMigrationDestructive, } from './sqlite-migrate.js';
|
|
7
|
+
import { banner, info, label, success, table, warn } from './ui.js';
|
|
8
|
+
export function showSqliteHelp() {
|
|
9
|
+
banner();
|
|
10
|
+
info('SQLite SQL-first workflow (--engine sqlite, --url <persistent filename or file: URL>):');
|
|
11
|
+
info('init -> migrate up -> generate (pull is an alias for generate)');
|
|
12
|
+
info('Existing databases: init or pull; status shows the catalog.');
|
|
13
|
+
info('migrate create <name> creates a file to edit with -- UP and -- DOWN SQL.');
|
|
14
|
+
info('migrate up [--step N], deploy [--wait[=seconds]], down [--step N], status [--exit-code]');
|
|
15
|
+
info('up/down/deploy support --dry-run and --allow-drift. up/down require --allow-destructive for destructive SQL without interactive confirmation.');
|
|
16
|
+
info('deploy is noninteractive and permits destructive SQL. A selected batch commits atomically.');
|
|
17
|
+
info('Native migration writes require Node >=24.10; migration status needs Node 22.x >=22.16 or >=24.');
|
|
18
|
+
info('Code-first schema diff: turbine push --schema-file <file> --dry-run; apply: turbine push --schema-file <file>.');
|
|
19
|
+
info('Recipes, views and PostgreSQL adapters are not supported.');
|
|
20
|
+
info('Explicit seed modules: turbine seed --engine sqlite --help (never run automatically by init).');
|
|
21
|
+
}
|
|
22
|
+
function validateFlags(args, config, sub) {
|
|
23
|
+
if (args.auto ||
|
|
24
|
+
args.fromDiff ||
|
|
25
|
+
args.recipe ||
|
|
26
|
+
args.allowPending ||
|
|
27
|
+
args.allowPooler ||
|
|
28
|
+
config.schemaFileConfigured) {
|
|
29
|
+
throw new ValidationError('SQLite migrations do not support schema diff, recipes, schemaFile, --allow-pending or --allow-pooler. Create and edit explicit UP/DOWN SQL.');
|
|
30
|
+
}
|
|
31
|
+
if (args.exitCode && sub !== 'status' && sub !== 'list') {
|
|
32
|
+
throw new ValidationError('--exit-code only applies to migrate status.');
|
|
33
|
+
}
|
|
34
|
+
if (args.wait !== undefined && sub !== 'deploy') {
|
|
35
|
+
throw new ValidationError('--wait only applies to migrate deploy.');
|
|
36
|
+
}
|
|
37
|
+
if (args.step !== undefined && sub !== 'up' && sub !== 'down') {
|
|
38
|
+
throw new ValidationError('--step only applies to SQLite migrate up/down; deploy always applies the entire pending batch.');
|
|
39
|
+
}
|
|
40
|
+
if (args.dryRun && !['up', 'down', 'deploy'].includes(sub)) {
|
|
41
|
+
throw new ValidationError('--dry-run only applies to SQLite migrate up/down/deploy.');
|
|
42
|
+
}
|
|
43
|
+
if (args.force) {
|
|
44
|
+
throw new ValidationError('SQLite migrations use --allow-drift to explicitly rebaseline modified files; --force is not supported.');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function inventory(files, section, printSql = false) {
|
|
48
|
+
assertSqliteMigrationFiles(files, section);
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
const sql = parseMigrationContent(readFileSync(file.path, 'utf8'), file.path)[section];
|
|
51
|
+
label('Migration', shown(file.filename));
|
|
52
|
+
const destructive = scanSqliteMigrationDestructive(sql);
|
|
53
|
+
if (destructive.length) {
|
|
54
|
+
warn(`DESTRUCTIVE SQL: ${destructive.map((hit) => hit.kind).join(', ')}`);
|
|
55
|
+
}
|
|
56
|
+
if (printSql)
|
|
57
|
+
console.log(sql);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export async function cmdSqliteMigrate(args, config, confirmDestructive) {
|
|
61
|
+
const sub = args.subcommand;
|
|
62
|
+
if (!sub || sub === 'help') {
|
|
63
|
+
showSqliteHelp();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!['create', 'up', 'deploy', 'down', 'status', 'list'].includes(sub)) {
|
|
67
|
+
throw new ValidationError(`Unknown migrate subcommand: ${sub}`);
|
|
68
|
+
}
|
|
69
|
+
validateFlags(args, config, sub);
|
|
70
|
+
banner();
|
|
71
|
+
if (sub === 'create') {
|
|
72
|
+
const name = args.positional[0];
|
|
73
|
+
if (!name || args.positional.length !== 1)
|
|
74
|
+
throw new ValidationError('Usage: turbine migrate create <name>');
|
|
75
|
+
const file = createMigration(config.migrationsDir, name);
|
|
76
|
+
success(`Created ${shown(file.path)}`);
|
|
77
|
+
info('Edit its UP/DOWN SQLite SQL, then run turbine migrate up.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (args.positional.length)
|
|
81
|
+
throw new ValidationError(`Unexpected arguments for migrate ${sub}.`);
|
|
82
|
+
if (!config.url)
|
|
83
|
+
throw new ValidationError('SQLite migrations need --url <filename>, config.url, or DATABASE_URL.');
|
|
84
|
+
label('SQLite database', shown(config.url));
|
|
85
|
+
label('Migrations', shown(config.migrationsDir));
|
|
86
|
+
const ignored = listIgnoredSqlFiles(config.migrationsDir);
|
|
87
|
+
for (const name of ignored)
|
|
88
|
+
warn(`Not a migration (expected YYYYMMDDHHMMSS_name.sql): ${shown(name)}`);
|
|
89
|
+
const options = { schema: config.schema, allowDrift: args.allowDrift };
|
|
90
|
+
if (sub === 'status' || sub === 'list') {
|
|
91
|
+
const statuses = await migrateSqliteStatus(config.url, config.migrationsDir, options);
|
|
92
|
+
const health = summarizeMigrationStatus(statuses);
|
|
93
|
+
info(`${statuses.filter((s) => s.applied).length} applied, ${statuses.filter((s) => !s.applied).length} pending`);
|
|
94
|
+
console.log(table(['Status', 'Migration', 'Applied at'], statuses.map((s) => [
|
|
95
|
+
s.missingFile ? 'Missing file' : s.checksumValid === false ? 'Drifted' : s.applied ? 'Applied' : 'Pending',
|
|
96
|
+
shown(s.file.filename),
|
|
97
|
+
s.appliedAt?.toISOString() ?? '-',
|
|
98
|
+
])));
|
|
99
|
+
const problems = statusGateProblems(health, ignored.map(shown));
|
|
100
|
+
if (problems.length)
|
|
101
|
+
warn(`Migration history is not clean: ${problems.join(', ')}`);
|
|
102
|
+
if (args.exitCode && problems.length)
|
|
103
|
+
process.exitCode = 2;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (args.allowDrift)
|
|
107
|
+
warn('--allow-drift rebaselines modified files; their previous SQL is not re-run. Missing files still block.');
|
|
108
|
+
if (sub === 'deploy')
|
|
109
|
+
warn('Deploy permits destructive SQLite SQL without prompting.');
|
|
110
|
+
if (args.dryRun) {
|
|
111
|
+
let files;
|
|
112
|
+
const direction = sub === 'down' ? 'down' : 'up';
|
|
113
|
+
if (sub === 'down') {
|
|
114
|
+
const plan = await planSqliteMigrationRollback(config.url, config.migrationsDir, { ...options, step: args.step });
|
|
115
|
+
if (plan.stoppedAt)
|
|
116
|
+
throw new MigrationError(`${plan.stoppedAt.name}: ${plan.stoppedAt.error}; the entire rollback batch would be refused.`);
|
|
117
|
+
files = plan.toRollback;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const plan = await inspectSqliteMigrationDeploy(config.url, config.migrationsDir, options);
|
|
121
|
+
const blocking = plan.mismatches.filter((m) => m.type === 'missing' || !args.allowDrift);
|
|
122
|
+
if (blocking.length)
|
|
123
|
+
throw new MigrationError(formatChecksumMismatchError(blocking));
|
|
124
|
+
files = sub === 'up' ? plan.pending.slice(0, args.step) : plan.pending;
|
|
125
|
+
for (const order of plan.outOfOrder)
|
|
126
|
+
warn(`Out of order: ${shown(order.applied)} predates ${shown(order.newestPrior)}.`);
|
|
127
|
+
}
|
|
128
|
+
inventory(files, direction, true);
|
|
129
|
+
info(`Dry run: ${files.length} migration(s); no database or history changes made.`);
|
|
130
|
+
info('SQL is displayed, not executed. Native authorization, SQL validity and foreign key checks run during execution.');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// The native runner re-reads files/history after acquiring its lock. A preview
|
|
134
|
+
// cannot authorize writes or turn a stale pending list into an execution plan.
|
|
135
|
+
const execute = (allowDestructive) => sub === 'down'
|
|
136
|
+
? migrateSqliteDown(config.url, config.migrationsDir, { ...options, step: args.step, allowDestructive })
|
|
137
|
+
: sub === 'deploy'
|
|
138
|
+
? migrateSqliteDeploy(config.url, config.migrationsDir, {
|
|
139
|
+
...options,
|
|
140
|
+
lockWaitMs: args.wait === undefined ? undefined : args.wait * 1000,
|
|
141
|
+
onLockWait: () => warn(`Another writer holds the SQLite lock; waiting up to ${args.wait}s.`),
|
|
142
|
+
})
|
|
143
|
+
: migrateSqliteUp(config.url, config.migrationsDir, { ...options, step: args.step, allowDestructive });
|
|
144
|
+
let result;
|
|
145
|
+
try {
|
|
146
|
+
result = await execute(args.allowDestructive === true);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (!(error instanceof Error) ||
|
|
150
|
+
!error.message.includes('DESTRUCTIVE') ||
|
|
151
|
+
sub === 'deploy' ||
|
|
152
|
+
args.allowDestructive)
|
|
153
|
+
throw error;
|
|
154
|
+
if (!(await confirmDestructive(error.message)))
|
|
155
|
+
throw new MigrationError('Aborted; no SQLite migrations or history changes were committed.');
|
|
156
|
+
result = await execute(true);
|
|
157
|
+
}
|
|
158
|
+
if (result.errors.length) {
|
|
159
|
+
throw new MigrationError(`SQLite migration batch rolled back: ${result.errors.map((e) => `${shown(e.file.filename)}: ${e.error}`).join('\n')}`);
|
|
160
|
+
}
|
|
161
|
+
const files = 'applied' in result ? result.applied : result.rolledBack;
|
|
162
|
+
success(`${files.length} migration(s) ${sub === 'down' ? 'rolled back' : 'applied'}`);
|
|
163
|
+
for (const file of files)
|
|
164
|
+
info(shown(file.filename));
|
|
165
|
+
for (const baseline of result.rebaselined)
|
|
166
|
+
warn(`Re-baselined ${shown(baseline.name)}: ${baseline.from} -> ${baseline.to}`);
|
|
167
|
+
if ('outOfOrder' in result) {
|
|
168
|
+
for (const order of result.outOfOrder)
|
|
169
|
+
warn(`Applied ${shown(order.applied)} out of order, before ${shown(order.newestPrior)}.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import type { DestructiveStatement } from './destructive.js';
|
|
3
|
+
import { type AppliedMigration, type MigrationDeployPlan, type MigrationFile, type MigrationRunResult, type MigrationStatus, type RebaselinedChecksum } from './migrate.js';
|
|
4
|
+
export interface SqliteMigrationOptions {
|
|
5
|
+
/** SQLite has one migration schema: main. */
|
|
6
|
+
schema?: string;
|
|
7
|
+
/** PostgreSQL-compatible adapter locks cannot own a SQLite transaction. */
|
|
8
|
+
adapter?: never;
|
|
9
|
+
dialect?: never;
|
|
10
|
+
lockWaitMs?: number;
|
|
11
|
+
onLockWait?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface SqliteMigrationUpOptions extends SqliteMigrationOptions {
|
|
14
|
+
step?: number;
|
|
15
|
+
allowDrift?: boolean;
|
|
16
|
+
force?: boolean;
|
|
17
|
+
allowDestructive?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface SqliteMigrationDownOptions extends SqliteMigrationOptions {
|
|
20
|
+
step?: number;
|
|
21
|
+
allowDrift?: boolean;
|
|
22
|
+
allowDestructive?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface SqliteMigrationDownResult {
|
|
25
|
+
rolledBack: MigrationFile[];
|
|
26
|
+
errors: Array<{
|
|
27
|
+
file: MigrationFile;
|
|
28
|
+
error: string;
|
|
29
|
+
}>;
|
|
30
|
+
rebaselined: RebaselinedChecksum[];
|
|
31
|
+
}
|
|
32
|
+
/** Static inventory for CLI confirmation. Native authorization also sees trigger effects. */
|
|
33
|
+
export declare function scanSqliteMigrationDestructive(sql: string): DestructiveStatement[];
|
|
34
|
+
/** Read-only static preflight for CLI previews. Native authorization is execution-only. */
|
|
35
|
+
export declare function assertSqliteMigrationFiles(files: readonly MigrationFile[], direction: 'up' | 'down'): void;
|
|
36
|
+
declare function rollbackPlan(applied: AppliedMigration[], migrationsDir: string, options?: SqliteMigrationDownOptions): {
|
|
37
|
+
toRollback: MigrationFile[];
|
|
38
|
+
stoppedAt: {
|
|
39
|
+
name: string;
|
|
40
|
+
error: string;
|
|
41
|
+
};
|
|
42
|
+
} | {
|
|
43
|
+
toRollback: MigrationFile[];
|
|
44
|
+
stoppedAt: null;
|
|
45
|
+
};
|
|
46
|
+
export declare function inspectSqliteMigrationDeploy(filename: string, migrationsDir: string, options?: SqliteMigrationOptions): Promise<MigrationDeployPlan>;
|
|
47
|
+
export declare function planSqliteMigrationRollback(filename: string, migrationsDir: string, options?: SqliteMigrationDownOptions): Promise<ReturnType<typeof rollbackPlan>>;
|
|
48
|
+
export declare function migrateSqliteStatus(filename: string, migrationsDir: string, options?: SqliteMigrationOptions): Promise<MigrationStatus[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Internal schema lifecycle seam. Owns the handle and BEGIN IMMEDIATE; callbacks
|
|
51
|
+
* are synchronous, must leave the transaction open, and cannot write history.
|
|
52
|
+
* History and its AUTOINCREMENT sequence are checked before committing.
|
|
53
|
+
*/
|
|
54
|
+
export declare function withSqliteSchemaTransaction<T>(filename: string, run: (db: DatabaseSync) => T, options?: SqliteMigrationOptions): T;
|
|
55
|
+
/** One native writer transaction covers the entire selected batch. */
|
|
56
|
+
export declare function migrateSqliteUp(filename: string, migrationsDir: string, options?: SqliteMigrationUpOptions): Promise<MigrationRunResult>;
|
|
57
|
+
export declare function migrateSqliteDeploy(filename: string, migrationsDir: string, options?: SqliteMigrationOptions & {
|
|
58
|
+
allowDrift?: boolean;
|
|
59
|
+
}): Promise<MigrationRunResult>;
|
|
60
|
+
export declare function migrateSqliteDown(filename: string, migrationsDir: string, options?: SqliteMigrationDownOptions): Promise<SqliteMigrationDownResult>;
|
|
61
|
+
export {};
|