@strav/cli 0.1.1 → 0.1.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strav/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI framework and code generators for the Strav framework",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"strav": "./src/cli/strav.ts"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@strav/kernel": "0.1.
|
|
37
|
-
"@strav/http": "0.1.
|
|
38
|
-
"@strav/database": "0.1.
|
|
39
|
-
"@strav/queue": "0.1.
|
|
40
|
-
"@strav/signal": "0.1.
|
|
36
|
+
"@strav/kernel": "0.1.4",
|
|
37
|
+
"@strav/http": "0.1.4",
|
|
38
|
+
"@strav/database": "0.1.4",
|
|
39
|
+
"@strav/queue": "0.1.4",
|
|
40
|
+
"@strav/signal": "0.1.4"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"chalk": "^5.6.2",
|
|
@@ -11,6 +11,7 @@ import SqlGenerator from '@strav/database/database/migration/sql_generator'
|
|
|
11
11
|
import MigrationFileGenerator from '@strav/database/database/migration/file_generator'
|
|
12
12
|
import MigrationTracker from '@strav/database/database/migration/tracker'
|
|
13
13
|
import MigrationRunner from '@strav/database/database/migration/runner'
|
|
14
|
+
import { discoverDomains } from '@strav/database'
|
|
14
15
|
import { getDatabasePaths } from '../config/loader.ts'
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -23,7 +24,8 @@ export async function freshDatabase(
|
|
|
23
24
|
db: Database,
|
|
24
25
|
registry: SchemaRegistry,
|
|
25
26
|
introspector: DatabaseIntrospector,
|
|
26
|
-
migrationsPath: string = 'database/migrations'
|
|
27
|
+
migrationsPath: string = 'database/migrations',
|
|
28
|
+
scope: string = 'public'
|
|
27
29
|
): Promise<number> {
|
|
28
30
|
// Drop all tables in public schema
|
|
29
31
|
console.log(chalk.cyan('\nDropping all tables and types...'))
|
|
@@ -69,8 +71,8 @@ export async function freshDatabase(
|
|
|
69
71
|
// Run the migration
|
|
70
72
|
console.log(chalk.cyan('Running migration...'))
|
|
71
73
|
|
|
72
|
-
const tracker = new MigrationTracker(db)
|
|
73
|
-
const runner = new MigrationRunner(db, tracker, migrationsPath)
|
|
74
|
+
const tracker = new MigrationTracker(db, scope)
|
|
75
|
+
const runner = new MigrationRunner(db, tracker, migrationsPath, scope)
|
|
74
76
|
const result = await runner.run()
|
|
75
77
|
|
|
76
78
|
return result.applied.length
|
|
@@ -99,7 +101,8 @@ export function register(program: Command): void {
|
|
|
99
101
|
.command('fresh')
|
|
100
102
|
.alias('migration:fresh')
|
|
101
103
|
.description('Reset database and migrations, regenerate and run from scratch')
|
|
102
|
-
.
|
|
104
|
+
.option('-s, --scope <scope>', 'Domain (e.g., public, tenant, factory, marketing)', 'public')
|
|
105
|
+
.action(async (opts: { scope: string }) => {
|
|
103
106
|
requireLocalEnv('fresh')
|
|
104
107
|
|
|
105
108
|
// 6-digit challenge
|
|
@@ -123,10 +126,19 @@ export function register(program: Command): void {
|
|
|
123
126
|
// Get configured database paths
|
|
124
127
|
const dbPaths = await getDatabasePaths()
|
|
125
128
|
|
|
126
|
-
|
|
129
|
+
// Validate scope against available domains
|
|
130
|
+
const availableDomains = discoverDomains(dbPaths.schemas)
|
|
131
|
+
if (!availableDomains.includes(opts.scope)) {
|
|
132
|
+
throw new Error(`Invalid domain: ${opts.scope}. Available domains: ${availableDomains.join(', ')}`)
|
|
133
|
+
}
|
|
134
|
+
const scope = opts.scope
|
|
135
|
+
|
|
136
|
+
const { db: database, registry, introspector } = await bootstrap(scope)
|
|
127
137
|
db = database
|
|
128
138
|
|
|
129
|
-
|
|
139
|
+
// Use scoped migrations path
|
|
140
|
+
const scopedPath = `${dbPaths.migrations}/${scope}`
|
|
141
|
+
const applied = await freshDatabase(db, registry, introspector, scopedPath, scope)
|
|
130
142
|
|
|
131
143
|
console.log(chalk.green(`\nFresh migration complete. Applied ${applied} migration(s).`))
|
|
132
144
|
} catch (err) {
|