d1-kyt 0.4.6 → 0.5.2
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/README.md +208 -131
- package/dist/cli.js +182 -224
- package/dist/cli.js.map +1 -1
- package/dist/migrate.d.ts +2 -3
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +4 -5
- package/dist/migrate.js.map +1 -1
- package/dist/schema-diff.d.ts +85 -0
- package/dist/schema-diff.d.ts.map +1 -0
- package/dist/schema-diff.js +346 -0
- package/dist/schema-diff.js.map +1 -0
- package/dist/schema.d.ts +128 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +148 -0
- package/dist/schema.js.map +1 -0
- package/package.json +9 -6
package/dist/cli.js
CHANGED
|
@@ -1,59 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { join, resolve } from 'node:path';
|
|
4
|
-
|
|
5
|
-
const VERSION = '0.4.3';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
const VERSION = '0.5.2';
|
|
6
5
|
const HELP = `
|
|
7
6
|
d1-kyt v${VERSION} - Opinionated Cloudflare D1 + Kysely toolkit
|
|
8
7
|
|
|
9
8
|
Usage:
|
|
10
|
-
d1-kyt init
|
|
11
|
-
d1-kyt
|
|
12
|
-
d1-kyt migrate:build
|
|
13
|
-
d1-kyt typegen
|
|
9
|
+
d1-kyt init [--dir <dir>]
|
|
10
|
+
d1-kyt schema:diff <name> [--dir <dir>] [--schema <path>]
|
|
14
11
|
|
|
15
12
|
Commands:
|
|
16
|
-
init
|
|
17
|
-
|
|
18
|
-
migrate:build Compile .ts migrations to .sql
|
|
19
|
-
typegen Generate TypeScript types (wraps kysely-codegen)
|
|
13
|
+
init Scaffold config, schema template, and snapshot in <dir>
|
|
14
|
+
schema:diff Diff schema against snapshot → generate .sql migration
|
|
20
15
|
|
|
21
16
|
Options:
|
|
17
|
+
--dir <path> Directory for config/schema/snapshot (default: auto-detected
|
|
18
|
+
from wrangler migrations_dir parent, or "db/")
|
|
19
|
+
--schema <path> Override schema file path (default: <dir>/schema.ts)
|
|
22
20
|
--help, -h Show this help message
|
|
23
21
|
--version, -v Show version
|
|
24
22
|
|
|
25
23
|
Examples:
|
|
26
|
-
d1-kyt init
|
|
27
|
-
d1-kyt
|
|
28
|
-
d1-kyt
|
|
29
|
-
d1-kyt
|
|
24
|
+
d1-kyt init # auto-detect dir (db/ by default)
|
|
25
|
+
d1-kyt init --dir db # use db/config.ts, db/schema.ts, db/schema.snapshot.jsonc
|
|
26
|
+
d1-kyt schema:diff create_users
|
|
27
|
+
d1-kyt schema:diff add_idx --schema src/schema.ts
|
|
30
28
|
`;
|
|
31
29
|
import { generateMigrationPrefix } from './naming.js';
|
|
32
|
-
import {
|
|
33
|
-
// ----------------------------------------------------------------------------
|
|
34
|
-
// Config Helpers
|
|
35
|
-
// ----------------------------------------------------------------------------
|
|
36
|
-
const D1_KYT_DIR = 'd1-kyt';
|
|
37
|
-
const CONFIG_FILE = 'config.ts';
|
|
38
|
-
const KYSELY_CONFIG_FILE = 'kysely-codegen.json';
|
|
39
|
-
function getConfigPath() {
|
|
40
|
-
return resolve(process.cwd(), D1_KYT_DIR, CONFIG_FILE);
|
|
41
|
-
}
|
|
42
|
-
function getKyselyConfigPath() {
|
|
43
|
-
return resolve(process.cwd(), D1_KYT_DIR, KYSELY_CONFIG_FILE);
|
|
44
|
-
}
|
|
45
|
-
async function readD1KytConfig() {
|
|
46
|
-
const configPath = getConfigPath();
|
|
47
|
-
if (!existsSync(configPath))
|
|
48
|
-
return null;
|
|
49
|
-
try {
|
|
50
|
-
const module = await import(configPath);
|
|
51
|
-
return module.default ?? module.config;
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
30
|
+
import { serializeSchema, diffSnapshots, diffToSQL } from './schema-diff.js';
|
|
57
31
|
function readWranglerConfig() {
|
|
58
32
|
const wranglerPaths = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
|
|
59
33
|
for (const filename of wranglerPaths) {
|
|
@@ -63,229 +37,219 @@ function readWranglerConfig() {
|
|
|
63
37
|
if (filename.endsWith('.toml')) {
|
|
64
38
|
const content = readFileSync(filepath, 'utf-8');
|
|
65
39
|
const match = content.match(/migrations_dir\s*=\s*"([^"]+)"/);
|
|
66
|
-
if (match)
|
|
40
|
+
if (match)
|
|
67
41
|
return { migrationsDir: match[1] };
|
|
68
|
-
}
|
|
69
42
|
}
|
|
70
43
|
else {
|
|
71
44
|
const content = readFileSync(filepath, 'utf-8')
|
|
72
45
|
.replace(/\/\/.*$/gm, '')
|
|
73
46
|
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
74
47
|
try {
|
|
75
|
-
const
|
|
76
|
-
const d1 =
|
|
77
|
-
if (d1?.migrations_dir)
|
|
48
|
+
const cfg = JSON.parse(content);
|
|
49
|
+
const d1 = cfg.d1_databases?.[0];
|
|
50
|
+
if (d1?.migrations_dir)
|
|
78
51
|
return { migrationsDir: d1.migrations_dir };
|
|
79
|
-
}
|
|
80
52
|
}
|
|
81
53
|
catch {
|
|
82
|
-
//
|
|
54
|
+
// ignore
|
|
83
55
|
}
|
|
84
56
|
}
|
|
85
57
|
}
|
|
86
58
|
return null;
|
|
87
59
|
}
|
|
88
60
|
// ----------------------------------------------------------------------------
|
|
61
|
+
// Dir resolution
|
|
62
|
+
//
|
|
63
|
+
// The "dir" is the single folder that holds config.ts, schema.ts, and
|
|
64
|
+
// schema.snapshot.jsonc. Resolution order:
|
|
65
|
+
// 1. --dir <path> flag (explicit)
|
|
66
|
+
// 2. Auto-detect an existing config: first d1-kyt/, then parent of
|
|
67
|
+
// wrangler migrationsDir (if it is not the project root)
|
|
68
|
+
// 3. Derive a sensible default for init: parent of wrangler migrationsDir
|
|
69
|
+
// (if it has a real parent), otherwise "d1-kyt"
|
|
70
|
+
// ----------------------------------------------------------------------------
|
|
71
|
+
const CONFIG_FILE = 'config.ts';
|
|
72
|
+
const SCHEMA_FILE = 'schema.ts';
|
|
73
|
+
const SNAPSHOT_FILE = 'schema.snapshot.jsonc';
|
|
74
|
+
/** Return the absolute path to <dir>/config.ts, or null if no config found. */
|
|
75
|
+
function findExistingDir(dirFlag) {
|
|
76
|
+
if (dirFlag) {
|
|
77
|
+
const abs = resolve(process.cwd(), dirFlag);
|
|
78
|
+
return existsSync(join(abs, CONFIG_FILE)) ? abs : null;
|
|
79
|
+
}
|
|
80
|
+
// 1. db/config.ts (default)
|
|
81
|
+
const defaultDir = resolve(process.cwd(), 'db');
|
|
82
|
+
if (existsSync(join(defaultDir, CONFIG_FILE)))
|
|
83
|
+
return defaultDir;
|
|
84
|
+
// 2. Legacy d1-kyt/config.ts
|
|
85
|
+
const legacy = resolve(process.cwd(), 'd1-kyt');
|
|
86
|
+
if (existsSync(join(legacy, CONFIG_FILE)))
|
|
87
|
+
return legacy;
|
|
88
|
+
// 3. Parent of wrangler migrations dir (e.g. src/ for src/migrations/)
|
|
89
|
+
const wrangler = readWranglerConfig();
|
|
90
|
+
if (wrangler) {
|
|
91
|
+
const parent = dirname(wrangler.migrationsDir);
|
|
92
|
+
if (parent !== '.') {
|
|
93
|
+
const abs = resolve(process.cwd(), parent);
|
|
94
|
+
if (existsSync(join(abs, CONFIG_FILE)))
|
|
95
|
+
return abs;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/** Pick the dir to use for init (before config exists). */
|
|
101
|
+
function defaultInitDir(dirFlag) {
|
|
102
|
+
if (dirFlag)
|
|
103
|
+
return resolve(process.cwd(), dirFlag);
|
|
104
|
+
const wrangler = readWranglerConfig();
|
|
105
|
+
if (wrangler) {
|
|
106
|
+
const parent = dirname(wrangler.migrationsDir);
|
|
107
|
+
if (parent !== '.')
|
|
108
|
+
return resolve(process.cwd(), parent);
|
|
109
|
+
}
|
|
110
|
+
return resolve(process.cwd(), 'db');
|
|
111
|
+
}
|
|
112
|
+
async function readD1KytConfig(dir) {
|
|
113
|
+
const configPath = join(dir, CONFIG_FILE);
|
|
114
|
+
if (!existsSync(configPath))
|
|
115
|
+
return null;
|
|
116
|
+
try {
|
|
117
|
+
const mod = await import(configPath);
|
|
118
|
+
return mod.default ?? mod.config;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// ----------------------------------------------------------------------------
|
|
89
125
|
// Commands
|
|
90
126
|
// ----------------------------------------------------------------------------
|
|
91
|
-
function cmdInit() {
|
|
127
|
+
function cmdInit(dirFlag) {
|
|
128
|
+
const dir = defaultInitDir(dirFlag);
|
|
129
|
+
const relDir = dir.replace(process.cwd() + '/', '');
|
|
92
130
|
const wrangler = readWranglerConfig();
|
|
93
131
|
const migrationsDir = wrangler?.migrationsDir ?? 'db/migrations';
|
|
94
132
|
if (wrangler) {
|
|
95
133
|
console.log(`Detected wrangler migrations_dir: ${migrationsDir}`);
|
|
96
134
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
mkdirSync(d1KytDir, { recursive: true });
|
|
101
|
-
console.log(`Created: ${D1_KYT_DIR}/`);
|
|
102
|
-
}
|
|
103
|
-
// Create d1-kyt/migrations
|
|
104
|
-
const srcMigrationsDir = join(d1KytDir, 'migrations');
|
|
105
|
-
if (!existsSync(srcMigrationsDir)) {
|
|
106
|
-
mkdirSync(srcMigrationsDir, { recursive: true });
|
|
107
|
-
console.log(`Created: ${D1_KYT_DIR}/migrations/`);
|
|
135
|
+
if (!existsSync(dir)) {
|
|
136
|
+
mkdirSync(dir, { recursive: true });
|
|
137
|
+
console.log(`Created: ${relDir}/`);
|
|
108
138
|
}
|
|
109
|
-
//
|
|
110
|
-
const configPath =
|
|
139
|
+
// config.ts
|
|
140
|
+
const configPath = join(dir, CONFIG_FILE);
|
|
111
141
|
if (!existsSync(configPath)) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
export default defineConfig({
|
|
115
|
-
migrationsDir: '${migrationsDir}',
|
|
116
|
-
namingStrategy: 'sequential',
|
|
117
|
-
});
|
|
118
|
-
`;
|
|
119
|
-
writeFileSync(configPath, configTemplate);
|
|
120
|
-
console.log(`Created: ${D1_KYT_DIR}/${CONFIG_FILE}`);
|
|
142
|
+
writeFileSync(configPath, `import { defineConfig } from 'd1-kyt/config';\n\nexport default defineConfig({\n migrationsDir: '${migrationsDir}',\n namingStrategy: 'sequential',\n});\n`);
|
|
143
|
+
console.log(`Created: ${relDir}/${CONFIG_FILE}`);
|
|
121
144
|
}
|
|
122
145
|
else {
|
|
123
|
-
console.log(`Skipped: ${
|
|
146
|
+
console.log(`Skipped: ${relDir}/${CONFIG_FILE} (already exists)`);
|
|
124
147
|
}
|
|
125
|
-
//
|
|
126
|
-
const
|
|
127
|
-
if (!existsSync(
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
excludePattern: '(_cf_|d1_)*',
|
|
131
|
-
outFile: 'generated.ts',
|
|
132
|
-
camelCase: true,
|
|
133
|
-
};
|
|
134
|
-
writeFileSync(kyselyConfigPath, JSON.stringify(kyselyConfig, null, 2) + '\n');
|
|
135
|
-
console.log(`Created: ${D1_KYT_DIR}/${KYSELY_CONFIG_FILE}`);
|
|
148
|
+
// schema.ts
|
|
149
|
+
const schemaPath = join(dir, SCHEMA_FILE);
|
|
150
|
+
if (!existsSync(schemaPath)) {
|
|
151
|
+
writeFileSync(schemaPath, `import { defineTable, defineIndex } from 'd1-kyt/schema';\nimport { createQueryBuilder } from 'd1-kyt';\nimport * as v from 'valibot';\n\n// Define your tables here, then run: d1-kyt schema:diff <name>\n//\n// export const users = defineTable('users', {\n// email: v.string(), // TEXT NOT NULL\n// name: v.optional(v.string()), // TEXT (nullable)\n// age: v.optional(v.pipe(v.number(), v.integer())), // INTEGER (nullable)\n// prefs: v.optional(v.object({ theme: v.string() })), // TEXT JSON (nullable)\n// });\n//\n// export const usersEmailIdx = defineIndex(users, ['email'], { unique: true });\n\n// Add each table to DB, then use \`db\` for type-safe query building.\nexport type DB = {\n // users: typeof users.$inferSelect;\n};\n\nexport const db = createQueryBuilder<DB>();\n`);
|
|
152
|
+
console.log(`Created: ${relDir}/${SCHEMA_FILE}`);
|
|
136
153
|
}
|
|
137
154
|
else {
|
|
138
|
-
console.log(`Skipped: ${
|
|
155
|
+
console.log(`Skipped: ${relDir}/${SCHEMA_FILE} (already exists)`);
|
|
139
156
|
}
|
|
140
|
-
//
|
|
141
|
-
const
|
|
142
|
-
if (!existsSync(
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
export const useTable = createUseTable<DB>();
|
|
147
|
-
`;
|
|
148
|
-
writeFileSync(indexPath, template);
|
|
149
|
-
console.log(`Created: ${D1_KYT_DIR}/index.ts`);
|
|
157
|
+
// schema.snapshot.jsonc
|
|
158
|
+
const snapshotPath = join(dir, SNAPSHOT_FILE);
|
|
159
|
+
if (!existsSync(snapshotPath)) {
|
|
160
|
+
const empty = { version: 1, tables: {} };
|
|
161
|
+
writeFileSync(snapshotPath, JSON.stringify(empty, null, 2) + '\n');
|
|
162
|
+
console.log(`Created: ${relDir}/${SNAPSHOT_FILE}`);
|
|
150
163
|
}
|
|
151
164
|
else {
|
|
152
|
-
console.log(`Skipped: ${
|
|
165
|
+
console.log(`Skipped: ${relDir}/${SNAPSHOT_FILE} (already exists)`);
|
|
153
166
|
}
|
|
154
167
|
console.log(`\nNext steps:`);
|
|
155
|
-
console.log(` 1.
|
|
156
|
-
console.log(` 2.
|
|
157
|
-
console.log(` 3. Apply
|
|
158
|
-
console.log(` 4. Generate types: d1-kyt typegen`);
|
|
168
|
+
console.log(` 1. Edit: ${relDir}/${SCHEMA_FILE}`);
|
|
169
|
+
console.log(` 2. Diff: d1-kyt schema:diff <name>`);
|
|
170
|
+
console.log(` 3. Apply: wrangler d1 migrations apply <db> --local`);
|
|
159
171
|
}
|
|
160
|
-
async function
|
|
161
|
-
const
|
|
162
|
-
if (!
|
|
172
|
+
async function cmdSchemaDiff(name, dirFlag, schemaFlag) {
|
|
173
|
+
const dir = findExistingDir(dirFlag);
|
|
174
|
+
if (!dir) {
|
|
163
175
|
console.error('Error: d1-kyt not initialized. Run "d1-kyt init" first.');
|
|
176
|
+
if (dirFlag)
|
|
177
|
+
console.error(` (looked in: ${dirFlag})`);
|
|
164
178
|
process.exit(1);
|
|
165
179
|
}
|
|
166
|
-
const
|
|
167
|
-
const outDir = resolve(process.cwd(), config.migrationsDir);
|
|
168
|
-
const strategy = config.namingStrategy ?? 'sequential';
|
|
169
|
-
// Collect existing files for sequential numbering
|
|
170
|
-
const existingSql = existsSync(outDir) ? readdirSync(outDir) : [];
|
|
171
|
-
const existingTs = existsSync(srcDir) ? readdirSync(srcDir) : [];
|
|
172
|
-
const existingFiles = [...existingSql, ...existingTs];
|
|
173
|
-
const prefix = generateMigrationPrefix(strategy, existingFiles);
|
|
174
|
-
const snakeName = name
|
|
175
|
-
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
176
|
-
.replace(/[\s-]+/g, '_')
|
|
177
|
-
.toLowerCase();
|
|
178
|
-
const filename = `${prefix}_${snakeName}.ts`;
|
|
179
|
-
const filepath = join(srcDir, filename);
|
|
180
|
-
const template = `import { defineTable, createIndex } from 'd1-kyt/migrate';
|
|
181
|
-
|
|
182
|
-
// Migration: ${snakeName}
|
|
183
|
-
// Created: ${new Date().toISOString().split('T')[0]}
|
|
184
|
-
|
|
185
|
-
export const migration = () => {
|
|
186
|
-
// Example:
|
|
187
|
-
// const User = defineTable('User', (col) => ({
|
|
188
|
-
// email: col.text().notNull(),
|
|
189
|
-
// name: col.text(),
|
|
190
|
-
// }));
|
|
191
|
-
//
|
|
192
|
-
// return [
|
|
193
|
-
// ...User.sql,
|
|
194
|
-
// createIndex(User, ['email'], { unique: true }),
|
|
195
|
-
// ];
|
|
196
|
-
|
|
197
|
-
return [];
|
|
198
|
-
};
|
|
199
|
-
`;
|
|
200
|
-
writeFileSync(filepath, template);
|
|
201
|
-
console.log(`Created: ${D1_KYT_DIR}/migrations/${filename}`);
|
|
202
|
-
console.log(`\nEdit the file, then run: d1-kyt migrate:build`);
|
|
203
|
-
}
|
|
204
|
-
async function cmdMigrateBuild() {
|
|
205
|
-
const config = await readD1KytConfig();
|
|
180
|
+
const config = await readD1KytConfig(dir);
|
|
206
181
|
if (!config) {
|
|
207
|
-
console.error(
|
|
182
|
+
console.error(`Error: Could not load config from ${join(dir, CONFIG_FILE)}`);
|
|
208
183
|
process.exit(1);
|
|
209
184
|
}
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
185
|
+
// Resolve schema file path
|
|
186
|
+
const schemaPath = schemaFlag
|
|
187
|
+
? resolve(process.cwd(), schemaFlag)
|
|
188
|
+
: join(dir, SCHEMA_FILE);
|
|
189
|
+
if (!existsSync(schemaPath)) {
|
|
190
|
+
console.error(`Error: Schema file not found: ${schemaPath}`);
|
|
191
|
+
process.exit(1);
|
|
214
192
|
}
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
193
|
+
// Load schema module
|
|
194
|
+
let schemaExports;
|
|
195
|
+
try {
|
|
196
|
+
schemaExports = await import(schemaPath);
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
console.error(`Error loading schema from ${schemaPath}:`, err);
|
|
200
|
+
process.exit(1);
|
|
222
201
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const tsPath = join(srcDir, tsFile);
|
|
202
|
+
// Serialize → diff → SQL
|
|
203
|
+
const currentSnapshot = serializeSchema(schemaExports);
|
|
204
|
+
const snapshotPath = join(dir, SNAPSHOT_FILE);
|
|
205
|
+
let prevSnapshot = { version: 1, tables: {} };
|
|
206
|
+
if (existsSync(snapshotPath)) {
|
|
229
207
|
try {
|
|
230
|
-
//
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
continue;
|
|
236
|
-
if (statements.length === 0) {
|
|
237
|
-
console.log(`Skipped: ${tsFile} (empty migration)`);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
const sql = `-- Generated by d1-kyt from ${tsFile}\n-- ${new Date().toISOString()}\n\n${statements.join('\n\n')}\n`;
|
|
241
|
-
writeFileSync(sqlPath, sql);
|
|
242
|
-
console.log(`Built: ${config.migrationsDir}/${sqlFile}`);
|
|
243
|
-
built++;
|
|
244
|
-
}
|
|
245
|
-
catch (err) {
|
|
246
|
-
console.error(`Error building ${tsFile}:`, err);
|
|
247
|
-
process.exit(1);
|
|
208
|
+
// Strip JSONC-style comments before parsing
|
|
209
|
+
const raw = readFileSync(snapshotPath, 'utf-8')
|
|
210
|
+
.replace(/\/\/.*$/gm, '')
|
|
211
|
+
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
212
|
+
prevSnapshot = JSON.parse(raw);
|
|
248
213
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const overrides = getJsonColumnOverrides();
|
|
252
|
-
if (Object.keys(overrides).length > 0) {
|
|
253
|
-
const kyselyConfigPath = getKyselyConfigPath();
|
|
254
|
-
if (existsSync(kyselyConfigPath)) {
|
|
255
|
-
const kyselyConfig = JSON.parse(readFileSync(kyselyConfigPath, 'utf-8'));
|
|
256
|
-
const existing = kyselyConfig.overrides?.columns ?? {};
|
|
257
|
-
const merged = { ...existing };
|
|
258
|
-
for (const [key, val] of Object.entries(overrides)) {
|
|
259
|
-
if (!(key in merged))
|
|
260
|
-
merged[key] = val;
|
|
261
|
-
}
|
|
262
|
-
kyselyConfig.overrides = { ...kyselyConfig.overrides, columns: merged };
|
|
263
|
-
writeFileSync(kyselyConfigPath, JSON.stringify(kyselyConfig, null, 2) + '\n');
|
|
214
|
+
catch {
|
|
215
|
+
console.warn(`Warning: Could not parse ${SNAPSHOT_FILE}; treating as empty.`);
|
|
264
216
|
}
|
|
265
217
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
218
|
+
const diff = diffSnapshots(prevSnapshot, currentSnapshot);
|
|
219
|
+
const statements = diffToSQL(diff);
|
|
220
|
+
if (statements.length === 0) {
|
|
221
|
+
console.log('Schema is up to date.');
|
|
222
|
+
return;
|
|
271
223
|
}
|
|
224
|
+
// Write migration file
|
|
225
|
+
const outDir = resolve(process.cwd(), config.migrationsDir);
|
|
226
|
+
if (!existsSync(outDir))
|
|
227
|
+
mkdirSync(outDir, { recursive: true });
|
|
228
|
+
const existingFiles = readdirSync(outDir);
|
|
229
|
+
const strategy = config.namingStrategy ?? 'sequential';
|
|
230
|
+
const prefix = generateMigrationPrefix(strategy, existingFiles);
|
|
231
|
+
const snakeName = name
|
|
232
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
233
|
+
.replace(/[\s-]+/g, '_')
|
|
234
|
+
.toLowerCase();
|
|
235
|
+
const filename = `${prefix}_${snakeName}.sql`;
|
|
236
|
+
const sql = `-- Generated by d1-kyt schema:diff\n` +
|
|
237
|
+
`-- ${new Date().toISOString()}\n\n` +
|
|
238
|
+
`${statements.join('\n\n')}\n`;
|
|
239
|
+
writeFileSync(join(outDir, filename), sql);
|
|
240
|
+
console.log(`Created: ${config.migrationsDir}/${filename}`);
|
|
241
|
+
// Update snapshot
|
|
242
|
+
writeFileSync(snapshotPath, JSON.stringify(currentSnapshot, null, 2) + '\n');
|
|
243
|
+
const relDir = dir.replace(process.cwd() + '/', '');
|
|
244
|
+
console.log(`Updated: ${relDir}/${SNAPSHOT_FILE}`);
|
|
245
|
+
console.log(`\nRun: wrangler d1 migrations apply <db> --local`);
|
|
272
246
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
console.log('Running kysely-codegen...');
|
|
280
|
-
try {
|
|
281
|
-
execSync(`npx kysely-codegen --config-file "${kyselyConfigPath}"`, {
|
|
282
|
-
stdio: 'inherit',
|
|
283
|
-
cwd: process.cwd(),
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
catch {
|
|
287
|
-
process.exit(1);
|
|
288
|
-
}
|
|
247
|
+
// ----------------------------------------------------------------------------
|
|
248
|
+
// Arg helpers
|
|
249
|
+
// ----------------------------------------------------------------------------
|
|
250
|
+
function flagValue(args, flag) {
|
|
251
|
+
const idx = args.indexOf(flag);
|
|
252
|
+
return idx !== -1 ? args[idx + 1] : undefined;
|
|
289
253
|
}
|
|
290
254
|
// ----------------------------------------------------------------------------
|
|
291
255
|
// Main
|
|
@@ -303,24 +267,18 @@ async function main() {
|
|
|
303
267
|
}
|
|
304
268
|
switch (command) {
|
|
305
269
|
case 'init':
|
|
306
|
-
cmdInit();
|
|
270
|
+
cmdInit(flagValue(args, '--dir'));
|
|
307
271
|
break;
|
|
308
|
-
case '
|
|
272
|
+
case 'schema:diff': {
|
|
309
273
|
const name = args[1];
|
|
310
|
-
if (!name) {
|
|
274
|
+
if (!name || name.startsWith('--')) {
|
|
311
275
|
console.error('Error: Migration name required');
|
|
312
|
-
console.error('Usage: d1-kyt
|
|
276
|
+
console.error('Usage: d1-kyt schema:diff <name> [--dir <dir>] [--schema <path>]');
|
|
313
277
|
process.exit(1);
|
|
314
278
|
}
|
|
315
|
-
await
|
|
279
|
+
await cmdSchemaDiff(name, flagValue(args, '--dir'), flagValue(args, '--schema'));
|
|
316
280
|
break;
|
|
317
281
|
}
|
|
318
|
-
case 'migrate:build':
|
|
319
|
-
await cmdMigrateBuild();
|
|
320
|
-
break;
|
|
321
|
-
case 'typegen':
|
|
322
|
-
cmdTypegen();
|
|
323
|
-
break;
|
|
324
282
|
default:
|
|
325
283
|
console.error(`Unknown command: ${command}`);
|
|
326
284
|
console.log(HELP);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,MAAM,IAAI,GAAG;UACH,OAAO;;;;;;;;;;;;;;;;;;;;;;CAsBhB,CAAC;AAGF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAW7E,SAAS,kBAAkB;IACzB,MAAM,aAAa,GAAG,CAAC,gBAAgB,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;IAE3E,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YAAE,SAAS;QAEpC,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAChD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;YAC9D,IAAI,KAAK;gBAAE,OAAO,EAA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QACR,CAAC;QAED;YACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/migrate.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ interface ColumnDefInternal {
|
|
|
8
8
|
isNotNull: boolean;
|
|
9
9
|
defaultValue: string | number | null;
|
|
10
10
|
isJson: boolean;
|
|
11
|
-
jsonOverrideType?: string;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
13
|
* Returns a record of "Table.column" → "unknown" for all json() columns
|
|
@@ -35,8 +34,8 @@ export interface ColumnBuilder {
|
|
|
35
34
|
integer(): ColumnDef<number>;
|
|
36
35
|
real(): ColumnDef<number>;
|
|
37
36
|
blob(): ColumnDef<string>;
|
|
38
|
-
/** JSON stored as TEXT.
|
|
39
|
-
json<T = unknown>(
|
|
37
|
+
/** JSON stored as TEXT. Type parameter carries the shape; kysely-codegen override is set automatically. */
|
|
38
|
+
json<T = unknown>(): ColumnDef<T>;
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
41
|
* Options for auto-generated columns in defineTable.
|
package/dist/migrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,KAAK,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvD,UAAU,iBAAiB;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot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