@deterministic-code/migraters 0.0.0-stage → 0.0.2

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.
Files changed (116) hide show
  1. package/README.md +1 -3
  2. package/bundle.yaml +262 -0
  3. package/cli.yaml +264 -0
  4. package/dist/abstractions/migrater.d.ts +28 -0
  5. package/dist/abstractions/migrater.js +1 -0
  6. package/dist/abstractions/sql-dialect-base.d.ts +16 -0
  7. package/dist/abstractions/sql-dialect-base.js +19 -0
  8. package/dist/abstractions/sql-dialect-factory.d.ts +8 -0
  9. package/dist/abstractions/sql-dialect-factory.js +22 -0
  10. package/dist/abstractions/sql-dialect.d.ts +16 -0
  11. package/dist/abstractions/sql-dialect.js +1 -0
  12. package/dist/bin/migrate-create.d.ts +2 -0
  13. package/dist/bin/migrate-create.js +71 -0
  14. package/dist/bin/migrate-down.d.ts +2 -0
  15. package/dist/bin/migrate-down.js +135 -0
  16. package/dist/bin/migrate-init.d.ts +2 -0
  17. package/dist/bin/migrate-init.js +77 -0
  18. package/dist/bin/migrate-setup.d.ts +2 -0
  19. package/dist/bin/migrate-setup.js +87 -0
  20. package/dist/bin/migrate-up.d.ts +2 -0
  21. package/dist/bin/migrate-up.js +97 -0
  22. package/dist/cli-contract.d.ts +6 -0
  23. package/dist/cli-contract.js +19 -0
  24. package/dist/cli-spec.d.ts +24 -0
  25. package/dist/cli-spec.js +33 -0
  26. package/dist/cli.d.ts +9 -0
  27. package/dist/cli.js +41 -0
  28. package/dist/create-sequence.d.ts +4 -0
  29. package/dist/create-sequence.js +16 -0
  30. package/dist/datasource-migrate.d.ts +31 -0
  31. package/dist/datasource-migrate.js +206 -0
  32. package/dist/dialects/mysql-dialect.d.ts +12 -0
  33. package/dist/dialects/mysql-dialect.js +56 -0
  34. package/dist/dialects/oracle-dialect.d.ts +18 -0
  35. package/dist/dialects/oracle-dialect.js +76 -0
  36. package/dist/dialects/postgres-dialect.d.ts +11 -0
  37. package/dist/dialects/postgres-dialect.js +58 -0
  38. package/dist/dialects/sqlite-dialect.d.ts +13 -0
  39. package/dist/dialects/sqlite-dialect.js +96 -0
  40. package/dist/dialects/sqlserver-dialect.d.ts +12 -0
  41. package/dist/dialects/sqlserver-dialect.js +73 -0
  42. package/dist/help.d.ts +2 -0
  43. package/dist/help.js +10 -0
  44. package/dist/index.d.ts +7 -0
  45. package/dist/index.js +6 -0
  46. package/dist/infrastructure/connection-resolver.d.ts +7 -0
  47. package/dist/infrastructure/connection-resolver.js +19 -0
  48. package/dist/infrastructure/default-factory.d.ts +4 -0
  49. package/dist/infrastructure/default-factory.js +15 -0
  50. package/dist/infrastructure/interop-default.d.ts +3 -0
  51. package/dist/infrastructure/interop-default.js +1 -0
  52. package/dist/infrastructure/message-templates.d.ts +3 -0
  53. package/dist/infrastructure/message-templates.js +18 -0
  54. package/dist/infrastructure/split-on-go.d.ts +2 -0
  55. package/dist/infrastructure/split-on-go.js +20 -0
  56. package/dist/infrastructure/sql-templates.d.ts +2 -0
  57. package/dist/infrastructure/sql-templates.js +4 -0
  58. package/dist/infrastructure/templates-root.d.ts +2 -0
  59. package/dist/infrastructure/templates-root.js +11 -0
  60. package/dist/init-select.d.ts +12 -0
  61. package/dist/init-select.js +52 -0
  62. package/dist/migrater.d.ts +12 -0
  63. package/dist/migrater.js +84 -0
  64. package/dist/migration-client.d.ts +21 -0
  65. package/dist/migration-client.js +1 -0
  66. package/dist/path-exists.d.ts +1 -0
  67. package/dist/path-exists.js +10 -0
  68. package/dist/sql.d.ts +3 -0
  69. package/dist/sql.js +15 -0
  70. package/dist/templates/help/create.txt +16 -0
  71. package/dist/templates/help/down.txt +42 -0
  72. package/dist/templates/help/init.txt +13 -0
  73. package/dist/templates/help/setup.txt +41 -0
  74. package/dist/templates/help/up.txt +43 -0
  75. package/dist/templates/messages/checksum-drift-line.txt +1 -0
  76. package/dist/templates/messages/checksum-drift.txt +11 -0
  77. package/dist/templates/messages/down/confirm-mismatch.txt +1 -0
  78. package/dist/templates/messages/down/confirm-prompt.txt +1 -0
  79. package/dist/templates/messages/down/confirm-stdin-failed.txt +1 -0
  80. package/dist/templates/messages/down/confirm-token-mismatch.txt +1 -0
  81. package/dist/templates/messages/down/confirm-tty-required.txt +1 -0
  82. package/dist/templates/messages/down/destructive-header.txt +3 -0
  83. package/dist/templates/messages/errors/invalid-name.txt +1 -0
  84. package/dist/templates/messages/errors/migrate-path-not-dir.txt +1 -0
  85. package/dist/templates/messages/errors/missing-connection.txt +1 -0
  86. package/dist/templates/messages/errors/missing-name-hint.txt +1 -0
  87. package/dist/templates/messages/errors/missing-name.txt +1 -0
  88. package/dist/templates/messages/errors/missing-provider-hint.txt +1 -0
  89. package/dist/templates/messages/errors/missing-provider.txt +1 -0
  90. package/dist/templates/messages/errors/missing-value-for-flag.txt +1 -0
  91. package/dist/templates/messages/errors/rollback-no-down-sibling.txt +1 -0
  92. package/dist/templates/messages/errors/rollback-no-rollback-sibling.txt +1 -0
  93. package/dist/templates/messages/errors/rollback-not-in-path.txt +1 -0
  94. package/dist/templates/messages/errors/sqlite-prerequisite.txt +1 -0
  95. package/dist/templates/messages/errors/unknown-arg.txt +1 -0
  96. package/dist/templates/messages/errors/unsupported-provider.txt +1 -0
  97. package/dist/templates/messages/setup-complete.txt +9 -0
  98. package/dist/templates/messages/status/applied.txt +1 -0
  99. package/dist/templates/messages/status/created.txt +1 -0
  100. package/dist/templates/messages/status/no-more-pending.txt +1 -0
  101. package/dist/templates/messages/status/no-pending.txt +1 -0
  102. package/dist/templates/messages/status/no-rollback.txt +1 -0
  103. package/dist/templates/messages/status/rolled-back.txt +1 -0
  104. package/dist/templates/scaffold/down.sql +1 -0
  105. package/dist/templates/scaffold/up.sql +1 -0
  106. package/dist/templates/sql/mysql/migrate_logs.sql +11 -0
  107. package/dist/templates/sql/mysql/migrates.sql +7 -0
  108. package/dist/templates/sql/oracle/migrate_logs.sql +14 -0
  109. package/dist/templates/sql/oracle/migrates.sql +10 -0
  110. package/dist/templates/sql/postgres/migrate_logs.sql +11 -0
  111. package/dist/templates/sql/postgres/migrates.sql +7 -0
  112. package/dist/templates/sql/sqlite/migrate_logs.sql +11 -0
  113. package/dist/templates/sql/sqlite/migrates.sql +7 -0
  114. package/dist/templates/sql/sqlserver/migrate_logs.sql +12 -0
  115. package/dist/templates/sql/sqlserver/migrates.sql +8 -0
  116. package/package.json +79 -4
