drizzle-multitenant 1.0.4 → 1.0.5
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/.claude/settings.local.json +3 -1
- package/README.md +112 -8
- package/dist/cli/index.js +1347 -141
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +178 -29
- package/dist/index.js.map +1 -1
- package/dist/migrator/index.d.ts +85 -4
- package/dist/migrator/index.js +197 -30
- package/dist/migrator/index.js.map +1 -1
- package/package.json +4 -1
- package/proposals/drizzle-kit-compatibility.md +499 -0
- package/proposals/improvements-from-primesys.md +385 -0
package/README.md
CHANGED
|
@@ -209,12 +209,18 @@ expect(tenantDb.__tenantId).toBe('expected-tenant');
|
|
|
209
209
|
## CLI Commands
|
|
210
210
|
|
|
211
211
|
```bash
|
|
212
|
+
# Initialize configuration (interactive wizard)
|
|
213
|
+
npx drizzle-multitenant init
|
|
214
|
+
|
|
212
215
|
# Generate a new migration
|
|
213
216
|
npx drizzle-multitenant generate --name=add-users-table
|
|
214
217
|
|
|
215
|
-
# Apply migrations to all tenants
|
|
218
|
+
# Apply migrations to all tenants (with progress bar)
|
|
216
219
|
npx drizzle-multitenant migrate --all --concurrency=10
|
|
217
220
|
|
|
221
|
+
# Interactive tenant selection
|
|
222
|
+
npx drizzle-multitenant migrate # Shows checkbox to select tenants
|
|
223
|
+
|
|
218
224
|
# Check migration status
|
|
219
225
|
npx drizzle-multitenant status
|
|
220
226
|
|
|
@@ -223,18 +229,114 @@ npx drizzle-multitenant tenant:create --id=new-tenant
|
|
|
223
229
|
|
|
224
230
|
# Drop a tenant schema
|
|
225
231
|
npx drizzle-multitenant tenant:drop --id=old-tenant --force
|
|
232
|
+
|
|
233
|
+
# Convert migration table format
|
|
234
|
+
npx drizzle-multitenant convert-format --to=name --dry-run
|
|
235
|
+
|
|
236
|
+
# Generate shell completions
|
|
237
|
+
npx drizzle-multitenant completion bash >> ~/.bashrc
|
|
238
|
+
npx drizzle-multitenant completion zsh >> ~/.zshrc
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Global Options
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
--json # Output as JSON (for scripts/CI)
|
|
245
|
+
--verbose # Show detailed output
|
|
246
|
+
--quiet # Only show errors
|
|
247
|
+
--no-color # Disable colored output
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### JSON Output
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# Get status as JSON for scripting
|
|
254
|
+
npx drizzle-multitenant status --json | jq '.tenants[] | select(.pending > 0)'
|
|
255
|
+
|
|
256
|
+
# Parse migration results
|
|
257
|
+
npx drizzle-multitenant migrate --all --json | jq '.summary'
|
|
226
258
|
```
|
|
227
259
|
|
|
228
260
|
### Status Output
|
|
229
261
|
|
|
230
262
|
```
|
|
231
|
-
|
|
232
|
-
│ Tenant
|
|
233
|
-
|
|
234
|
-
│
|
|
235
|
-
│
|
|
236
|
-
│
|
|
237
|
-
|
|
263
|
+
┌──────────────────┬──────────────┬────────────┬─────────┬─────────┬──────────┐
|
|
264
|
+
│ Tenant │ Schema │ Format │ Applied │ Pending │ Status │
|
|
265
|
+
├──────────────────┼──────────────┼────────────┼─────────┼─────────┼──────────┤
|
|
266
|
+
│ abc-123 │ tenant_abc │ drizzle-kit│ 45 │ 3 │ Behind │
|
|
267
|
+
│ def-456 │ tenant_def │ name │ 48 │ 0 │ OK │
|
|
268
|
+
│ ghi-789 │ tenant_ghi │ (new) │ 0 │ 48 │ Behind │
|
|
269
|
+
└──────────────────┴──────────────┴────────────┴─────────┴─────────┴──────────┘
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Migration Table Formats
|
|
273
|
+
|
|
274
|
+
`drizzle-multitenant` supports multiple migration table formats for compatibility with existing databases:
|
|
275
|
+
|
|
276
|
+
### Supported Formats
|
|
277
|
+
|
|
278
|
+
| Format | Identifier | Timestamp | Compatible With |
|
|
279
|
+
|--------|------------|-----------|-----------------|
|
|
280
|
+
| `name` | Filename | `applied_at` (timestamp) | drizzle-multitenant native |
|
|
281
|
+
| `hash` | SHA-256 | `created_at` (timestamp) | Custom scripts |
|
|
282
|
+
| `drizzle-kit` | SHA-256 | `created_at` (bigint) | drizzle-kit migrate |
|
|
283
|
+
|
|
284
|
+
### Configuration
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
// tenant.config.ts
|
|
288
|
+
export default defineConfig({
|
|
289
|
+
// ...
|
|
290
|
+
migrations: {
|
|
291
|
+
tenantFolder: './drizzle/tenant',
|
|
292
|
+
tenantDiscovery: async () => getTenantIds(),
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Table format for tracking migrations
|
|
296
|
+
* - "auto": Auto-detect existing format (default)
|
|
297
|
+
* - "name": Filename-based (drizzle-multitenant native)
|
|
298
|
+
* - "hash": SHA-256 hash
|
|
299
|
+
* - "drizzle-kit": Exact drizzle-kit format
|
|
300
|
+
*/
|
|
301
|
+
tableFormat: 'auto',
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Format to use when creating new tables (only for "auto" mode)
|
|
305
|
+
* @default "name"
|
|
306
|
+
*/
|
|
307
|
+
defaultFormat: 'name',
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Migrating from drizzle-kit
|
|
313
|
+
|
|
314
|
+
If you have existing databases with migrations applied via `drizzle-kit migrate`, the CLI will automatically detect the format:
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
# Check current format for all tenants
|
|
318
|
+
npx drizzle-multitenant status
|
|
319
|
+
|
|
320
|
+
# Apply new migrations (works with any format)
|
|
321
|
+
npx drizzle-multitenant migrate --all
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Converting Between Formats
|
|
325
|
+
|
|
326
|
+
Use the `convert-format` command to standardize all tenants to a single format:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# Preview conversion (dry-run)
|
|
330
|
+
npx drizzle-multitenant convert-format --to=name --dry-run
|
|
331
|
+
|
|
332
|
+
# Convert all tenants to name format
|
|
333
|
+
npx drizzle-multitenant convert-format --to=name
|
|
334
|
+
|
|
335
|
+
# Convert specific tenant
|
|
336
|
+
npx drizzle-multitenant convert-format --to=name --tenant=abc-123
|
|
337
|
+
|
|
338
|
+
# Convert to drizzle-kit format (for compatibility)
|
|
339
|
+
npx drizzle-multitenant convert-format --to=drizzle-kit
|
|
238
340
|
```
|
|
239
341
|
|
|
240
342
|
## Cross-Schema Queries
|
|
@@ -319,6 +421,8 @@ const result = await query
|
|
|
319
421
|
| `chalk` | Terminal styling |
|
|
320
422
|
| `ora` | Loading spinners |
|
|
321
423
|
| `cli-table3` | Table formatting |
|
|
424
|
+
| `cli-progress` | Progress bars |
|
|
425
|
+
| `@inquirer/prompts` | Interactive prompts |
|
|
322
426
|
|
|
323
427
|
## Comparison
|
|
324
428
|
|