@deessejs/cli 0.3.0 → 0.3.1
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/dist/commands/db-generate.d.ts +3 -6
- package/dist/commands/db-generate.d.ts.map +1 -1
- package/dist/commands/db-generate.js +15 -46
- package/dist/commands/db-generate.js.map +1 -1
- package/dist/commands/db-introspect.d.ts +2 -3
- package/dist/commands/db-introspect.d.ts.map +1 -1
- package/dist/commands/db-introspect.js +5 -27
- package/dist/commands/db-introspect.js.map +1 -1
- package/dist/commands/db-migrate.d.ts +3 -4
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/db-migrate.js +25 -61
- package/dist/commands/db-migrate.js.map +1 -1
- package/dist/commands/db-push.d.ts +3 -6
- package/dist/commands/db-push.d.ts.map +1 -1
- package/dist/commands/db-push.js +19 -47
- package/dist/commands/db-push.js.map +1 -1
- package/package.json +2 -3
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:generate command
|
|
3
3
|
*
|
|
4
|
-
* Generates migrations from schema changes
|
|
4
|
+
* Generates migrations from schema changes by spawning drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
9
|
-
* 3. Get previous snapshot from ./src/db/meta/_snapshot.json (if exists)
|
|
10
|
-
* 4. Generate migration SQL using generateMigration
|
|
11
|
-
* 5. Save new snapshot and migration files
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
|
+
* 2. Spawn drizzle-kit generate command
|
|
12
9
|
*/
|
|
13
10
|
export interface DbGenerateOptions {
|
|
14
11
|
cwd?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-generate.d.ts","sourceRoot":"","sources":["../../src/commands/db-generate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-generate.d.ts","sourceRoot":"","sources":["../../src/commands/db-generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0B/E"}
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:generate command
|
|
3
3
|
*
|
|
4
|
-
* Generates migrations from schema changes
|
|
4
|
+
* Generates migrations from schema changes by spawning drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
9
|
-
* 3. Get previous snapshot from ./src/db/meta/_snapshot.json (if exists)
|
|
10
|
-
* 4. Generate migration SQL using generateMigration
|
|
11
|
-
* 5. Save new snapshot and migration files
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
|
+
* 2. Spawn drizzle-kit generate command
|
|
12
9
|
*/
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { generateDrizzleJson, generateMigration, } from 'drizzle-kit/api';
|
|
16
|
-
import { loadSchema, verifySchemaPath } from '../utils/schema-loader.js';
|
|
17
|
-
const SCHEMA_PATH = './src/db/schema.ts';
|
|
18
|
-
const MIGRATIONS_DIR = './src/db/migrations';
|
|
19
|
-
const SNAPSHOT_DIR = './src/db/meta';
|
|
20
|
-
const SNAPSHOT_FILE = '_snapshot.json';
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
11
|
+
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
21
12
|
export async function dbGenerate(options = {}) {
|
|
22
13
|
const cwd = options.cwd ?? process.cwd();
|
|
23
14
|
// Verify schema file exists
|
|
@@ -28,40 +19,18 @@ export async function dbGenerate(options = {}) {
|
|
|
28
19
|
throw new Error(`db:generate requires ${SCHEMA_PATH} to exist.\n` +
|
|
29
20
|
`Please create this file and export your Drizzle tables.`);
|
|
30
21
|
}
|
|
31
|
-
|
|
32
|
-
await fs.mkdir(path.join(cwd, MIGRATIONS_DIR), { recursive: true });
|
|
33
|
-
// Ensure snapshot directory exists
|
|
34
|
-
await fs.mkdir(path.join(cwd, SNAPSHOT_DIR), { recursive: true });
|
|
35
|
-
// Load the schema
|
|
36
|
-
const { schema } = await loadSchema();
|
|
37
|
-
// Generate current schema snapshot
|
|
38
|
-
const currentSchema = generateDrizzleJson(schema);
|
|
39
|
-
// Load previous snapshot (if exists)
|
|
40
|
-
let prevSchema = null;
|
|
41
|
-
const snapshotPath = path.join(cwd, SNAPSHOT_DIR, SNAPSHOT_FILE);
|
|
22
|
+
console.warn('Generating migrations using drizzle-kit...');
|
|
42
23
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
execSync('npx drizzle-kit generate', {
|
|
25
|
+
cwd,
|
|
26
|
+
stdio: 'inherit',
|
|
27
|
+
});
|
|
45
28
|
}
|
|
46
|
-
catch {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const migrationSql = await generateMigration(prevSchema ?? undefined, currentSchema);
|
|
52
|
-
if (!migrationSql || migrationSql.length === 0) {
|
|
53
|
-
console.warn('No changes detected. No migration to generate.');
|
|
54
|
-
return;
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code === 'ENOENT') {
|
|
31
|
+
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
55
34
|
}
|
|
56
|
-
// Generate migration file name based on timestamp
|
|
57
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
58
|
-
const migrationName = `${timestamp}_migration.sql`;
|
|
59
|
-
const migrationPath = path.join(cwd, MIGRATIONS_DIR, migrationName);
|
|
60
|
-
// Save migration file
|
|
61
|
-
await fs.writeFile(migrationPath, migrationSql.join('\n\n'));
|
|
62
|
-
// Save new snapshot
|
|
63
|
-
await fs.writeFile(snapshotPath, JSON.stringify(currentSchema, null, 2));
|
|
64
|
-
console.warn(`Generated migration: ${migrationName}`);
|
|
65
|
-
console.warn(`Migration saved to: ${MIGRATIONS_DIR}/${migrationName}`);
|
|
66
35
|
}
|
|
67
36
|
//# sourceMappingURL=db-generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-generate.js","sourceRoot":"","sources":["../../src/commands/db-generate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-generate.js","sourceRoot":"","sources":["../../src/commands/db-generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAM1E,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAA6B,EAAE;IAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAEzC,4BAA4B;IAC5B,IAAI,CAAC;QACH,MAAM,gBAAgB,EAAE,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,wBAAwB,WAAW,cAAc;YACjD,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,QAAQ,CAAC,0BAA0B,EAAE;YACnC,GAAG;YACH,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:introspect command
|
|
3
3
|
*
|
|
4
|
-
* Introspects the database
|
|
4
|
+
* Introspects the database by spawning drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
8
|
* 2. Spawn drizzle-kit introspect command
|
|
9
|
-
* 3. Note: Introspection result needs to be processed manually
|
|
10
9
|
*/
|
|
11
10
|
export interface DbIntrospectOptions {
|
|
12
11
|
cwd?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-introspect.d.ts","sourceRoot":"","sources":["../../src/commands/db-introspect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-introspect.d.ts","sourceRoot":"","sources":["../../src/commands/db-introspect.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgDnF"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:introspect command
|
|
3
3
|
*
|
|
4
|
-
* Introspects the database
|
|
4
|
+
* Introspects the database by spawning drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
8
|
* 2. Spawn drizzle-kit introspect command
|
|
9
|
-
* 3. Note: Introspection result needs to be processed manually
|
|
10
9
|
*/
|
|
11
10
|
import { execSync } from 'node:child_process';
|
|
11
|
+
import { SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
12
12
|
import { loadConfig } from '../utils/config.js';
|
|
13
13
|
import { detectDialect } from '../utils/dialect.js';
|
|
14
|
-
import { SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
15
14
|
import * as fs from 'node:fs/promises';
|
|
16
15
|
import * as path from 'node:path';
|
|
17
16
|
import * as p from '@clack/prompts';
|
|
@@ -26,15 +25,6 @@ export async function dbIntrospect(options = {}) {
|
|
|
26
25
|
// Detect dialect
|
|
27
26
|
const dialect = detectDialect(db);
|
|
28
27
|
console.warn(`Introspecting ${dialect} database...`);
|
|
29
|
-
console.warn('');
|
|
30
|
-
console.warn(`Note: db:introspect requires drizzle-kit CLI introspection.`);
|
|
31
|
-
console.warn(`This command will attempt to use 'npx drizzle-kit introspect'.`);
|
|
32
|
-
console.warn('');
|
|
33
|
-
// Build the command
|
|
34
|
-
const args = [
|
|
35
|
-
'drizzle-kit',
|
|
36
|
-
'introspect',
|
|
37
|
-
];
|
|
38
28
|
// Check if schema file exists and warn
|
|
39
29
|
const schemaPath = path.join(cwd, SCHEMA_PATH);
|
|
40
30
|
try {
|
|
@@ -53,29 +43,17 @@ export async function dbIntrospect(options = {}) {
|
|
|
53
43
|
catch {
|
|
54
44
|
// File doesn't exist, that's fine
|
|
55
45
|
}
|
|
46
|
+
console.warn('Introspecting database using drizzle-kit...');
|
|
56
47
|
try {
|
|
57
|
-
|
|
58
|
-
// Note: This requires drizzle.config.ts to be configured properly
|
|
59
|
-
execSync(`npx ${args.join(' ')}`, {
|
|
48
|
+
execSync('npx drizzle-kit introspect', {
|
|
60
49
|
cwd,
|
|
61
50
|
stdio: 'inherit',
|
|
62
51
|
});
|
|
63
|
-
console.warn('');
|
|
64
|
-
console.warn('Introspection complete!');
|
|
65
|
-
console.warn('');
|
|
66
|
-
console.warn('Note: drizzle-kit generates a drizzle schema file, not src/db/schema.ts.');
|
|
67
|
-
console.warn('You may need to manually copy the generated schema to src/db/schema.ts');
|
|
68
52
|
}
|
|
69
53
|
catch (error) {
|
|
70
54
|
if (error.code === 'ENOENT') {
|
|
71
55
|
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
72
56
|
}
|
|
73
|
-
console.warn('');
|
|
74
|
-
console.warn('Drizzle Kit introspection requires a drizzle.config.ts file.');
|
|
75
|
-
console.warn('For full introspection support, please:');
|
|
76
|
-
console.warn('1. Create a drizzle.config.ts file');
|
|
77
|
-
console.warn('2. Run: npx drizzle-kit introspect');
|
|
78
|
-
console.warn('');
|
|
79
57
|
throw error;
|
|
80
58
|
}
|
|
81
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-introspect.js","sourceRoot":"","sources":["../../src/commands/db-introspect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-introspect.js","sourceRoot":"","sources":["../../src/commands/db-introspect.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAOpC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAA+B,EAAE;IAClE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAEvD,+CAA+C;IAC/C,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,EAAE,CAAC;IACtC,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;IAE3B,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,iBAAiB;IACjB,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAElC,OAAO,CAAC,IAAI,CAAC,iBAAiB,OAAO,cAAc,CAAC,CAAC;IAErD,uCAAuC;IACvC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC/C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC5B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC;gBAC9B,OAAO,EAAE,YAAY,WAAW,6BAA6B;gBAC7D,YAAY,EAAE,KAAK;aACpB,CAAC,CAAC;YAEH,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACpC,CAAC,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;gBAClC,OAAO;YACT,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,kCAAkC;IACpC,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;IAE5D,IAAI,CAAC;QACH,QAAQ,CAAC,4BAA4B,EAAE;YACrC,GAAG;YACH,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:migrate command
|
|
3
3
|
*
|
|
4
|
-
* Applies pending migrations
|
|
4
|
+
* Applies pending migrations by spawning drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
9
|
-
* 3. Execute each migration in order
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
|
+
* 2. Spawn drizzle-kit migrate command
|
|
10
9
|
*/
|
|
11
10
|
export interface DbMigrateOptions {
|
|
12
11
|
cwd?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-migrate.d.ts","sourceRoot":"","sources":["../../src/commands/db-migrate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-migrate.d.ts","sourceRoot":"","sources":["../../src/commands/db-migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiC7E"}
|
|
@@ -1,77 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:migrate command
|
|
3
3
|
*
|
|
4
|
-
* Applies pending migrations
|
|
4
|
+
* Applies pending migrations by spawning drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
9
|
-
* 3. Execute each migration in order
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
|
+
* 2. Spawn drizzle-kit migrate command
|
|
10
9
|
*/
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { loadConfig } from '../utils/config.js';
|
|
14
|
-
const MIGRATIONS_DIR = './src/db/migrations';
|
|
15
|
-
async function getMigrationFiles(cwd) {
|
|
16
|
-
const migrationsPath = path.join(cwd, MIGRATIONS_DIR);
|
|
17
|
-
try {
|
|
18
|
-
const files = await fs.readdir(migrationsPath);
|
|
19
|
-
return files
|
|
20
|
-
.filter((file) => file.endsWith('.sql'))
|
|
21
|
-
.map((name) => ({
|
|
22
|
-
name,
|
|
23
|
-
path: path.join(migrationsPath, name),
|
|
24
|
-
}))
|
|
25
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
11
|
+
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
31
12
|
export async function dbMigrate(options = {}) {
|
|
32
13
|
const { cwd = process.cwd(), dryRun = false } = options;
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!db) {
|
|
37
|
-
throw new Error('Config does not have a database instance');
|
|
14
|
+
// Verify schema file exists
|
|
15
|
+
try {
|
|
16
|
+
await verifySchemaPath();
|
|
38
17
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.warn('No migrations to apply.');
|
|
43
|
-
return;
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error(`db:migrate requires ${SCHEMA_PATH} to exist.\n` +
|
|
20
|
+
`Please create this file and export your Drizzle tables.`);
|
|
44
21
|
}
|
|
45
|
-
console.warn(
|
|
22
|
+
console.warn('Applying migrations using drizzle-kit...');
|
|
23
|
+
// Build the command
|
|
24
|
+
const args = ['drizzle-kit', 'migrate'];
|
|
46
25
|
if (dryRun) {
|
|
47
|
-
|
|
48
|
-
for (const file of files) {
|
|
49
|
-
console.warn(` - ${file.name}`);
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
26
|
+
args.push('--dry-run');
|
|
52
27
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
await db.execute(sql);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw new Error('Database driver does not support execute(). ' +
|
|
66
|
-
'Please use a supported driver like drizzle-orm/node-postgres.');
|
|
67
|
-
}
|
|
68
|
-
console.warn(` Applied successfully`);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
console.error(` Failed: ${error.message}`);
|
|
72
|
-
throw error;
|
|
28
|
+
try {
|
|
29
|
+
execSync(`npx ${args.join(' ')}`, {
|
|
30
|
+
cwd,
|
|
31
|
+
stdio: 'inherit',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.code === 'ENOENT') {
|
|
36
|
+
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
73
37
|
}
|
|
38
|
+
throw error;
|
|
74
39
|
}
|
|
75
|
-
console.warn(`\nSuccessfully applied ${files.length} migration(s).`);
|
|
76
40
|
}
|
|
77
41
|
//# sourceMappingURL=db-migrate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-migrate.js","sourceRoot":"","sources":["../../src/commands/db-migrate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-migrate.js","sourceRoot":"","sources":["../../src/commands/db-migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAO1E,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,UAA4B,EAAE;IAC5D,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAExD,4BAA4B;IAC5B,IAAI,CAAC;QACH,MAAM,gBAAgB,EAAE,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,uBAAuB,WAAW,cAAc;YAChD,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;IAEzD,oBAAoB;IACpB,MAAM,IAAI,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAExC,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,CAAC;QACH,QAAQ,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;YAChC,GAAG;YACH,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:push command
|
|
3
3
|
*
|
|
4
|
-
* Pushes schema changes directly to the database
|
|
5
|
-
* Uses drizzle-kit's pushSchema programmatic API.
|
|
4
|
+
* Pushes schema changes directly to the database by spawning drizzle-kit CLI.
|
|
6
5
|
*
|
|
7
6
|
* Flow:
|
|
8
|
-
* 1.
|
|
9
|
-
* 2.
|
|
10
|
-
* 3. Call pushSchema with the schema
|
|
11
|
-
* 4. Show warnings and apply if confirmed (or force)
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
|
+
* 2. Spawn drizzle-kit push command
|
|
12
9
|
*/
|
|
13
10
|
export interface DbPushOptions {
|
|
14
11
|
force?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-push.d.ts","sourceRoot":"","sources":["../../src/commands/db-push.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-push.d.ts","sourceRoot":"","sources":["../../src/commands/db-push.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiCvE"}
|
package/dist/commands/db-push.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:push command
|
|
3
3
|
*
|
|
4
|
-
* Pushes schema changes directly to the database
|
|
5
|
-
* Uses drizzle-kit's pushSchema programmatic API.
|
|
4
|
+
* Pushes schema changes directly to the database by spawning drizzle-kit CLI.
|
|
6
5
|
*
|
|
7
6
|
* Flow:
|
|
8
|
-
* 1.
|
|
9
|
-
* 2.
|
|
10
|
-
* 3. Call pushSchema with the schema
|
|
11
|
-
* 4. Show warnings and apply if confirmed (or force)
|
|
7
|
+
* 1. Verify schema exists at ./src/db/schema.ts
|
|
8
|
+
* 2. Spawn drizzle-kit push command
|
|
12
9
|
*/
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { loadSchema, verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
16
|
-
import * as p from '@clack/prompts';
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
11
|
+
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
17
12
|
export async function dbPush(options = {}) {
|
|
18
|
-
const { force = false } = options;
|
|
13
|
+
const { force = false, cwd = process.cwd() } = options;
|
|
19
14
|
// Verify schema file exists
|
|
20
15
|
try {
|
|
21
16
|
await verifySchemaPath();
|
|
@@ -24,46 +19,23 @@ export async function dbPush(options = {}) {
|
|
|
24
19
|
throw new Error(`db:push requires ${SCHEMA_PATH} to exist.\n` +
|
|
25
20
|
`Please create this file and export your Drizzle tables.`);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
|
|
22
|
+
console.warn('Pushing schema changes to database using drizzle-kit...');
|
|
23
|
+
// Build the command
|
|
24
|
+
const args = ['drizzle-kit', 'push'];
|
|
25
|
+
if (force) {
|
|
26
|
+
args.push('--force');
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const result = await pushSchema(schema, db);
|
|
38
|
-
// Check for data loss
|
|
39
|
-
if (result.hasDataLoss && !force) {
|
|
40
|
-
p.note('The following changes may cause data loss:', 'Warning');
|
|
41
|
-
for (const warning of result.warnings) {
|
|
42
|
-
console.warn(` - ${warning}`);
|
|
43
|
-
}
|
|
44
|
-
console.warn('');
|
|
45
|
-
const confirm = await p.confirm({
|
|
46
|
-
message: 'Do you want to apply these changes anyway?',
|
|
47
|
-
initialValue: false,
|
|
28
|
+
try {
|
|
29
|
+
execSync(`npx ${args.join(' ')}`, {
|
|
30
|
+
cwd,
|
|
31
|
+
stdio: 'inherit',
|
|
48
32
|
});
|
|
49
|
-
if (p.isCancel(confirm) || !confirm) {
|
|
50
|
-
p.cancel('Push cancelled.');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else if (result.warnings.length > 0) {
|
|
55
|
-
p.note(result.warnings.join('\n'), 'Warnings');
|
|
56
33
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
for (const stmt of result.statementsToExecute) {
|
|
61
|
-
console.warn(` ${stmt}`);
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.code === 'ENOENT') {
|
|
36
|
+
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
62
37
|
}
|
|
63
|
-
|
|
38
|
+
throw error;
|
|
64
39
|
}
|
|
65
|
-
// Apply the changes
|
|
66
|
-
await result.apply();
|
|
67
|
-
console.warn(`Successfully pushed ${result.statementsToExecute.length} changes to the database.`);
|
|
68
40
|
}
|
|
69
41
|
//# sourceMappingURL=db-push.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-push.js","sourceRoot":"","sources":["../../src/commands/db-push.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-push.js","sourceRoot":"","sources":["../../src/commands/db-push.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAO1E,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,UAAyB,EAAE;IACtD,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAEvD,4BAA4B;IAC5B,IAAI,CAAC;QACH,MAAM,gBAAgB,EAAE,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,oBAAoB,WAAW,cAAc;YAC7C,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;IAExE,oBAAoB;IACpB,MAAM,IAAI,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAErC,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,CAAC;QACH,QAAQ,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;YAChC,GAAG;YACH,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deessejs/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "DeesseJS CLI for managing DeesseJS projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
"author": "DeesseJS",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@clack/prompts": "^0.8.2"
|
|
28
|
-
"drizzle-kit": "^0.30.0"
|
|
27
|
+
"@clack/prompts": "^0.8.2"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"@types/node": "^22.10.6",
|