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,316 @@
|
|
|
1
|
+
/** Scoped structural MySQL diagnostics on one existing read-only tool snapshot. */
|
|
2
|
+
import { guardCheckout } from '../connection-guard.js';
|
|
3
|
+
import { ValidationError } from '../errors.js';
|
|
4
|
+
import { createMysqlToolPool, introspectMysqlToolClient, mysqlToolIndexSummary } from './mysql-tools.js';
|
|
5
|
+
const CODES = [
|
|
6
|
+
'MYSQL_RUNTIME',
|
|
7
|
+
'MYSQL_VISIBILITY',
|
|
8
|
+
'MYSQL_SCOPE',
|
|
9
|
+
'MYSQL_ENGINES',
|
|
10
|
+
'MYSQL_CONSTRAINTS',
|
|
11
|
+
'MYSQL_FOREIGN_KEYS',
|
|
12
|
+
'MYSQL_INDEXES',
|
|
13
|
+
'MYSQL_MIGRATIONS',
|
|
14
|
+
];
|
|
15
|
+
const MODES = new Set('ALLOW_INVALID_DATES ANSI_QUOTES ERROR_FOR_DIVISION_BY_ZERO HIGH_NOT_PRECEDENCE IGNORE_SPACE NO_AUTO_VALUE_ON_ZERO NO_BACKSLASH_ESCAPES NO_DIR_IN_CREATE NO_ENGINE_SUBSTITUTION NO_UNSIGNED_SUBTRACTION NO_ZERO_DATE NO_ZERO_IN_DATE ONLY_FULL_GROUP_BY PAD_CHAR_TO_FULL_LENGTH PIPES_AS_CONCAT REAL_AS_FLOAT STRICT_ALL_TABLES STRICT_TRANS_TABLES TIME_TRUNCATE_FRACTIONAL'.split(' '));
|
|
16
|
+
const LIMITATIONS = [
|
|
17
|
+
'Catalog visibility requires proven database-wide grants. Roles and partial revokes may cause refusal.',
|
|
18
|
+
'The owned transport requests a read-only repeatable-read consistent snapshot. Concurrent DDL and nontransactional tables are not snapshot-isolated.',
|
|
19
|
+
'Only declared foreign keys and visible structural index facts are assessed. Opaque, prefix and invisible keys retain unknown coverage; no index necessity or performance is inferred.',
|
|
20
|
+
'Migration counts and dirty-journal presence are observed only. Files, checksums, row validity, pending migrations and schema drift are not assessed.',
|
|
21
|
+
'No data rows, SQL expressions, defaults, predicates, credentials, endpoints or grant text are reported. No repair SQL is generated.',
|
|
22
|
+
];
|
|
23
|
+
/** Does not open, release, commit or roll back the supplied snapshot. */
|
|
24
|
+
export async function collectMysqlDoctor(snapshot, options = {}) {
|
|
25
|
+
const checks = CODES.map((code) => ({
|
|
26
|
+
code,
|
|
27
|
+
status: 'unknown',
|
|
28
|
+
severity: 'warning',
|
|
29
|
+
facts: { reason: 'not-assessed' },
|
|
30
|
+
}));
|
|
31
|
+
let current = 'MYSQL_RUNTIME';
|
|
32
|
+
const set = (code, status, facts) => {
|
|
33
|
+
checks[CODES.indexOf(code)] = {
|
|
34
|
+
code,
|
|
35
|
+
status,
|
|
36
|
+
severity: status === 'pass' ? 'info' : status === 'fail' ? 'error' : 'warning',
|
|
37
|
+
facts,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
const runtime = (await snapshot.query('SELECT VERSION() AS version, @@session.sql_mode AS sql_mode, @@session.foreign_key_checks AS foreign_key_checks')).rows[0];
|
|
42
|
+
const version = typeof runtime?.version === 'string' ? /^8\.\d+\.\d+(?=-|$)/.exec(runtime.version)?.[0] : undefined;
|
|
43
|
+
if (!version || /mariadb/i.test(runtime?.version ?? '') || typeof runtime?.sql_mode !== 'string') {
|
|
44
|
+
set(current, 'unknown', { reason: 'unrecognized-native-runtime' });
|
|
45
|
+
return finish();
|
|
46
|
+
}
|
|
47
|
+
const modes = [...new Set(runtime.sql_mode.split(',').filter(Boolean))].sort();
|
|
48
|
+
const foreignKeyChecks = runtime.foreign_key_checks === 1 || runtime.foreign_key_checks === 0 ? runtime.foreign_key_checks === 1 : null;
|
|
49
|
+
set(current, foreignKeyChecks === true && modes.every((mode) => MODES.has(mode)) ? 'pass' : 'warn', {
|
|
50
|
+
version,
|
|
51
|
+
sqlModes: modes.filter((mode) => MODES.has(mode)),
|
|
52
|
+
unrecognizedSqlModeCount: modes.filter((mode) => !MODES.has(mode)).length,
|
|
53
|
+
foreignKeyChecks,
|
|
54
|
+
});
|
|
55
|
+
current = 'MYSQL_VISIBILITY';
|
|
56
|
+
try {
|
|
57
|
+
await snapshot.assertVisibility();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
set(current, 'unknown', { reason: 'catalog-visibility-unproved', assessment: 'refused' });
|
|
61
|
+
return finish();
|
|
62
|
+
}
|
|
63
|
+
set(current, 'pass', { coverage: 'database-wide-grants-proved' });
|
|
64
|
+
current = 'MYSQL_SCOPE';
|
|
65
|
+
const metadata = await introspectMysqlToolClient(snapshot.client, {
|
|
66
|
+
...options,
|
|
67
|
+
exclude: [...(options.exclude ?? []), '_turbine_migration_state'],
|
|
68
|
+
});
|
|
69
|
+
const tables = Object.values(metadata.tables).sort((a, b) => compare(a.name, b.name));
|
|
70
|
+
const selected = new Set(tables.map((table) => table.name));
|
|
71
|
+
const catalog = (await snapshot.query(`SELECT TABLE_NAME, TABLE_TYPE, ENGINE FROM information_schema.TABLES
|
|
72
|
+
WHERE TABLE_SCHEMA = :p1 ORDER BY TABLE_NAME`, [snapshot.schema])).rows;
|
|
73
|
+
set(current, 'pass', {
|
|
74
|
+
selectedTables: tables.length,
|
|
75
|
+
visibleCatalogObjects: catalog.length,
|
|
76
|
+
excludedCatalogObjects: catalog.filter((row) => !selected.has(row.TABLE_NAME)).length,
|
|
77
|
+
filtersApplied: Boolean(options.include?.length || options.exclude?.length),
|
|
78
|
+
migrationScope: 'whole-selected-database',
|
|
79
|
+
});
|
|
80
|
+
current = 'MYSQL_ENGINES';
|
|
81
|
+
const engines = tables.map((table) => {
|
|
82
|
+
const row = catalog.find((entry) => entry.TABLE_NAME === table.name);
|
|
83
|
+
const engine = typeof row?.ENGINE === 'string' &&
|
|
84
|
+
/^(InnoDB|MyISAM|MEMORY|CSV|ARCHIVE|BLACKHOLE|MERGE|MRG_MYISAM|FEDERATED|NDB|NDBCLUSTER)$/i.test(row.ENGINE)
|
|
85
|
+
? row.ENGINE.toUpperCase()
|
|
86
|
+
: null;
|
|
87
|
+
return {
|
|
88
|
+
table: table.name,
|
|
89
|
+
engine,
|
|
90
|
+
transactional: engine === 'INNODB'
|
|
91
|
+
? true
|
|
92
|
+
: engine !== null &&
|
|
93
|
+
['MYISAM', 'MEMORY', 'CSV', 'ARCHIVE', 'BLACKHOLE', 'MERGE', 'MRG_MYISAM'].includes(engine)
|
|
94
|
+
? false
|
|
95
|
+
: null,
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
set(current, engines.some((row) => row.transactional === false)
|
|
99
|
+
? 'warn'
|
|
100
|
+
: engines.some((row) => row.transactional === null)
|
|
101
|
+
? 'unknown'
|
|
102
|
+
: 'pass', { tables: engines, assessment: 'InnoDB transactional suitability only; other engines are not certified' });
|
|
103
|
+
current = 'MYSQL_CONSTRAINTS';
|
|
104
|
+
const constraints = (await snapshot.query(`SELECT TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE, ENFORCED FROM information_schema.TABLE_CONSTRAINTS
|
|
105
|
+
WHERE TABLE_SCHEMA = :p1 ORDER BY TABLE_NAME, CONSTRAINT_NAME`, [snapshot.schema])).rows
|
|
106
|
+
.filter((row) => selected.has(row.TABLE_NAME))
|
|
107
|
+
.map((row) => ({
|
|
108
|
+
table: row.TABLE_NAME,
|
|
109
|
+
constraint: row.CONSTRAINT_NAME,
|
|
110
|
+
type: ['PRIMARY KEY', 'UNIQUE', 'FOREIGN KEY', 'CHECK'].includes(row.CONSTRAINT_TYPE)
|
|
111
|
+
? row.CONSTRAINT_TYPE
|
|
112
|
+
: null,
|
|
113
|
+
enforced: row.ENFORCED === 'YES' ? true : row.ENFORCED === 'NO' ? false : null,
|
|
114
|
+
}));
|
|
115
|
+
set(current, constraints.some((row) => row.enforced === false)
|
|
116
|
+
? 'warn'
|
|
117
|
+
: constraints.some((row) => row.type === null || row.enforced === null)
|
|
118
|
+
? 'unknown'
|
|
119
|
+
: 'pass', {
|
|
120
|
+
constraints,
|
|
121
|
+
assessment: 'declarations and enforcement flags only; constraint expressions withheld and row integrity not scanned',
|
|
122
|
+
});
|
|
123
|
+
current = 'MYSQL_FOREIGN_KEYS';
|
|
124
|
+
const keys = (await snapshot.query(`SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, ORDINAL_POSITION,
|
|
125
|
+
REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME, (REFERENCED_TABLE_SCHEMA = TABLE_SCHEMA) AS target_local
|
|
126
|
+
FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = :p1 AND REFERENCED_TABLE_NAME IS NOT NULL
|
|
127
|
+
ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION`, [snapshot.schema])).rows;
|
|
128
|
+
const groups = new Map();
|
|
129
|
+
for (const key of keys) {
|
|
130
|
+
if (!selected.has(key.TABLE_NAME))
|
|
131
|
+
continue;
|
|
132
|
+
const id = JSON.stringify([key.TABLE_NAME, key.CONSTRAINT_NAME]);
|
|
133
|
+
const group = groups.get(id) ?? [];
|
|
134
|
+
group.push(key);
|
|
135
|
+
groups.set(id, group);
|
|
136
|
+
}
|
|
137
|
+
const foreignKeys = [...groups.values()].map((group) => ({
|
|
138
|
+
table: group[0].TABLE_NAME,
|
|
139
|
+
constraint: group[0].CONSTRAINT_NAME,
|
|
140
|
+
columns: group.map((key) => key.COLUMN_NAME),
|
|
141
|
+
targetTable: group[0].REFERENCED_TABLE_NAME,
|
|
142
|
+
targetColumns: group.map((key) => key.REFERENCED_COLUMN_NAME),
|
|
143
|
+
targetScope: group.every((key) => key.target_local === 1) ? 'same-database' : 'external-database',
|
|
144
|
+
}));
|
|
145
|
+
set(current, foreignKeyChecks === true ? 'pass' : 'warn', {
|
|
146
|
+
declared: foreignKeys,
|
|
147
|
+
enforcement: foreignKeyChecks,
|
|
148
|
+
assessment: 'declarations only; existing row integrity not scanned',
|
|
149
|
+
});
|
|
150
|
+
current = 'MYSQL_INDEXES';
|
|
151
|
+
const primaryKeys = (await snapshot.query(`SELECT TABLE_NAME, COLUMN_NAME, SUB_PART, SEQ_IN_INDEX, INDEX_TYPE, IS_VISIBLE
|
|
152
|
+
FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = :p1 AND INDEX_NAME = 'PRIMARY'
|
|
153
|
+
ORDER BY TABLE_NAME, SEQ_IN_INDEX`, [snapshot.schema])).rows;
|
|
154
|
+
const indexes = tables.flatMap((table) => table.indexes.map((index) => ({ table: table.name, ...mysqlToolIndexSummary(index) })));
|
|
155
|
+
function coverage(tableName, columns) {
|
|
156
|
+
const table = metadata.tables[tableName];
|
|
157
|
+
if (!table || !selected.has(tableName))
|
|
158
|
+
return 'unknown-outside-scope';
|
|
159
|
+
const primary = primaryKeys.filter((key) => key.TABLE_NAME === tableName);
|
|
160
|
+
if (primary.length >= columns.length &&
|
|
161
|
+
columns.every((column, i) => primary[i]?.COLUMN_NAME === column &&
|
|
162
|
+
primary[i]?.SUB_PART === null &&
|
|
163
|
+
primary[i]?.INDEX_TYPE === 'BTREE' &&
|
|
164
|
+
primary[i]?.IS_VISIBLE === 'YES'))
|
|
165
|
+
return 'observed-primary-leading-columns';
|
|
166
|
+
let opaque = primary.some((key) => key.SUB_PART !== null || key.COLUMN_NAME === null || key.INDEX_TYPE !== 'BTREE' || key.IS_VISIBLE !== 'YES');
|
|
167
|
+
for (const index of table.indexes) {
|
|
168
|
+
const summary = mysqlToolIndexSummary(index);
|
|
169
|
+
if (!summary) {
|
|
170
|
+
opaque = true;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const keys = summary.keys;
|
|
174
|
+
if (summary.type === 'BTREE' &&
|
|
175
|
+
summary.visible === true &&
|
|
176
|
+
keys.length >= columns.length &&
|
|
177
|
+
columns.every((column, i) => keys[i]?.column === column && keys[i]?.prefixLength === null))
|
|
178
|
+
return 'observed-leading-columns';
|
|
179
|
+
// Any opaque key is conservative unknown; it is never a missing index.
|
|
180
|
+
if (summary.type !== 'BTREE' ||
|
|
181
|
+
summary.visible !== true ||
|
|
182
|
+
keys.some((key) => key.column === null || key.prefixLength !== null))
|
|
183
|
+
opaque = true;
|
|
184
|
+
}
|
|
185
|
+
return opaque ? 'unknown-opaque-keys' : 'not-observed';
|
|
186
|
+
}
|
|
187
|
+
const coverageFacts = foreignKeys.map((key) => ({
|
|
188
|
+
...key,
|
|
189
|
+
sourceCoverage: coverage(key.table, key.columns),
|
|
190
|
+
targetCoverage: key.targetScope === 'same-database' ? coverage(key.targetTable, key.targetColumns) : 'unknown-outside-scope',
|
|
191
|
+
}));
|
|
192
|
+
const verdicts = coverageFacts.flatMap((key) => [key.sourceCoverage, key.targetCoverage]);
|
|
193
|
+
set(current, verdicts.includes('not-observed')
|
|
194
|
+
? 'warn'
|
|
195
|
+
: verdicts.some((value) => value.startsWith('unknown'))
|
|
196
|
+
? 'unknown'
|
|
197
|
+
: 'pass', {
|
|
198
|
+
indexes,
|
|
199
|
+
primaryKeys: primaryKeys
|
|
200
|
+
.filter((key) => selected.has(key.TABLE_NAME))
|
|
201
|
+
.map((key) => ({
|
|
202
|
+
table: key.TABLE_NAME,
|
|
203
|
+
column: key.COLUMN_NAME,
|
|
204
|
+
prefixLength: key.SUB_PART,
|
|
205
|
+
position: key.SEQ_IN_INDEX,
|
|
206
|
+
type: key.INDEX_TYPE === 'BTREE' ? 'BTREE' : null,
|
|
207
|
+
visible: key.IS_VISIBLE === 'YES' ? true : key.IS_VISIBLE === 'NO' ? false : null,
|
|
208
|
+
})),
|
|
209
|
+
foreignKeys: coverageFacts,
|
|
210
|
+
assessment: 'ordered full-column BTREE prefixes only; no index SQL or performance recommendation',
|
|
211
|
+
});
|
|
212
|
+
current = 'MYSQL_MIGRATIONS';
|
|
213
|
+
const history = catalog.find((row) => row.TABLE_NAME === '_turbine_migrations');
|
|
214
|
+
const journal = catalog.find((row) => row.TABLE_NAME === '_turbine_migration_state');
|
|
215
|
+
const counts = {
|
|
216
|
+
history: history ? 'present' : 'not-observed',
|
|
217
|
+
journal: journal ? 'present' : 'not-observed',
|
|
218
|
+
appliedCount: null,
|
|
219
|
+
dirtyCount: null,
|
|
220
|
+
integrity: 'not-assessed',
|
|
221
|
+
};
|
|
222
|
+
for (const [row, name, output] of [
|
|
223
|
+
[history, '_turbine_migrations', 'appliedCount'],
|
|
224
|
+
[journal, '_turbine_migration_state', 'dirtyCount'],
|
|
225
|
+
]) {
|
|
226
|
+
if (!row)
|
|
227
|
+
continue;
|
|
228
|
+
if (row.TABLE_TYPE !== 'BASE TABLE' || row.ENGINE?.toUpperCase() !== 'INNODB') {
|
|
229
|
+
set(current, 'unknown', { ...counts, reason: 'tracking-object-not-InnoDB-table' });
|
|
230
|
+
return finish();
|
|
231
|
+
}
|
|
232
|
+
// Names are constants, schema is quoted independently of sql_mode.
|
|
233
|
+
const count = (await snapshot.query(`SELECT COUNT(*) AS n FROM ${quote(snapshot.schema)}.${quote(name)}`)).rows[0]?.n;
|
|
234
|
+
const value = Number(count);
|
|
235
|
+
if ((typeof count !== 'number' && !(typeof count === 'string' && /^(0|[1-9]\d*)$/.test(count))) ||
|
|
236
|
+
!Number.isSafeInteger(value) ||
|
|
237
|
+
value < 0)
|
|
238
|
+
throw new Error('Invalid count');
|
|
239
|
+
counts[output] = value;
|
|
240
|
+
}
|
|
241
|
+
set(current, Number(counts.dirtyCount) > 0 ? 'fail' : history && journal ? 'pass' : 'unknown', counts);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
set(current, 'fail', { reason: 'collection-failed', detailsWithheld: true });
|
|
245
|
+
}
|
|
246
|
+
return finish();
|
|
247
|
+
function finish() {
|
|
248
|
+
return {
|
|
249
|
+
formatVersion: 1,
|
|
250
|
+
engine: 'mysql',
|
|
251
|
+
ok: checks.every((check) => check.status === 'pass'),
|
|
252
|
+
checks,
|
|
253
|
+
limitations: [...LIMITATIONS],
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function compare(a, b) {
|
|
258
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
259
|
+
}
|
|
260
|
+
function quote(name) {
|
|
261
|
+
if (!name || Array.from(name).length > 64 || name.includes('\0'))
|
|
262
|
+
throw new ValidationError('Invalid MySQL catalog identifier.');
|
|
263
|
+
return `\`${name.replaceAll('`', '``')}\``;
|
|
264
|
+
}
|
|
265
|
+
/** Reject legacy parser defaults and original tokens before creating any pool. */
|
|
266
|
+
export function assertMysqlDoctorArguments(args, argv) {
|
|
267
|
+
const allowed = new Set(['command', 'subcommand', 'positional', 'engine', 'url', 'schema', 'json', 'help']);
|
|
268
|
+
if (Object.entries(args).some(([key, value]) => value !== undefined && !allowed.has(key)) ||
|
|
269
|
+
args.subcommand !== undefined ||
|
|
270
|
+
args.positional.length)
|
|
271
|
+
throw new ValidationError('MySQL doctor supports only --json, --engine, --url, --schema and --help; PostgreSQL repair, unused, audit, metrics and plan options are unsupported.');
|
|
272
|
+
if (!argv)
|
|
273
|
+
return;
|
|
274
|
+
for (let i = 1; i < argv.length; i++) {
|
|
275
|
+
const token = argv[i];
|
|
276
|
+
if (['--engine', '--url', '-u', '--schema', '-s'].includes(token)) {
|
|
277
|
+
const value = argv[++i];
|
|
278
|
+
if (!value || value.startsWith('-'))
|
|
279
|
+
throw new ValidationError('MySQL doctor requires explicit non-flag option operands.');
|
|
280
|
+
}
|
|
281
|
+
else if (!['--json', '--help', '-h'].includes(token))
|
|
282
|
+
throw new ValidationError('Unsupported MySQL doctor argument.');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
export function showMysqlDoctorHelp() {
|
|
286
|
+
console.log('turbine doctor --engine mysql [--json] [--url mysql://host/database] [--schema database]\nRead-only scoped native MySQL 8.x structural checks. No repairs, files, query plans, unused-index or metrics analysis. Unknown checks do not mean clean.');
|
|
287
|
+
}
|
|
288
|
+
/** Owns only the pool and snapshot opened here. The caller supplies the native transport bridge. */
|
|
289
|
+
export async function cmdMysqlDoctor(args, config, collect) {
|
|
290
|
+
assertMysqlDoctorArguments(args);
|
|
291
|
+
if (config.engine !== 'mysql' || config.adapter !== undefined)
|
|
292
|
+
throw new ValidationError('MySQL doctor requires engine mysql without a PostgreSQL adapter.');
|
|
293
|
+
const pool = createMysqlToolPool(config.url, config.schema, config);
|
|
294
|
+
try {
|
|
295
|
+
const client = await pool.connect();
|
|
296
|
+
const checkout = guardCheckout(client);
|
|
297
|
+
try {
|
|
298
|
+
const report = await collect(client, config);
|
|
299
|
+
console.log(args.json ? JSON.stringify(report, null, 2) : formatMysqlDoctor(report));
|
|
300
|
+
return report;
|
|
301
|
+
}
|
|
302
|
+
finally {
|
|
303
|
+
checkout.release();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
finally {
|
|
307
|
+
await pool.end();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
export function formatMysqlDoctor(report) {
|
|
311
|
+
return [
|
|
312
|
+
`MySQL doctor: ${report.ok ? 'scoped checks passed' : 'attention or unknown checks'}`,
|
|
313
|
+
...report.checks.map((check) => `${check.code}: ${check.status} (${check.severity}) ${JSON.stringify(check.facts)}`),
|
|
314
|
+
...report.limitations.map((limit) => `Limitation: ${limit}`),
|
|
315
|
+
].join('\n');
|
|
316
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SchemaDef } from '../schema-builder.js';
|
|
2
|
+
import { type ResolvedConfig } from './config.js';
|
|
3
|
+
import type { CliArgs } from './index.js';
|
|
4
|
+
export declare function showMysqlMigrateHelp(): void;
|
|
5
|
+
/** Check original tokens too: the shared legacy parser can swallow a safety flag as an operand. */
|
|
6
|
+
export declare function assertMysqlMigrationArguments(args: CliArgs, argv?: readonly string[]): void;
|
|
7
|
+
export declare function cmdMysqlMigrate(args: CliArgs, config: ResolvedConfig, loadSchema?: (path: string) => Promise<SchemaDef>): Promise<void>;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/** MySQL SQL-first CLI adapter. Native DDL effects are never represented as transactional. */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { MigrationError, ValidationError } from '../errors.js';
|
|
4
|
+
import { printableCatalogName as shown } from '../introspect.js';
|
|
5
|
+
import { mysqlDatabaseFromUrl } from './config.js';
|
|
6
|
+
import { createMigration, formatChecksumMismatchError, listIgnoredSqlFiles, parseMigrationContent, statusGateProblems, summarizeMigrationStatus, } from './migrate.js';
|
|
7
|
+
import { inspectMysqlMigrationDeploy, migrateMysqlDeploy, migrateMysqlDown, migrateMysqlStatus, migrateMysqlUp, planMysqlMigrationRollback, recoverMysqlMigration, } from './mysql-migrate.js';
|
|
8
|
+
import { createMysqlSchemaMigration } from './mysql-schema.js';
|
|
9
|
+
import { assertMysqlSchemaConfig } from './mysql-schema-command.js';
|
|
10
|
+
import { banner, info, label, redactUrl, success, table, warn } from './ui.js';
|
|
11
|
+
export function showMysqlMigrateHelp() {
|
|
12
|
+
info(`MySQL SQL-first migrations (optional mysql2 peer, direct MySQL 8.0.17+):
|
|
13
|
+
turbine migrate create <name> --engine mysql [--from-diff --schema-file path]
|
|
14
|
+
turbine migrate up --engine mysql [--step N] [--allow-destructive] [--allow-drift]
|
|
15
|
+
turbine migrate deploy --engine mysql [--wait[=seconds]]
|
|
16
|
+
turbine migrate down --engine mysql [--step N] [--allow-destructive] [--allow-drift]
|
|
17
|
+
turbine migrate status --engine mysql [--exit-code] (list is an alias)
|
|
18
|
+
turbine migrate recover <name> <checksum> <applied|rolled-back> --engine mysql --acknowledge-partial-ddl
|
|
19
|
+
|
|
20
|
+
Config/.env/--url select the database; default migrations: ./turbine/migrations.
|
|
21
|
+
Files use YYYYMMDDHHMMSS_name.sql with -- UP / -- DOWN sections.
|
|
22
|
+
up/down/deploy accept --dry-run: read-only inspection, not an execution guarantee.
|
|
23
|
+
Deploy permits destructive SQL without prompting, applies all pending files and always refuses drift.
|
|
24
|
+
MySQL DDL implicitly commits; failures can leave partial effects and block all ordinary writes.
|
|
25
|
+
Recovery requires manual reconciliation and exact dirty name/checksum/outcome; it never replays SQL.
|
|
26
|
+
Status --exit-code returns 2 for dirty, pending, drift, missing or ignored files; errors return 1.
|
|
27
|
+
create --from-diff compares a conservative SchemaDef subset and writes SQL for review, without applying it.
|
|
28
|
+
No --force, --auto, recipes, adapters, --allow-pending or --allow-pooler.
|
|
29
|
+
A configured schemaFile is used only by create --from-diff; ordinary SQL execution does not import it.`);
|
|
30
|
+
}
|
|
31
|
+
/** Check original tokens too: the shared legacy parser can swallow a safety flag as an operand. */
|
|
32
|
+
export function assertMysqlMigrationArguments(args, argv) {
|
|
33
|
+
const keys = new Set([
|
|
34
|
+
'command',
|
|
35
|
+
'engine',
|
|
36
|
+
'subcommand',
|
|
37
|
+
'positional',
|
|
38
|
+
'url',
|
|
39
|
+
'schema',
|
|
40
|
+
'step',
|
|
41
|
+
'dryRun',
|
|
42
|
+
'force',
|
|
43
|
+
'help',
|
|
44
|
+
'auto',
|
|
45
|
+
'fromDiff',
|
|
46
|
+
'recipe',
|
|
47
|
+
'allowDrift',
|
|
48
|
+
'allowDestructive',
|
|
49
|
+
'allowPending',
|
|
50
|
+
'allowPooler',
|
|
51
|
+
'exitCode',
|
|
52
|
+
'wait',
|
|
53
|
+
'schemaFile',
|
|
54
|
+
'acknowledgePartialDdl',
|
|
55
|
+
]);
|
|
56
|
+
for (const [key, value] of Object.entries(args)) {
|
|
57
|
+
if (value !== undefined && !keys.has(key))
|
|
58
|
+
throw new ValidationError(`Unsupported MySQL migration option: ${key}.`);
|
|
59
|
+
}
|
|
60
|
+
if (!argv)
|
|
61
|
+
return;
|
|
62
|
+
const operands = new Set(['--engine', '--url', '-u', '--schema', '-s', '--step', '-n', '--recipe', '--schema-file']);
|
|
63
|
+
const flags = new Set([
|
|
64
|
+
'--dry-run',
|
|
65
|
+
'--force',
|
|
66
|
+
'-f',
|
|
67
|
+
'--help',
|
|
68
|
+
'-h',
|
|
69
|
+
'--auto',
|
|
70
|
+
'--from-diff',
|
|
71
|
+
'--allow-drift',
|
|
72
|
+
'--allow-destructive',
|
|
73
|
+
'--allow-pending',
|
|
74
|
+
'--allow-pooler',
|
|
75
|
+
'--exit-code',
|
|
76
|
+
'--acknowledge-partial-ddl',
|
|
77
|
+
]);
|
|
78
|
+
for (let i = 1; i < argv.length; i++) {
|
|
79
|
+
const token = argv[i];
|
|
80
|
+
if (operands.has(token)) {
|
|
81
|
+
const value = argv[++i];
|
|
82
|
+
if (!value?.trim() || value.startsWith('-'))
|
|
83
|
+
throw new ValidationError(`MySQL ${token} requires an explicit non-flag operand.`);
|
|
84
|
+
}
|
|
85
|
+
else if (token === '--wait') {
|
|
86
|
+
const value = argv[i + 1];
|
|
87
|
+
if (value && /^\d+$/.test(value))
|
|
88
|
+
i++;
|
|
89
|
+
}
|
|
90
|
+
else if (token.startsWith('--wait=')) {
|
|
91
|
+
if (!/^\d+$/.test(token.slice(7)))
|
|
92
|
+
throw new ValidationError('Invalid MySQL --wait operand.');
|
|
93
|
+
}
|
|
94
|
+
else if (token.startsWith('-') && !flags.has(token)) {
|
|
95
|
+
throw new ValidationError(`Unsupported MySQL migration flag: ${shown(token)}.`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function validate(args, config, sub) {
|
|
100
|
+
assertMysqlMigrationArguments(args);
|
|
101
|
+
if (config.engine !== 'mysql' || config.adapter !== undefined)
|
|
102
|
+
throw new ValidationError('MySQL migrations require engine "mysql" and no PostgreSQL adapter.');
|
|
103
|
+
if (typeof config.migrationsDir !== 'string' || !config.migrationsDir.trim() || config.migrationsDir.includes('\0'))
|
|
104
|
+
throw new ValidationError('MySQL migrationsDir must be a nonempty path.');
|
|
105
|
+
if (args.auto ||
|
|
106
|
+
args.recipe ||
|
|
107
|
+
args.allowPending ||
|
|
108
|
+
args.allowPooler ||
|
|
109
|
+
(args.fromDiff && sub !== 'create') ||
|
|
110
|
+
(args.schemaFile !== undefined && !(sub === 'create' && args.fromDiff)))
|
|
111
|
+
throw new ValidationError('MySQL migrations require explicit SQL files; --from-diff and --schema-file only apply to create, and --auto, recipes, --allow-pending and --allow-pooler are unsupported.');
|
|
112
|
+
if (sub === 'create' && args.fromDiff)
|
|
113
|
+
assertMysqlSchemaConfig(config);
|
|
114
|
+
if (args.force)
|
|
115
|
+
throw new ValidationError('MySQL migrations refuse --force; create a new migration.');
|
|
116
|
+
if (args.exitCode && !['status', 'list'].includes(sub))
|
|
117
|
+
throw new ValidationError('--exit-code only applies to MySQL migrate status/list.');
|
|
118
|
+
if (args.step !== undefined && (!['up', 'down'].includes(sub) || !Number.isSafeInteger(args.step) || args.step < 1))
|
|
119
|
+
throw new ValidationError('--step requires a positive integer and only applies to MySQL migrate up/down.');
|
|
120
|
+
if (args.wait !== undefined &&
|
|
121
|
+
(sub !== 'deploy' || !Number.isSafeInteger(args.wait) || args.wait < 1 || args.wait * 1000 > 2147483647))
|
|
122
|
+
throw new ValidationError('--wait requires 1..2147483 seconds and only applies to MySQL migrate deploy.');
|
|
123
|
+
if (args.dryRun && !['up', 'down', 'deploy'].includes(sub))
|
|
124
|
+
throw new ValidationError('--dry-run only applies to MySQL migrate up/down/deploy.');
|
|
125
|
+
if (args.allowDrift && !['up', 'down'].includes(sub))
|
|
126
|
+
throw new ValidationError('--allow-drift only applies to MySQL migrate up/down; deploy always refuses drift.');
|
|
127
|
+
if (args.allowDestructive && !['up', 'down'].includes(sub))
|
|
128
|
+
throw new ValidationError('--allow-destructive only applies to MySQL migrate up/down; deploy supplies consent.');
|
|
129
|
+
if (args.acknowledgePartialDdl && sub !== 'recover')
|
|
130
|
+
throw new ValidationError('--acknowledge-partial-ddl only applies to MySQL migrate recover.');
|
|
131
|
+
if (sub === 'create') {
|
|
132
|
+
if (args.positional.length !== 1)
|
|
133
|
+
throw new ValidationError('Usage: turbine migrate create <name> --engine mysql');
|
|
134
|
+
}
|
|
135
|
+
else if (sub === 'recover') {
|
|
136
|
+
const [name, checksum, outcome] = args.positional;
|
|
137
|
+
if (args.positional.length !== 3 ||
|
|
138
|
+
!name ||
|
|
139
|
+
!/^[a-f0-9]{64}$/.test(checksum ?? '') ||
|
|
140
|
+
!['applied', 'rolled-back'].includes(outcome ?? '') ||
|
|
141
|
+
args.acknowledgePartialDdl !== true)
|
|
142
|
+
throw new ValidationError('Usage: turbine migrate recover <exact-name> <sha256> <applied|rolled-back> --engine mysql --acknowledge-partial-ddl. Manually reconcile schema/data first.');
|
|
143
|
+
}
|
|
144
|
+
else if (args.positional.length)
|
|
145
|
+
throw new ValidationError(`Unexpected arguments for MySQL migrate ${sub}.`);
|
|
146
|
+
if (config.url) {
|
|
147
|
+
const database = mysqlDatabaseFromUrl(config.url);
|
|
148
|
+
if (config.schema !== database)
|
|
149
|
+
throw new ValidationError('MySQL migration schema must match the URL database.');
|
|
150
|
+
}
|
|
151
|
+
else if (sub !== 'create') {
|
|
152
|
+
throw new ValidationError('MySQL migrations need --url, config.url, or DATABASE_URL selecting an existing database.');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export async function cmdMysqlMigrate(args, config, loadSchema) {
|
|
156
|
+
const sub = args.subcommand;
|
|
157
|
+
if (!sub || sub === 'help') {
|
|
158
|
+
showMysqlMigrateHelp();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (!['create', 'up', 'deploy', 'down', 'status', 'list', 'recover'].includes(sub))
|
|
162
|
+
throw new ValidationError(`Unknown MySQL migrate subcommand: ${shown(sub)}`);
|
|
163
|
+
validate(args, config, sub);
|
|
164
|
+
banner();
|
|
165
|
+
if (sub === 'create') {
|
|
166
|
+
if (args.fromDiff) {
|
|
167
|
+
if (!loadSchema)
|
|
168
|
+
throw new ValidationError('MySQL create --from-diff requires the CLI schema loader integration.');
|
|
169
|
+
const schema = await loadSchema(config.schemaFile);
|
|
170
|
+
const result = await createMysqlSchemaMigration(config.url, config.migrationsDir, args.positional[0], schema);
|
|
171
|
+
if (!result.file)
|
|
172
|
+
success('No supported schema changes; no migration file created.');
|
|
173
|
+
else {
|
|
174
|
+
success(`Created ${shown(result.file.path)}`);
|
|
175
|
+
warn('Review UP and destructive DOWN. MySQL DDL implicitly commits; every ALTER requires --allow-destructive.');
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const file = createMigration(config.migrationsDir, args.positional[0]);
|
|
180
|
+
success(`Created ${shown(file.path)}`);
|
|
181
|
+
info('Edit its UP/DOWN MySQL SQL, then run turbine migrate up --engine mysql.');
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
label('MySQL database', redactUrl(config.url));
|
|
185
|
+
label('Migrations', shown(config.migrationsDir));
|
|
186
|
+
const options = { schema: config.schema };
|
|
187
|
+
const ignored = listIgnoredSqlFiles(config.migrationsDir);
|
|
188
|
+
for (const file of ignored)
|
|
189
|
+
warn(`Not a migration (expected YYYYMMDDHHMMSS_name.sql): ${shown(file)}`);
|
|
190
|
+
if (sub === 'status' || sub === 'list') {
|
|
191
|
+
const statuses = await migrateMysqlStatus(config.url, config.migrationsDir, options);
|
|
192
|
+
console.log(table(['Status', 'Migration', 'Applied at'], statuses.map((s) => [
|
|
193
|
+
s.dirty
|
|
194
|
+
? 'Dirty'
|
|
195
|
+
: s.missingFile
|
|
196
|
+
? 'Missing file'
|
|
197
|
+
: s.checksumValid === false
|
|
198
|
+
? 'Drifted'
|
|
199
|
+
: s.applied
|
|
200
|
+
? 'Applied'
|
|
201
|
+
: 'Pending',
|
|
202
|
+
shown(s.file.filename),
|
|
203
|
+
s.appliedAt?.toISOString() ?? '-',
|
|
204
|
+
])));
|
|
205
|
+
const problems = statusGateProblems(summarizeMigrationStatus(statuses), ignored.map(shown));
|
|
206
|
+
for (const status of statuses) {
|
|
207
|
+
if (!status.dirty)
|
|
208
|
+
continue;
|
|
209
|
+
const dirty = status.dirty;
|
|
210
|
+
problems.push(`dirty: ${shown(dirty.name)}`);
|
|
211
|
+
warn(`Dirty ${shown(dirty.name)}: checksum ${dirty.checksum}, ${dirty.direction}, ${dirty.completedStatements}/${dirty.totalStatements} confirmed statement responses.`);
|
|
212
|
+
warn('Counts are lower bounds; later SQL may have effects. Autocommitted DDL is not rolled back. Reconcile manually before recover.');
|
|
213
|
+
}
|
|
214
|
+
info(`${statuses.filter((s) => s.applied).length} applied, ${statuses.filter((s) => !s.applied).length} pending`);
|
|
215
|
+
if (problems.length)
|
|
216
|
+
warn(`Migration history is not clean: ${problems.join(', ')}`);
|
|
217
|
+
if (args.exitCode && problems.length)
|
|
218
|
+
process.exitCode = 2;
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (sub === 'recover') {
|
|
222
|
+
await recoverMysqlMigration(config.url, config.migrationsDir, {
|
|
223
|
+
...options,
|
|
224
|
+
name: args.positional[0],
|
|
225
|
+
checksum: args.positional[1],
|
|
226
|
+
outcome: args.positional[2],
|
|
227
|
+
acknowledgePartialDdl: true,
|
|
228
|
+
});
|
|
229
|
+
success('Recorded manually reconciled MySQL migration outcome; no migration SQL was executed.');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (args.allowDrift)
|
|
233
|
+
warn('--allow-drift records modified checksums without replaying applied UP SQL; missing files still block.');
|
|
234
|
+
if (args.dryRun) {
|
|
235
|
+
const plan = await inspectMysqlMigrationDeploy(config.url, config.migrationsDir, options);
|
|
236
|
+
if (plan.dirty)
|
|
237
|
+
throw new MigrationError(`MySQL migration ${shown(plan.dirty.name)} is dirty; reconcile and recover before continuing. Autocommitted DDL is not rolled back.`);
|
|
238
|
+
const blocking = plan.mismatches.filter((m) => m.type === 'missing' || !args.allowDrift);
|
|
239
|
+
if (blocking.length)
|
|
240
|
+
throw new MigrationError(formatChecksumMismatchError(blocking));
|
|
241
|
+
const files = sub === 'down'
|
|
242
|
+
? await planMysqlMigrationRollback(config.url, config.migrationsDir, { ...options, step: args.step })
|
|
243
|
+
: sub === 'up'
|
|
244
|
+
? plan.pending.slice(0, args.step)
|
|
245
|
+
: plan.pending;
|
|
246
|
+
for (const file of files) {
|
|
247
|
+
label('Migration', shown(file.filename));
|
|
248
|
+
console.log(parseMigrationContent(readFileSync(file.path, 'utf8'), file.path)[sub === 'down' ? 'down' : 'up']);
|
|
249
|
+
}
|
|
250
|
+
for (const order of plan.outOfOrder)
|
|
251
|
+
warn(`Out of order: ${shown(order.applied)} predates ${shown(order.newestPrior)}.`);
|
|
252
|
+
info(`Dry run: ${files.length} migration(s); no database or history changes made.`);
|
|
253
|
+
warn('SQL is displayed, not executed or certified. Native SQL mode/policy, executable SQL, authorization, destructive consent and concurrent state are checked again at execution; this inspection does not guarantee success.');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
warn('MySQL DDL implicitly commits. Partial effects may remain on failure; no transactional rollback is promised.');
|
|
257
|
+
if (sub === 'deploy')
|
|
258
|
+
warn('Deploy permits destructive MySQL SQL without prompting.');
|
|
259
|
+
const writeOptions = {
|
|
260
|
+
...options,
|
|
261
|
+
step: args.step,
|
|
262
|
+
allowDrift: args.allowDrift,
|
|
263
|
+
allowDestructive: args.allowDestructive,
|
|
264
|
+
};
|
|
265
|
+
const result = sub === 'down'
|
|
266
|
+
? await migrateMysqlDown(config.url, config.migrationsDir, writeOptions)
|
|
267
|
+
: sub === 'deploy'
|
|
268
|
+
? await migrateMysqlDeploy(config.url, config.migrationsDir, {
|
|
269
|
+
...options,
|
|
270
|
+
lockWaitMs: args.wait === undefined ? undefined : args.wait * 1000,
|
|
271
|
+
onLockWait: () => warn(`Another runner holds the MySQL migration lock; waiting up to ${args.wait}s.`),
|
|
272
|
+
})
|
|
273
|
+
: await migrateMysqlUp(config.url, config.migrationsDir, writeOptions);
|
|
274
|
+
const files = 'applied' in result ? result.applied : result.rolledBack;
|
|
275
|
+
for (const file of files)
|
|
276
|
+
info(`${sub === 'down' ? 'DOWN completed' : 'Applied'}: ${shown(file.filename)}`);
|
|
277
|
+
for (const baseline of result.rebaselined)
|
|
278
|
+
warn(`Re-baselined ${shown(baseline.name)}: ${baseline.from} -> ${baseline.to}`);
|
|
279
|
+
if ('outOfOrder' in result)
|
|
280
|
+
for (const order of result.outOfOrder)
|
|
281
|
+
warn(`Applied ${shown(order.applied)} out of order, before ${shown(order.newestPrior)}.`);
|
|
282
|
+
if (result.errors.length)
|
|
283
|
+
throw new MigrationError(result.errors.map((e) => `${shown(e.file.filename)}: ${e.error}`).join('\n'));
|
|
284
|
+
success(`${files.length} migration(s) ${sub === 'down' ? 'DOWN completed' : 'applied'}`);
|
|
285
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DestructiveStatement } from './destructive.js';
|
|
2
|
+
export interface MysqlMigrationSqlMode {
|
|
3
|
+
noBackslashEscapes: boolean;
|
|
4
|
+
ansiQuotes: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface MysqlMigrationStatement {
|
|
7
|
+
/** Original SQL, including literal spelling. */
|
|
8
|
+
sql: string;
|
|
9
|
+
/** Comments removed, literals masked, identifiers in scanner-compatible quotes. */
|
|
10
|
+
normalized: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Split MySQL SQL without applying PostgreSQL dollar-quote or comment rules.
|
|
14
|
+
* Mode comes from the dedicated connection; this function never changes it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseMysqlMigrationStatements(sql: string, mode: MysqlMigrationSqlMode): MysqlMigrationStatement[];
|
|
17
|
+
/** Apply the shared destructive policy with MySQL-specific rewrite detection. */
|
|
18
|
+
export declare function scanMysqlMigrationDestructive(statements: readonly MysqlMigrationStatement[]): DestructiveStatement[];
|