drizzle-multitenant 1.0.3 → 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.
@@ -10,7 +10,9 @@
10
10
  "Bash(mkdir:*)",
11
11
  "Bash(node ./bin/drizzle-multitenant.js:*)",
12
12
  "Bash(ls:*)",
13
- "Bash(npm run test:*)"
13
+ "Bash(npm run test:*)",
14
+ "Bash(node ./dist/cli/index.js:*)",
15
+ "Bash(npx tsc:*)"
14
16
  ]
15
17
  }
16
18
  }
package/README.md CHANGED
@@ -56,6 +56,15 @@ export default defineConfig({
56
56
  tenant: tenantSchema,
57
57
  shared: sharedSchema,
58
58
  },
59
+ // Optional: CLI migrations config
60
+ migrations: {
61
+ tenantFolder: './drizzle/tenant',
62
+ migrationsTable: '__drizzle_migrations', // Custom table name
63
+ tenantDiscovery: async () => {
64
+ // Return list of tenant IDs for migrations
65
+ return ['tenant-1', 'tenant-2'];
66
+ },
67
+ },
59
68
  });
60
69
  ```
61
70
 
@@ -200,12 +209,18 @@ expect(tenantDb.__tenantId).toBe('expected-tenant');
200
209
  ## CLI Commands
201
210
 
202
211
  ```bash
212
+ # Initialize configuration (interactive wizard)
213
+ npx drizzle-multitenant init
214
+
203
215
  # Generate a new migration
204
216
  npx drizzle-multitenant generate --name=add-users-table
205
217
 
206
- # Apply migrations to all tenants
218
+ # Apply migrations to all tenants (with progress bar)
207
219
  npx drizzle-multitenant migrate --all --concurrency=10
208
220
 
221
+ # Interactive tenant selection
222
+ npx drizzle-multitenant migrate # Shows checkbox to select tenants
223
+
209
224
  # Check migration status
210
225
  npx drizzle-multitenant status
211
226
 
@@ -214,18 +229,114 @@ npx drizzle-multitenant tenant:create --id=new-tenant
214
229
 
215
230
  # Drop a tenant schema
216
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'
217
258
  ```
218
259
 
219
260
  ### Status Output
220
261
 
221
262
  ```
222
- ┌─────────────────────┬─────────┬─────────┬──────────┐
223
- │ Tenant │ Applied │ Pending │ Status │
224
- ├─────────────────────┼─────────┼─────────┼──────────┤
225
- tenant_abc123 150OK
226
- tenant_def45615 │ 0 │ OK │
227
- tenant_ghi789 141 │ Behind │
228
- └─────────────────────┴─────────┴─────────┴──────────┘
263
+ ┌──────────────────┬──────────────┬────────────┬─────────┬─────────┬──────────┐
264
+ │ Tenant Schema │ Format │ Applied │ Pending │ Status │
265
+ ├──────────────────┼──────────────┼────────────┼─────────┼─────────┼──────────┤
266
+ abc-123 tenant_abc │ drizzle-kit│ 453Behind
267
+ def-456 │ tenant_def │ name48 │ 0 │ OK │
268
+ ghi-789 tenant_ghi │ (new)048 │ 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
229
340
  ```
230
341
 
231
342
  ## Cross-Schema Queries
@@ -310,6 +421,8 @@ const result = await query
310
421
  | `chalk` | Terminal styling |
311
422
  | `ora` | Loading spinners |
312
423
  | `cli-table3` | Table formatting |
424
+ | `cli-progress` | Progress bars |
425
+ | `@inquirer/prompts` | Interactive prompts |
313
426
 
314
427
  ## Comparison
315
428