package/README.md CHANGED
@@ -1,3 +1 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ Migrate executables for deterministic-code.
package/bundle.yaml ADDED
@@ -0,0 +1,262 @@
1
+ # Source of truth for vendoring migrate runners into generated apps.
2
+ # generators-migraters `fetch-bundle` copies these files; `generate` emits
3
+ # Bundled content or Reference install instructions from the same manifest.
4
+
5
+ repository: https://github.com/deterministic-code/migraters
6
+ ref: main
7
+
8
+ languages:
9
+ typescript:
10
+ root: migraters
11
+ common:
12
+ - cli.yaml
13
+ - typescript/cli.yaml
14
+ - typescript/package.json
15
+ - typescript/tsconfig.build.json
16
+ - typescript/src/**/*.ts
17
+ - shared/templates/help/**
18
+ - shared/templates/messages/**
19
+ - shared/templates/scaffold/**
20
+ exclude:
21
+ - typescript/src/**/*.test.ts
22
+ - typescript/src/generate-help.ts
23
+ dialects:
24
+ sqlite:
25
+ files:
26
+ - typescript/src/dialects/sqlite-dialect.ts
27
+ - shared/templates/sql/sqlite/**
28
+ apk: sqlite
29
+ packages:
30
+ - name: better-sqlite3
31
+ version: "^13.0.3"
32
+ installScripts: true
33
+ postgres:
34
+ files:
35
+ - typescript/src/dialects/postgres-dialect.ts
36
+ - shared/templates/sql/postgres/**
37
+ apk: postgresql-client
38
+ packages:
39
+ - name: pg
40
+ version: "^8.13.0"
41
+ mysql:
42
+ files:
43
+ - typescript/src/dialects/mysql-dialect.ts
44
+ - shared/templates/sql/mysql/**
45
+ apk: mysql-client
46
+ packages:
47
+ - name: mysql2
48
+ version: "^3.22.2"
49
+ sqlserver:
50
+ files:
51
+ - typescript/src/dialects/sqlserver-dialect.ts
52
+ - shared/templates/sql/sqlserver/**
53
+ packages:
54
+ - name: mssql
55
+ version: "^12.5.0"
56
+ oracle:
57
+ files:
58
+ - typescript/src/dialects/oracle-dialect.ts
59
+ - shared/templates/sql/oracle/**
60
+ packages:
61
+ - name: oracledb
62
+ version: "^6.10.0"
63
+ commands:
64
+ setup: migrate-setup --provider {{provider}}
65
+ up: migrate-up --provider {{provider}} --migrate-path {{migrationsPath}}
66
+ down: migrate-down --provider {{provider}} --migrate-path {{migrationsPath}}
67
+ create: migrate-create --provider {{provider}}
68
+ build:
69
+ cwd: typescript
70
+ steps:
71
+ - npm install
72
+ - npm run build
73
+ invoke:
74
+ setup:
75
+ reference: migrate-setup --provider "$DIALECT" --connection "$CONN"
76
+ bundled: npm --prefix /app/migraters/typescript exec -- migrate-setup --provider "$DIALECT" --connection "$CONN"
77
+ up:
78
+ reference: migrate-up --provider "$DIALECT" --migrate-path "$MIGRATIONS_DIR" --connection "$CONN"
79
+ bundled: npm --prefix /app/migraters/typescript exec -- migrate-up --provider "$DIALECT" --migrate-path "$MIGRATIONS_DIR" --connection "$CONN"
80
+ reference:
81
+ package: "@deterministic-code/migraters"
82
+ spec: "github:deterministic-code/migraters"
83
+ docker:
84
+ copy:
85
+ reference: |
86
+ COPY {{shared}}sql {{containerSqlRoot}}
87
+ bundled: |
88
+ COPY {{shared}}sql {{containerSqlRoot}}
89
+ COPY {{lane}}migraters ./migraters
90
+ runtime_copy:
91
+ reference: |
92
+ COPY {{shared}}sql {{containerSqlRoot}}
93
+ bundled: |
94
+ COPY {{shared}}sql {{containerSqlRoot}}
95
+ COPY {{lane}}migraters ./migraters
96
+
97
+ rust:
98
+ root: migraters
99
+ common:
100
+ - rust/Cargo.toml
101
+ - rust/rustfmt.toml
102
+ - rust/src/**/*.rs
103
+ - rust/init/**
104
+ - shared/templates/help/**
105
+ - shared/templates/messages/**
106
+ - shared/templates/scaffold/**
107
+ - cli.yaml
108
+ dialects:
109
+ sqlite:
110
+ files:
111
+ - rust/src/dialects/sqlite.rs
112
+ - shared/templates/sql/sqlite/**
113
+ apk: sqlite
114
+ feature: sqlite
115
+ postgres:
116
+ files:
117
+ - rust/src/dialects/postgres.rs
118
+ - shared/templates/sql/postgres/**
119
+ apk: postgresql-client
120
+ feature: postgres
121
+ mysql:
122
+ files:
123
+ - rust/src/dialects/mysql.rs
124
+ - shared/templates/sql/mysql/**
125
+ apk: mysql-client
126
+ feature: mysql
127
+ sqlserver:
128
+ files:
129
+ - rust/src/dialects/sqlserver.rs
130
+ - shared/templates/sql/sqlserver/**
131
+ feature: sqlserver
132
+ oracle:
133
+ files:
134
+ - rust/src/dialects/oracle.rs
135
+ - shared/templates/sql/oracle/**
136
+ feature: oracle
137
+ commands:
138
+ setup: migrate-setup --provider {{provider}}
139
+ up: migrate-up --provider {{provider}} --migrate-path {{migrationsPath}}
140
+ down: migrate-down --provider {{provider}} --migrate-path {{migrationsPath}}
141
+ create: migrate-create --provider {{provider}}
142
+ build:
143
+ cwd: rust
144
+ steps:
145
+ - cargo build --release
146
+ invoke:
147
+ setup:
148
+ reference: migrate-setup --provider "$DIALECT" --connection "$CONN"
149
+ bundled: /app/migraters/rust/target/release/migrate-setup --provider "$DIALECT" --connection "$CONN"
150
+ up:
151
+ reference: migrate-up --provider "$DIALECT" --migrate-path "$MIGRATIONS_DIR" --connection "$CONN"
152
+ bundled: /app/migraters/rust/target/release/migrate-up --provider "$DIALECT" --migrate-path "$MIGRATIONS_DIR" --connection "$CONN"
153
+ reference:
154
+ git: "https://github.com/deterministic-code/migraters"
155
+ path: rust
156
+ docker:
157
+ copy:
158
+ reference: |
159
+ COPY {{shared}}sql ./sql
160
+ bundled: |
161
+ COPY {{shared}}sql ./sql
162
+ COPY {{lane}}migraters ./migraters
163
+ RUN cargo build --release --manifest-path migraters/rust/Cargo.toml
164
+ runtime_copy:
165
+ reference: |
166
+ COPY {{shared}}sql {{containerSqlRoot}}
167
+ bundled: |
168
+ COPY --from=builder /app/migraters/rust/target/release/migrate-setup /app/migraters/rust/target/release/migrate-setup
169
+ COPY --from=builder /app/migraters/rust/target/release/migrate-up /app/migraters/rust/target/release/migrate-up
170
+ COPY --from=builder /app/migraters/rust/target/release/migrate-down /app/migraters/rust/target/release/migrate-down
171
+ COPY --from=builder /app/migraters/rust/target/release/migrate-create /app/migraters/rust/target/release/migrate-create
172
+ COPY {{shared}}sql {{containerSqlRoot}}
173
+
174
+ csharp:
175
+ root: migraters
176
+ common:
177
+ - csharp/**/*.cs
178
+ - csharp/MigrateRunner.csproj
179
+ - csharp/MigrateInit/MigrateInit.csproj
180
+ - csharp/GlobalUsings.cs
181
+ - csharp/.csharpierrc.json
182
+ - csharp/.csharpierignore
183
+ - csharp/dotnet-tools.json
184
+ - cli.yaml
185
+ - shared/templates/help/**
186
+ - shared/templates/messages/**
187
+ - shared/templates/scaffold/**
188
+ exclude:
189
+ - csharp/bin/**
190
+ - csharp/obj/**
191
+ dialects:
192
+ sqlite:
193
+ files:
194
+ - csharp/Dialects/SqliteDialect.cs
195
+ - shared/templates/sql/sqlite/**
196
+ apk: sqlite
197
+ packages:
198
+ - name: Microsoft.Data.Sqlite
199
+ version: "9.0.0"
200
+ postgres:
201
+ files:
202
+ - csharp/Dialects/PostgresDialect.cs
203
+ - shared/templates/sql/postgres/**
204
+ apk: postgresql-client
205
+ packages:
206
+ - name: Npgsql
207
+ version: "9.0.1"
208
+ mysql:
209
+ files:
210
+ - csharp/Dialects/MysqlDialect.cs
211
+ - shared/templates/sql/mysql/**
212
+ apk: mysql-client
213
+ packages:
214
+ - name: MySqlConnector
215
+ version: "2.4.0"
216
+ sqlserver:
217
+ files:
218
+ - csharp/Dialects/SqlServerDialect.cs
219
+ - shared/templates/sql/sqlserver/**
220
+ packages:
221
+ - name: Microsoft.Data.SqlClient
222
+ version: "6.0.1"
223
+ oracle:
224
+ files:
225
+ - csharp/Dialects/OracleDialect.cs
226
+ - shared/templates/sql/oracle/**
227
+ packages:
228
+ - name: Oracle.ManagedDataAccess.Core
229
+ version: "23.7.0"
230
+ commands:
231
+ setup: migrate-setup --provider {{provider}}
232
+ up: migrate-up --provider {{provider}} --migrate-path {{migrationsPath}}
233
+ down: migrate-down --provider {{provider}} --migrate-path {{migrationsPath}}
234
+ create: migrate-create --provider {{provider}}
235
+ build:
236
+ cwd: csharp
237
+ steps:
238
+ - dotnet publish MigrateRunner.csproj -c Release
239
+ invoke:
240
+ setup:
241
+ reference: migrate-setup --provider "$DIALECT" --connection "$CONN"
242
+ bundled: dotnet /app/MigrateRunner/MigrateRunner.dll setup --provider "$DIALECT" --connection "$CONN"
243
+ up:
244
+ reference: migrate-up --provider "$DIALECT" --migrate-path "$MIGRATIONS_DIR" --connection "$CONN"
245
+ bundled: dotnet /app/MigrateRunner/MigrateRunner.dll up --provider "$DIALECT" --migrate-path "$MIGRATIONS_DIR" --connection "$CONN"
246
+ reference:
247
+ git: "https://github.com/deterministic-code/migraters"
248
+ path: csharp
249
+ docker:
250
+ copy:
251
+ reference: |
252
+ COPY {{shared}}sql ./sql
253
+ bundled: |
254
+ COPY {{shared}}sql ./sql
255
+ COPY {{lane}}migraters ./migraters
256
+ RUN dotnet publish migraters/csharp/MigrateRunner.csproj -c Release -o /app/migrate-publish
257
+ runtime_copy:
258
+ reference: |
259
+ COPY {{shared}}sql {{containerSqlRoot}}
260
+ bundled: |
261
+ COPY --from=build /app/migrate-publish ./MigrateRunner
262
+ COPY {{shared}}sql {{containerSqlRoot}}
package/cli.yaml ADDED
@@ -0,0 +1,264 @@
1
+ # Source of truth for migrate command names, argv layout, and --help copy.
2
+ # TypeScript, Rust, and C# parsers must match this file.
3
+ # IMigrater (setup, up, down, create) lives in api.yaml. SQL spelling is a provider detail.
4
+ # Help templates in shared/templates/help are generated:
5
+ # npm run generate:help
6
+ # Usage line for each verb: `Usage: migrate-<verb> ` + args in order.
7
+
8
+ command: migrate-{verb}
9
+
10
+ providers:
11
+ - sqlite
12
+ - postgres
13
+ - mysql
14
+ - sqlserver
15
+ - oracle
16
+
17
+ # Lookup: lowercase, strip spaces/underscores/hyphens, then match a provider or alias.
18
+ provider_aliases:
19
+ sqlite3: sqlite
20
+ mariadb: mysql
21
+ postgresql: postgres
22
+ pg: postgres
23
+ mssql: sqlserver
24
+ mssqlserver: sqlserver
25
+ ora: oracle
26
+
27
+ exit_codes:
28
+ success: 0
29
+ usage: 2
30
+ runtime: 1
31
+
32
+ help:
33
+ - -h
34
+ - --help
35
+
36
+ help_stream: stderr
37
+
38
+ # Canonical argv is `--flag value`. `--flag=value` is optional extra syntax.
39
+ aliases:
40
+ --migrate-path: --migrations-path
41
+ --migrate-root: --migrations-root
42
+
43
+ env_var_list_separator: " / "
44
+
45
+ migrations:
46
+ path_flag: --migrations-path
47
+ root_flag: --migrations-root
48
+ root_default: sql
49
+ layout: "<root>/<provider>/migrations"
50
+ discovery: top_level_up_down_pairs
51
+ missing_directory: errors/migrate-path-not-dir
52
+
53
+ create:
54
+ name_pattern: "^[a-z][a-z0-9_]*$"
55
+ sequence_digits: 4
56
+
57
+ checksum:
58
+ algorithm: sha256
59
+ drift_bypass: MIGRATE_ALLOW_CHECKSUM_DRIFT
60
+
61
+ # Documented when a command sets show_connection_env: true.
62
+ connection_environment:
63
+ sqlite: [SQLITE_PATH, DB_PATH]
64
+ postgres: [PG_CONNECTION_STRING, DATABASE_URL]
65
+ mysql: [MYSQL_URL, DATABASE_URL]
66
+ sqlserver: [MSSQL_URL, DATABASE_URL]
67
+ oracle: [ORACLE_CONNECT_STRING, DATABASE_URL]
68
+
69
+ commands:
70
+ - verb: init
71
+ summary: |
72
+ Selects the dialects this tree will compile and install. Repeat --dialect
73
+ once per provider. Re-running replaces the previous set. --all restores
74
+ every dialect. Does not take --connection.
75
+ examples: |
76
+ {{command}} --dialect sqlite --dialect postgres
77
+ {{command}} --dialect oracle
78
+ {{command}} --all
79
+ args:
80
+ - flag: --dialect
81
+ placeholder: providers
82
+ required: false
83
+ help: "Dialect to enable. Repeat for each dialect. Aliases from this file apply."
84
+ - flag: --all
85
+ required: false
86
+ help: "Enable every dialect. Restores the committed full-provider set."
87
+
88
+ - verb: setup
89
+ show_connection_env: true
90
+ summary: |
91
+ Creates the bookkeeping tables (migrates, migrate_logs) for the chosen dialect
92
+ and the migrations directory (mkdir -p). Idempotent — re-running against an
93
+ already-setup database is a no-op. For sqlite, also mkdir -p of the parent
94
+ directory of --connection so a fresh-tree path like ./.test/foo.sqlite works.
95
+ examples: |
96
+ # sqlite — bare path or sqlite:// URL; both create a file on disk.
97
+ {{command}} --provider sqlite --connection ./app.sqlite
98
+ {{command}} --provider sqlite --connection sqlite:///absolute/path/app.sqlite
99
+
100
+ # postgres — URL or keyword form.
101
+ {{command}} --provider postgres --connection postgresql://user:pass@host:5432/dbname
102
+
103
+ # mysql — URL form.
104
+ {{command}} --provider mysql --connection mysql://user:pass@host:3306/dbname
105
+
106
+ # sqlserver / oracle — pass a driver-native connection string.
107
+ {{command}} --provider sqlserver --connection "Server=host;Database=dbname;User Id=user;Password=pass;"
108
+ {{command}} --provider oracle --connection "user/pass@host:1521/service"
109
+
110
+ # env-var fallback when --connection is omitted:
111
+ SQLITE_PATH=./app.sqlite {{command}} --provider sqlite
112
+ DATABASE_URL=postgresql://... {{command}} --provider postgres
113
+ DATABASE_URL=mysql://... {{command}} --provider mysql
114
+
115
+ # explicit in-memory sqlite:
116
+ {{command}} --provider sqlite --connection :memory:
117
+ args:
118
+ - flag: --provider
119
+ placeholder: providers
120
+ required: true
121
+ help: "Database dialect. Required."
122
+ - flag: --connection
123
+ placeholder: url
124
+ required: true
125
+ help: "Connection string. Required (or set the per-dialect env var below)."
126
+ - flag: --migrations-path
127
+ placeholder: dir
128
+ required: false
129
+ help: "Migrations directory (default: ./sql/<dialect>/migrations)."
130
+ - flag: --and-up
131
+ required: false
132
+ help: "After setup, immediately invoke migrate-up so the chain is applied in one step."
133
+
134
+ - verb: up
135
+ show_connection_env: true
136
+ summary: |
137
+ Applies ALL pending migrations in sequence, each in its own transaction.
138
+ examples: |
139
+ # sqlite — bare path or sqlite:// URL; both create a file on disk.
140
+ {{command}} --provider sqlite --connection ./app.sqlite
141
+ {{command}} --provider sqlite --connection sqlite:///absolute/path/app.sqlite
142
+
143
+ # postgres — URL or keyword form.
144
+ {{command}} --provider postgres --connection postgresql://user:pass@host:5432/dbname
145
+
146
+ # mysql — URL form.
147
+ {{command}} --provider mysql --connection mysql://user:pass@host:3306/dbname
148
+
149
+ # sqlserver / oracle — pass a driver-native connection string.
150
+ {{command}} --provider sqlserver --connection "Server=host;Database=dbname;User Id=user;Password=pass;"
151
+ {{command}} --provider oracle --connection "user/pass@host:1521/service"
152
+
153
+ # env-var fallback when --connection is omitted:
154
+ SQLITE_PATH=./app.sqlite {{command}} --provider sqlite
155
+ DATABASE_URL=postgresql://... {{command}} --provider postgres
156
+
157
+ # custom migrations layout (default looks under sql/<dialect>/migrations):
158
+ {{command}} --provider sqlite --connection ./app.sqlite --migrations-path ./db/changes/sqlite
159
+ {{command}} --provider sqlite --connection ./app.sqlite --migrations-root ./db/changes
160
+
161
+ # one-shot: apply the next pending migration only, then exit.
162
+ {{command}} --provider sqlite --connection ./app.sqlite --one
163
+ args:
164
+ - flag: --provider
165
+ placeholder: providers
166
+ required: true
167
+ help: "Database dialect. Required."
168
+ - flag: --connection
169
+ placeholder: url
170
+ required: true
171
+ help: "Connection string. Required (or set the per-dialect env var below)."
172
+ - flag: --migrations-path
173
+ placeholder: dir
174
+ required: false
175
+ help: "Full path to the migrations directory (e.g. sql/sqlite/migrations)."
176
+ - flag: --migrations-root
177
+ placeholder: dir
178
+ required: false
179
+ help: |
180
+ Root prefix; the script then looks at <migrations-root>/<dialect>/migrations.
181
+ Defaults to 'sql'. Ignored when --migrations-path is also set.
182
+ - flag: --one
183
+ required: false
184
+ help: "Apply only the next pending migration, then exit. Default is to apply all pending migrations."
185
+
186
+ - verb: down
187
+ show_connection_env: true
188
+ summary: |
189
+ Rolls back the MOST RECENTLY applied migration (one step). DESTRUCTIVE: prints a
190
+ random 4-letter uppercase token on stderr and refuses to proceed unless the
191
+ operator types it back on stdin (or passes --confirm <TOKEN> matching it).
192
+ examples: |
193
+ # sqlite — bare path or sqlite:// URL.
194
+ {{command}} --provider sqlite --connection ./app.sqlite
195
+ {{command}} --provider sqlite --connection sqlite:///absolute/path/app.sqlite
196
+
197
+ # postgres — URL or keyword form.
198
+ {{command}} --provider postgres --connection postgresql://user:pass@host:5432/dbname
199
+
200
+ # mysql — URL form.
201
+ {{command}} --provider mysql --connection mysql://user:pass@host:3306/dbname
202
+
203
+ # sqlserver / oracle — pass a driver-native connection string.
204
+ {{command}} --provider sqlserver --connection "Server=host;Database=dbname;User Id=user;Password=pass;"
205
+ {{command}} --provider oracle --connection "user/pass@host:1521/service"
206
+
207
+ # env-var fallback when --connection is omitted:
208
+ SQLITE_PATH=./app.sqlite {{command}} --provider sqlite
209
+ DATABASE_URL=postgresql://... {{command}} --provider postgres
210
+
211
+ # custom migrations layout (default looks under sql/<dialect>/migrations):
212
+ {{command}} --provider sqlite --connection ./app.sqlite --migrations-path ./db/changes/sqlite
213
+ args:
214
+ - flag: --provider
215
+ placeholder: providers
216
+ required: true
217
+ help: "Database dialect. Required."
218
+ - flag: --connection
219
+ placeholder: url
220
+ required: true
221
+ help: "Connection string. Required (or set the per-dialect env var below)."
222
+ - flag: --migrations-path
223
+ placeholder: dir
224
+ required: false
225
+ help: "Full path to the migrations directory."
226
+ - flag: --migrations-root
227
+ placeholder: dir
228
+ required: false
229
+ help: |
230
+ Root prefix; the script then looks at <migrations-root>/<dialect>/migrations.
231
+ Defaults to 'sql'. Ignored when --migrations-path is also set.
232
+ - flag: --confirm
233
+ placeholder: TOKEN
234
+ required: false
235
+ help: |
236
+ Skip the interactive prompt. The TOKEN must match the value
237
+ printed on stderr at runtime — there is no fixed bypass value.
238
+
239
+ - verb: create
240
+ summary: |
241
+ Creates a new <NNNN>_<name>_up.sql + <NNNN>_<name>_down.sql pair scaffolded
242
+ with TODO placeholders. NNNN is one greater than the highest 1-4-digit
243
+ sequence prefix already present in the migrations directory (starts at 0001).
244
+ Legacy timestamp-prefixed filenames are ignored for numbering.
245
+ examples: |
246
+ {{command}} --provider sqlite --name add_users
247
+ {{command}} --provider postgres --name backfill_email_lower --migrations-path ./db/changes/postgres
248
+ args:
249
+ - flag: --provider
250
+ placeholder: providers
251
+ required: true
252
+ help: "Database dialect. Required."
253
+ - flag: --name
254
+ placeholder: snake_case_slug
255
+ required: true
256
+ help: |
257
+ snake_case slug for the new migration. Required. Must
258
+ match /^[a-z][a-z0-9_]*$/.
259
+ - flag: --migrations-path
260
+ placeholder: dir
261
+ required: false
262
+ help: |
263
+ Migrations directory (default: ./sql/<dialect>/migrations).
264
+ Created with mkdir -p if it does not exist.
@@ -0,0 +1,28 @@
1
+ export type SetupArg = {
2
+ connection: string;
3
+ migrationsPath: string;
4
+ };
5
+ export type UpArg = {
6
+ connection: string;
7
+ migrationsPath: string;
8
+ one?: boolean;
9
+ };
10
+ export type DownArg = {
11
+ connection: string;
12
+ migrationsPath: string;
13
+ };
14
+ export type CreateArg = {
15
+ name: string;
16
+ migrationsPath: string;
17
+ };
18
+ export type CreateResponse = {
19
+ upName: string;
20
+ downName: string;
21
+ };
22
+ export interface IMigrater {
23
+ readonly name: string;
24
+ setup(args: SetupArg): Promise<void>;
25
+ up(args: UpArg): Promise<string[]>;
26
+ down(args: DownArg): Promise<string | null>;
27
+ create(args: CreateArg): Promise<CreateResponse>;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { SqlDialect } from '../sql.ts';
2
+ import type { ISqlDialect } from './sql-dialect.ts';
3
+ export declare abstract class SqlDialectBase implements ISqlDialect {
4
+ abstract readonly name: SqlDialect;
5
+ abstract readonly connectionEnvironmentVariables: readonly string[];
6
+ abstract readonly migratesDdl: string;
7
+ abstract readonly migrateLogsDdl: string;
8
+ readonly usesLastInsertRowid: boolean;
9
+ quoteIdent(ident: string): string;
10
+ nowExpr(): string;
11
+ limitClause(n: number): string;
12
+ translatePlaceholders(sql: string): string;
13
+ prerequisiteError(_connection: string): Promise<string | null>;
14
+ prepareSetup(_connection: string): Promise<void>;
15
+ abstract createClient(connection: string): Promise<import('../migration-client.ts').MigrationClient>;
16
+ }
@@ -0,0 +1,19 @@
1
+ export class SqlDialectBase {
2
+ usesLastInsertRowid = false;
3
+ quoteIdent(ident) {
4
+ return `"${ident}"`;
5
+ }
6
+ nowExpr() {
7
+ return 'CURRENT_TIMESTAMP';
8
+ }
9
+ limitClause(n) {
10
+ return `LIMIT ${n}`;
11
+ }
12
+ translatePlaceholders(sql) {
13
+ return sql;
14
+ }
15
+ async prerequisiteError(_connection) {
16
+ return null;
17
+ }
18
+ async prepareSetup(_connection) { }
19
+ }
@@ -0,0 +1,8 @@
1
+ import type { ISqlDialect } from './sql-dialect.ts';
2
+ export declare class SqlDialectFactory {
3
+ private readonly byName;
4
+ constructor(dialects: readonly ISqlDialect[]);
5
+ tryGet(raw: string): ISqlDialect | undefined;
6
+ get(raw: string): ISqlDialect;
7
+ all(): readonly ISqlDialect[];
8
+ }
@@ -0,0 +1,22 @@
1
+ import { normalizeDialect } from "../sql.js";
2
+ const VALID = 'sqlite, mysql, postgres, sqlserver, oracle';
3
+ export class SqlDialectFactory {
4
+ byName;
5
+ constructor(dialects) {
6
+ this.byName = new Map(dialects.map((d) => [d.name, d]));
7
+ }
8
+ tryGet(raw) {
9
+ const key = normalizeDialect(raw);
10
+ return key ? this.byName.get(key) : undefined;
11
+ }
12
+ get(raw) {
13
+ const dialect = this.tryGet(raw);
14
+ if (!dialect) {
15
+ throw new Error(`Unknown SQL dialect "${raw}". Valid: ${VALID}.`);
16
+ }
17
+ return dialect;
18
+ }
19
+ all() {
20
+ return [...this.byName.values()];
21
+ }
22
+ }
@@ -0,0 +1,16 @@
1
+ import type { MigrationClient } from '../migration-client.ts';
2
+ import type { SqlDialect } from '../sql.ts';
3
+ export interface ISqlDialect {
4
+ readonly name: SqlDialect;
5
+ readonly connectionEnvironmentVariables: readonly string[];
6
+ readonly migratesDdl: string;
7
+ readonly migrateLogsDdl: string;
8
+ readonly usesLastInsertRowid: boolean;
9
+ quoteIdent(ident: string): string;
10
+ nowExpr(): string;
11
+ limitClause(n: number): string;
12
+ translatePlaceholders(sql: string): string;
13
+ prerequisiteError(connection: string): Promise<string | null>;
14
+ prepareSetup(connection: string): Promise<void>;
15
+ createClient(connection: string): Promise<MigrationClient>;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};