@deessejs/cli 0.5.1 → 0.6.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 +4 -7
- package/dist/commands/db-generate.d.ts.map +1 -1
- package/dist/commands/db-generate.js +31 -45
- package/dist/commands/db-generate.js.map +1 -1
- package/dist/commands/db-push.d.ts +4 -6
- package/dist/commands/db-push.d.ts.map +1 -1
- package/dist/commands/db-push.js +41 -49
- 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
|
-
*
|
|
4
|
+
* Verifies schema and config exist, then delegates to drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
6
|
+
* Requirements:
|
|
7
|
+
* - src/db/schema.ts: Your Drizzle tables
|
|
8
|
+
* - drizzle.config.ts: Standard drizzle-kit config with schema and out settings
|
|
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;AASH,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4C/E"}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:generate command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema and config exist, then delegates to drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
6
|
+
* Requirements:
|
|
7
|
+
* - src/db/schema.ts: Your Drizzle tables
|
|
8
|
+
* - drizzle.config.ts: Standard drizzle-kit config with schema and out settings
|
|
12
9
|
*/
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
11
|
+
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
13
12
|
import * as fs from 'node:fs/promises';
|
|
14
13
|
import * as path from 'node:path';
|
|
15
|
-
|
|
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';
|
|
14
|
+
const DRIZZLE_CONFIG_PATH = './drizzle.config.ts';
|
|
23
15
|
export async function dbGenerate(options = {}) {
|
|
24
16
|
const cwd = options.cwd ?? process.cwd();
|
|
25
17
|
// Verify schema file exists
|
|
@@ -30,40 +22,34 @@ export async function dbGenerate(options = {}) {
|
|
|
30
22
|
throw new Error(`db:generate requires ${SCHEMA_PATH} to exist.\n` +
|
|
31
23
|
`Please create this file and export your Drizzle tables.`);
|
|
32
24
|
}
|
|
33
|
-
//
|
|
34
|
-
|
|
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);
|
|
25
|
+
// Verify drizzle.config.ts exists
|
|
26
|
+
const drizzleConfigPath = path.join(cwd, DRIZZLE_CONFIG_PATH);
|
|
44
27
|
try {
|
|
45
|
-
|
|
46
|
-
prevSchema = JSON.parse(snapshotContent);
|
|
28
|
+
await fs.access(drizzleConfigPath);
|
|
47
29
|
}
|
|
48
30
|
catch {
|
|
49
|
-
|
|
50
|
-
|
|
31
|
+
throw new Error(`db:generate requires ${DRIZZLE_CONFIG_PATH} to exist.\n` +
|
|
32
|
+
`Please create this file with your drizzle-kit configuration.\n\n` +
|
|
33
|
+
`Example:\n` +
|
|
34
|
+
`import { defineConfig } from 'drizzle-kit';\n` +
|
|
35
|
+
`export default defineConfig({\n` +
|
|
36
|
+
` schema: './src/db/schema.ts',\n` +
|
|
37
|
+
` out: './src/db/migrations',\n` +
|
|
38
|
+
` dialect: 'postgresql',\n` +
|
|
39
|
+
`});`);
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
console.warn('Generating migrations with drizzle-kit...');
|
|
42
|
+
try {
|
|
43
|
+
execSync('npx drizzle-kit generate', {
|
|
44
|
+
cwd,
|
|
45
|
+
stdio: 'inherit',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error.code === 'ENOENT') {
|
|
50
|
+
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
57
53
|
}
|
|
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}`);
|
|
68
54
|
}
|
|
69
55
|
//# 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;AAC1E,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAMlD,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,kCAAkC;IAClC,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,wBAAwB,mBAAmB,cAAc;YACzD,kEAAkE;YAClE,YAAY;YACZ,+CAA+C;YAC/C,iCAAiC;YACjC,mCAAmC;YACnC,iCAAiC;YACjC,4BAA4B;YAC5B,KAAK,CACN,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;IAE1D,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,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:push command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema and config exist, then delegates to drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* 3. Call pushSchema with the schema
|
|
10
|
-
* 4. Show warnings and apply
|
|
6
|
+
* Requirements:
|
|
7
|
+
* - src/db/schema.ts: Your Drizzle tables
|
|
8
|
+
* - drizzle.config.ts: Standard drizzle-kit config with schema and dbCredentials
|
|
11
9
|
*/
|
|
12
10
|
export interface DbPushOptions {
|
|
13
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;AASH,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,CAoDvE"}
|
package/dist/commands/db-push.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* db:push command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Verifies schema and config exist, then delegates to drizzle-kit CLI.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* 3. Call pushSchema with the schema
|
|
10
|
-
* 4. Show warnings and apply
|
|
6
|
+
* Requirements:
|
|
7
|
+
* - src/db/schema.ts: Your Drizzle tables
|
|
8
|
+
* - drizzle.config.ts: Standard drizzle-kit config with schema and dbCredentials
|
|
11
9
|
*/
|
|
12
|
-
import {
|
|
13
|
-
import { verifySchemaPath, SCHEMA_PATH
|
|
14
|
-
import
|
|
15
|
-
import * as
|
|
16
|
-
const
|
|
17
|
-
const { pushSchema } = require('drizzle-kit/api');
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
11
|
+
import { verifySchemaPath, SCHEMA_PATH } from '../utils/schema-loader.js';
|
|
12
|
+
import * as fs from 'node:fs/promises';
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
const DRIZZLE_CONFIG_PATH = './drizzle.config.ts';
|
|
18
15
|
export async function dbPush(options = {}) {
|
|
19
|
-
const { force = false } = options;
|
|
16
|
+
const { force = false, cwd = process.cwd() } = options;
|
|
20
17
|
// Verify schema file exists
|
|
21
18
|
try {
|
|
22
19
|
await verifySchemaPath();
|
|
@@ -25,46 +22,41 @@ export async function dbPush(options = {}) {
|
|
|
25
22
|
throw new Error(`db:push requires ${SCHEMA_PATH} to exist.\n` +
|
|
26
23
|
`Please create this file and export your Drizzle tables.`);
|
|
27
24
|
}
|
|
28
|
-
//
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
throw new Error('Config does not have a database instance');
|
|
25
|
+
// Verify drizzle.config.ts exists
|
|
26
|
+
const drizzleConfigPath = path.join(cwd, DRIZZLE_CONFIG_PATH);
|
|
27
|
+
try {
|
|
28
|
+
await fs.access(drizzleConfigPath);
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
p.cancel('Push cancelled.');
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new Error(`db:push requires ${DRIZZLE_CONFIG_PATH} to exist.\n` +
|
|
32
|
+
`Please create this file with your drizzle-kit configuration.\n\n` +
|
|
33
|
+
`Example:\n` +
|
|
34
|
+
`import { defineConfig } from 'drizzle-kit';\n` +
|
|
35
|
+
`export default defineConfig({\n` +
|
|
36
|
+
` schema: './src/db/schema.ts',\n` +
|
|
37
|
+
` dialect: 'postgresql',\n` +
|
|
38
|
+
` dbCredentials: {\n` +
|
|
39
|
+
` url: process.env.DATABASE_URL,\n` +
|
|
40
|
+
` },\n` +
|
|
41
|
+
`});`);
|
|
42
|
+
}
|
|
43
|
+
console.warn('Pushing schema to database with drizzle-kit...');
|
|
44
|
+
const args = ['npx drizzle-kit', 'push'];
|
|
45
|
+
if (force) {
|
|
46
|
+
args.push('--force');
|
|
54
47
|
}
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
try {
|
|
49
|
+
execSync(args.join(' '), {
|
|
50
|
+
cwd,
|
|
51
|
+
stdio: 'inherit',
|
|
52
|
+
env: process.env,
|
|
53
|
+
});
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
for (const stmt of result.statementsToExecute) {
|
|
62
|
-
console.warn(` ${stmt}`);
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === 'ENOENT') {
|
|
57
|
+
throw new Error('drizzle-kit not found. Please install it: npm install drizzle-kit');
|
|
63
58
|
}
|
|
64
|
-
|
|
59
|
+
throw error;
|
|
65
60
|
}
|
|
66
|
-
// Apply the changes
|
|
67
|
-
await result.apply();
|
|
68
|
-
console.warn(`Successfully pushed ${result.statementsToExecute.length} changes to the database.`);
|
|
69
61
|
}
|
|
70
62
|
//# 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;AAC1E,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAOlD,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,M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": "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",
|