@deessejs/cli 0.3.1 → 0.4.0
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 +6 -3
- package/dist/commands/db-generate.d.ts.map +1 -1
- package/dist/commands/db-generate.js +48 -15
- package/dist/commands/db-generate.js.map +1 -1
- package/dist/commands/db-introspect.d.ts +4 -5
- package/dist/commands/db-introspect.d.ts.map +1 -1
- package/dist/commands/db-introspect.js +17 -43
- package/dist/commands/db-introspect.js.map +1 -1
- package/dist/commands/db-migrate.d.ts +4 -5
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/db-migrate.js +17 -25
- package/dist/commands/db-migrate.js.map +1 -1
- package/dist/commands/db-push.d.ts +5 -3
- package/dist/commands/db-push.d.ts.map +1 -1
- package/dist/commands/db-push.js +48 -19
- package/dist/commands/db-push.js.map +1 -1
- package/dist/commands/db-studio.d.ts +3 -4
- package/dist/commands/db-studio.d.ts.map +1 -1
- package/dist/commands/db-studio.js +16 -39
- package/dist/commands/db-studio.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:generate command
|
|
3
3
|
*
|
|
4
|
-
* Generates migrations from schema changes
|
|
4
|
+
* Generates migrations from schema changes using drizzle-kit's programmatic API.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
7
|
+
* 1. Load schema from ./src/db/schema.ts
|
|
8
|
+
* 2. Get current schema snapshot using generateDrizzleJson
|
|
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
|
|
9
12
|
*/
|
|
10
13
|
export interface DbGenerateOptions {
|
|
11
14
|
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;;;;;;;;;;;GAWG;AAeH,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgE/E"}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:generate command
|
|
3
3
|
*
|
|
4
|
-
* Generates migrations from schema changes
|
|
4
|
+
* Generates migrations from schema changes using drizzle-kit's programmatic API.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
7
|
+
* 1. Load schema from ./src/db/schema.ts
|
|
8
|
+
* 2. Get current schema snapshot using generateDrizzleJson
|
|
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
|
|
9
12
|
*/
|
|
10
|
-
import
|
|
11
|
-
import
|
|
13
|
+
import * as fs from 'node:fs/promises';
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
16
|
+
import { loadSchema, verifySchemaPath } from '../utils/schema-loader.js';
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
const { generateDrizzleJson, generateMigration } = require('drizzle-kit/api');
|
|
19
|
+
const SCHEMA_PATH = './src/db/schema.ts';
|
|
20
|
+
const MIGRATIONS_DIR = './src/db/migrations';
|
|
21
|
+
const SNAPSHOT_DIR = './src/db/meta';
|
|
22
|
+
const SNAPSHOT_FILE = '_snapshot.json';
|
|
12
23
|
export async function dbGenerate(options = {}) {
|
|
13
24
|
const cwd = options.cwd ?? process.cwd();
|
|
14
25
|
// Verify schema file exists
|
|
@@ -19,18 +30,40 @@ export async function dbGenerate(options = {}) {
|
|
|
19
30
|
throw new Error(`db:generate requires ${SCHEMA_PATH} to exist.\n` +
|
|
20
31
|
`Please create this file and export your Drizzle tables.`);
|
|
21
32
|
}
|
|
22
|
-
|
|
33
|
+
// Ensure migrations directory exists
|
|
34
|
+
await fs.mkdir(path.join(cwd, MIGRATIONS_DIR), { recursive: true });
|
|
35
|
+
// Ensure snapshot directory exists
|
|
36
|
+
await fs.mkdir(path.join(cwd, SNAPSHOT_DIR), { recursive: true });
|
|
37
|
+
// Load the schema
|
|
38
|
+
const { schema } = await loadSchema();
|
|
39
|
+
// Generate current schema snapshot
|
|
40
|
+
const currentSchema = generateDrizzleJson(schema);
|
|
41
|
+
// Load previous snapshot (if exists)
|
|
42
|
+
let prevSchema = null;
|
|
43
|
+
const snapshotPath = path.join(cwd, SNAPSHOT_DIR, SNAPSHOT_FILE);
|
|
23
44
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
stdio: 'inherit',
|
|
27
|
-
});
|
|
45
|
+
const snapshotContent = await fs.readFile(snapshotPath, 'utf-8');
|
|
46
|
+
prevSchema = JSON.parse(snapshotContent);
|
|
28
47
|
}
|
|
29
|
-
catch
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
48
|
+
catch {
|
|
49
|
+
// No previous snapshot - this is the first migration
|
|
50
|
+
console.warn('No previous snapshot found. This will be the first migration.');
|
|
51
|
+
}
|
|
52
|
+
// Generate migration SQL
|
|
53
|
+
const migrationSql = await generateMigration(prevSchema ?? undefined, currentSchema);
|
|
54
|
+
if (!migrationSql || migrationSql.length === 0) {
|
|
55
|
+
console.warn('No changes detected. No migration to generate.');
|
|
56
|
+
return;
|
|
34
57
|
}
|
|
58
|
+
// Generate migration file name based on timestamp
|
|
59
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
60
|
+
const migrationName = `${timestamp}_migration.sql`;
|
|
61
|
+
const migrationPath = path.join(cwd, MIGRATIONS_DIR, migrationName);
|
|
62
|
+
// Save migration file
|
|
63
|
+
await fs.writeFile(migrationPath, migrationSql.join('\n\n'));
|
|
64
|
+
// Save new snapshot
|
|
65
|
+
await fs.writeFile(snapshotPath, JSON.stringify(currentSchema, null, 2));
|
|
66
|
+
console.warn(`Generated migration: ${migrationName}`);
|
|
67
|
+
console.warn(`Migration saved to: ${MIGRATIONS_DIR}/${migrationName}`);
|
|
35
68
|
}
|
|
36
69
|
//# 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;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEzE,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE9E,MAAM,WAAW,GAAG,oBAAoB,CAAC;AACzC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAC7C,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAMvC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAA6B,EAAE;IAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC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AI,CAAC,gDAAgD,CAAC,CAAC;QAC/D,OAAO;IACT,CAAC;IAED,kDAAkD;IAClD,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9E,MAAM,aAAa,GAAG,GAAG,SAAS,gBAAgB,CAAC;IACnD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAEpE,sBAAsB;IACtB,MAAM,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7D,oBAAoB;IACpB,MAAM,EAAE,CAAC,SAAS,CAChB,YAAY,EACZ,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CACvC,CAAC;IAEF,OAAO,CAAC,IAAI,CAAC,wBAAwB,aAAa,EAAE,CAAC,CAAC;IACtD,OAAO,CAAC,IAAI,CAAC,uBAAuB,cAAc,IAAI,aAAa,EAAE,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:introspect command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema setup and provides instructions for introspecting database.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 2. Spawn drizzle-kit introspect command
|
|
6
|
+
* For Drizzle, run:
|
|
7
|
+
* npx drizzle-kit introspect
|
|
9
8
|
*/
|
|
10
9
|
export interface DbIntrospectOptions {
|
|
11
10
|
cwd?: string;
|
|
12
11
|
force?: boolean;
|
|
13
12
|
}
|
|
14
|
-
export declare function dbIntrospect(
|
|
13
|
+
export declare function dbIntrospect(_options?: DbIntrospectOptions): Promise<void>;
|
|
15
14
|
//# sourceMappingURL=db-introspect.d.ts.map
|
|
@@ -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;;;;;;;GAOG;AAKH,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,YAAY,CAAC,QAAQ,GAAE,mBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBpF"}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:introspect command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema setup and provides instructions for introspecting database.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 2. Spawn drizzle-kit introspect command
|
|
6
|
+
* For Drizzle, run:
|
|
7
|
+
* npx drizzle-kit introspect
|
|
9
8
|
*/
|
|
10
|
-
import { execSync } from 'node:child_process';
|
|
11
|
-
import { SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
12
9
|
import { loadConfig } from '../utils/config.js';
|
|
13
10
|
import { detectDialect } from '../utils/dialect.js';
|
|
14
|
-
|
|
15
|
-
import * as path from 'node:path';
|
|
16
|
-
import * as p from '@clack/prompts';
|
|
17
|
-
export async function dbIntrospect(options = {}) {
|
|
18
|
-
const { cwd = process.cwd(), force = false } = options;
|
|
11
|
+
export async function dbIntrospect(_options = {}) {
|
|
19
12
|
// Load config to verify database is configured
|
|
20
13
|
const { config } = await loadConfig();
|
|
21
14
|
const db = config.database;
|
|
@@ -24,37 +17,18 @@ export async function dbIntrospect(options = {}) {
|
|
|
24
17
|
}
|
|
25
18
|
// Detect dialect
|
|
26
19
|
const dialect = detectDialect(db);
|
|
27
|
-
console.warn(`
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// File doesn't exist, that's fine
|
|
45
|
-
}
|
|
46
|
-
console.warn('Introspecting database using drizzle-kit...');
|
|
47
|
-
try {
|
|
48
|
-
execSync('npx drizzle-kit introspect', {
|
|
49
|
-
cwd,
|
|
50
|
-
stdio: 'inherit',
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
if (error.code === 'ENOENT') {
|
|
55
|
-
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
56
|
-
}
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
20
|
+
console.warn(`
|
|
21
|
+
Database Config OK
|
|
22
|
+
|
|
23
|
+
Detected dialect: ${dialect}
|
|
24
|
+
|
|
25
|
+
To introspect your database and generate a schema file, run:
|
|
26
|
+
|
|
27
|
+
npx drizzle-kit introspect
|
|
28
|
+
|
|
29
|
+
This will generate/update a schema file based on your database tables.
|
|
30
|
+
|
|
31
|
+
Note: This command requires a drizzle.config.ts file. See 'deesse db:generate' for setup.
|
|
32
|
+
`);
|
|
59
33
|
}
|
|
60
34
|
//# sourceMappingURL=db-introspect.js.map
|
|
@@ -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;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOpD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAgC,EAAE;IACnE,+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;;;oBAGK,OAAO;;;;;;;;;CAS1B,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:migrate command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema setup and provides instructions for applying migrations.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 2. Spawn drizzle-kit migrate command
|
|
6
|
+
* For Drizzle, run:
|
|
7
|
+
* npx drizzle-kit migrate
|
|
9
8
|
*/
|
|
10
9
|
export interface DbMigrateOptions {
|
|
11
10
|
cwd?: string;
|
|
12
11
|
dryRun?: boolean;
|
|
13
12
|
}
|
|
14
|
-
export declare function dbMigrate(
|
|
13
|
+
export declare function dbMigrate(_options?: DbMigrateOptions): Promise<void>;
|
|
15
14
|
//# sourceMappingURL=db-migrate.d.ts.map
|
|
@@ -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;;;;;;;GAOG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,SAAS,CAAC,QAAQ,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB9E"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:migrate command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema setup and provides instructions for applying migrations.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 2. Spawn drizzle-kit migrate command
|
|
6
|
+
* For Drizzle, run:
|
|
7
|
+
* npx drizzle-kit migrate
|
|
9
8
|
*/
|
|
10
|
-
import { execSync } from 'node:child_process';
|
|
11
9
|
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
12
|
-
export async function dbMigrate(
|
|
13
|
-
const { cwd = process.cwd(), dryRun = false } = options;
|
|
10
|
+
export async function dbMigrate(_options = {}) {
|
|
14
11
|
// Verify schema file exists
|
|
15
12
|
try {
|
|
16
13
|
await verifySchemaPath();
|
|
@@ -19,23 +16,18 @@ export async function dbMigrate(options = {}) {
|
|
|
19
16
|
throw new Error(`db:migrate requires ${SCHEMA_PATH} to exist.\n` +
|
|
20
17
|
`Please create this file and export your Drizzle tables.`);
|
|
21
18
|
}
|
|
22
|
-
console.warn(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (error.code === 'ENOENT') {
|
|
36
|
-
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
37
|
-
}
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
19
|
+
console.warn(`
|
|
20
|
+
Database Schema OK: ${SCHEMA_PATH}
|
|
21
|
+
|
|
22
|
+
To apply pending migrations with Drizzle, run:
|
|
23
|
+
|
|
24
|
+
npx drizzle-kit migrate
|
|
25
|
+
|
|
26
|
+
Use --dry-run to see what would be applied:
|
|
27
|
+
|
|
28
|
+
npx drizzle-kit migrate --dry
|
|
29
|
+
|
|
30
|
+
Note: This command requires a drizzle.config.ts file. See 'deesse db:generate' for setup.
|
|
31
|
+
`);
|
|
40
32
|
}
|
|
41
33
|
//# 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;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAO1E,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,WAA6B,EAAE;IAC7D,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;sBACO,WAAW;;;;;;;;;;;CAWhC,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:push command
|
|
3
3
|
*
|
|
4
|
-
* Pushes schema changes directly to the database
|
|
4
|
+
* Pushes schema changes directly to the database using drizzle-kit's pushSchema.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
7
|
+
* 1. Load schema from ./src/db/schema.ts
|
|
8
|
+
* 2. Load config to get database instance
|
|
9
|
+
* 3. Call pushSchema with the schema
|
|
10
|
+
* 4. Show warnings and apply
|
|
9
11
|
*/
|
|
10
12
|
export interface DbPushOptions {
|
|
11
13
|
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;;;;;;;;;;GAUG;AAUH,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,CA8DvE"}
|
package/dist/commands/db-push.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:push command
|
|
3
3
|
*
|
|
4
|
-
* Pushes schema changes directly to the database
|
|
4
|
+
* Pushes schema changes directly to the database using drizzle-kit's pushSchema.
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
|
-
* 1.
|
|
8
|
-
* 2.
|
|
7
|
+
* 1. Load schema from ./src/db/schema.ts
|
|
8
|
+
* 2. Load config to get database instance
|
|
9
|
+
* 3. Call pushSchema with the schema
|
|
10
|
+
* 4. Show warnings and apply
|
|
9
11
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
12
|
+
import { createRequire } from 'node:module';
|
|
13
|
+
import { verifySchemaPath, SCHEMA_PATH, loadSchema } from '../utils/schema-loader.js';
|
|
14
|
+
import { loadConfig } from '../utils/config.js';
|
|
15
|
+
import * as p from '@clack/prompts';
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
const { pushSchema } = require('drizzle-kit/api');
|
|
12
18
|
export async function dbPush(options = {}) {
|
|
13
|
-
const { force = false
|
|
19
|
+
const { force = false } = options;
|
|
14
20
|
// Verify schema file exists
|
|
15
21
|
try {
|
|
16
22
|
await verifySchemaPath();
|
|
@@ -19,23 +25,46 @@ export async function dbPush(options = {}) {
|
|
|
19
25
|
throw new Error(`db:push requires ${SCHEMA_PATH} to exist.\n` +
|
|
20
26
|
`Please create this file and export your Drizzle tables.`);
|
|
21
27
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
|
|
28
|
+
// Load config to get database instance
|
|
29
|
+
const { config } = await loadConfig();
|
|
30
|
+
const db = config.database;
|
|
31
|
+
if (!db) {
|
|
32
|
+
throw new Error('Config does not have a database instance');
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
// Load the schema
|
|
35
|
+
const { schema } = await loadSchema();
|
|
36
|
+
// Push schema to database
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const result = await pushSchema(schema, db);
|
|
39
|
+
// Check for data loss
|
|
40
|
+
if (result.hasDataLoss && !force) {
|
|
41
|
+
p.note('The following changes may cause data loss:', 'Warning');
|
|
42
|
+
for (const warning of result.warnings) {
|
|
43
|
+
console.warn(` - ${warning}`);
|
|
44
|
+
}
|
|
45
|
+
console.warn('');
|
|
46
|
+
const confirm = await p.confirm({
|
|
47
|
+
message: 'Do you want to apply these changes anyway?',
|
|
48
|
+
initialValue: false,
|
|
32
49
|
});
|
|
50
|
+
if (p.isCancel(confirm) || !confirm) {
|
|
51
|
+
p.cancel('Push cancelled.');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (result.warnings.length > 0) {
|
|
56
|
+
p.note(result.warnings.join('\n'), 'Warnings');
|
|
33
57
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
// Show statements that will be executed
|
|
59
|
+
if (result.statementsToExecute.length > 0) {
|
|
60
|
+
console.warn('The following SQL will be executed:');
|
|
61
|
+
for (const stmt of result.statementsToExecute) {
|
|
62
|
+
console.warn(` ${stmt}`);
|
|
37
63
|
}
|
|
38
|
-
|
|
64
|
+
console.warn('');
|
|
39
65
|
}
|
|
66
|
+
// Apply the changes
|
|
67
|
+
await result.apply();
|
|
68
|
+
console.warn(`Successfully pushed ${result.statementsToExecute.length} changes to the database.`);
|
|
40
69
|
}
|
|
41
70
|
//# 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;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAEpC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAOlD,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,UAAyB,EAAE;IACtD,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAElC,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,uCAAuC;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,EAAE,CAAC;IACtC,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;IAE3B,IAAI,CAAC,E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,EAAE,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;IAED,oBAAoB;IACpB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IAErB,OAAO,CAAC,IAAI,CAAC,uBAAuB,MAAM,CAAC,mBAAmB,CAAC,MAAM,2BAA2B,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:studio command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema setup and provides instructions for opening Drizzle Studio.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 2. Spawn drizzle-kit studio command with appropriate arguments
|
|
6
|
+
* For Drizzle, run:
|
|
7
|
+
* npx drizzle-kit studio
|
|
9
8
|
*/
|
|
10
9
|
export interface DbStudioOptions {
|
|
11
10
|
port?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-studio.d.ts","sourceRoot":"","sources":["../../src/commands/db-studio.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-studio.d.ts","sourceRoot":"","sources":["../../src/commands/db-studio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C3E"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:studio command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema setup and provides instructions for opening Drizzle Studio.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* 2. Spawn drizzle-kit studio command with appropriate arguments
|
|
6
|
+
* For Drizzle, run:
|
|
7
|
+
* npx drizzle-kit studio
|
|
9
8
|
*/
|
|
10
|
-
import { execSync } from 'node:child_process';
|
|
11
9
|
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
12
10
|
import { detectDialect } from '../utils/dialect.js';
|
|
13
11
|
import { loadConfig } from '../utils/config.js';
|
|
14
12
|
export async function dbStudio(options = {}) {
|
|
15
|
-
const cwd = options.cwd ?? process.cwd();
|
|
16
13
|
const port = options.port ?? parseInt(process.env['DB_STUDIO_PORT'] ?? '4983', 10);
|
|
17
14
|
const host = options.host ?? process.env['DB_STUDIO_HOST'] ?? '127.0.0.1';
|
|
18
15
|
// Verify schema file exists
|
|
@@ -35,38 +32,18 @@ export async function dbStudio(options = {}) {
|
|
|
35
32
|
throw new Error(`Drizzle Studio currently only supports PostgreSQL.\n` +
|
|
36
33
|
`Detected dialect: ${dialect}`);
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
console.warn(`Since we don't use drizzle.config.ts, please either:`);
|
|
52
|
-
console.warn(`1. Create a minimal drizzle.config.ts pointing to your schema`);
|
|
53
|
-
console.warn(`2. Or use 'npx drizzle-kit studio' directly with a config file`);
|
|
54
|
-
console.warn('');
|
|
55
|
-
// Try to spawn drizzle-kit anyway - it might work if user has a config
|
|
56
|
-
try {
|
|
57
|
-
execSync(`npx ${args.join(' ')}`, {
|
|
58
|
-
cwd,
|
|
59
|
-
stdio: 'inherit',
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
if (error.code === 'ENOENT') {
|
|
64
|
-
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
65
|
-
}
|
|
66
|
-
// Drizzle-kit studio might fail if no config - show helpful message
|
|
67
|
-
console.warn('Drizzle Studio requires a drizzle.config.ts file to work.');
|
|
68
|
-
console.warn('For now, please use: npx drizzle-kit studio');
|
|
69
|
-
throw error;
|
|
70
|
-
}
|
|
35
|
+
console.warn(`
|
|
36
|
+
Database Schema OK: ${SCHEMA_PATH}
|
|
37
|
+
|
|
38
|
+
To open Drizzle Studio, run:
|
|
39
|
+
|
|
40
|
+
npx drizzle-kit studio
|
|
41
|
+
|
|
42
|
+
Or with custom host/port:
|
|
43
|
+
|
|
44
|
+
npx drizzle-kit studio --host ${host} --port ${port}
|
|
45
|
+
|
|
46
|
+
Note: Drizzle Studio requires a drizzle.config.ts file. See 'deesse db:generate' for setup.
|
|
47
|
+
`);
|
|
71
48
|
}
|
|
72
49
|
//# sourceMappingURL=db-studio.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-studio.js","sourceRoot":"","sources":["../../src/commands/db-studio.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db-studio.js","sourceRoot":"","sources":["../../src/commands/db-studio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQhD,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,UAA2B,EAAE;IAC1D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC;IACnF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,WAAW,CAAC;IAE1E,4BAA4B;IAC5B,IAAI,CAAC;QACH,MAAM,gBAAgB,EAAE,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,sBAAsB,WAAW,cAAc;YAC/C,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IAED,+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,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,sDAAsD;YACtD,qBAAqB,OAAO,EAAE,CAC/B,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,IAAI,CAAC;sBACO,WAAW;;;;;;;;kCAQC,IAAI,WAAW,IAAI;;;CAGpD,CAAC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deessejs/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "DeesseJS CLI for managing DeesseJS projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"author": "DeesseJS",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@clack/prompts": "^0.8.2"
|
|
27
|
+
"@clack/prompts": "^0.8.2",
|
|
28
|
+
"drizzle-kit": "^0.30.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/node": "^22.10.6",
|