peta-migrate 0.1.1 → 0.2.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.
@@ -0,0 +1,550 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { Migrator } from "kysely/migration";
5
+ //#region src/checksum.ts
6
+ /**
7
+ * Compute SHA-256 hex digest of a file's content.
8
+ */
9
+ function computeChecksum(filePath) {
10
+ const content = readFileSync(filePath, "utf-8");
11
+ return createHash("sha256").update(content).digest("hex");
12
+ }
13
+ /**
14
+ * Load the checksum store from the migrations directory.
15
+ */
16
+ function loadChecksums(migrationsDir) {
17
+ const filePath = resolve(migrationsDir, ".checksums.json");
18
+ if (!existsSync(filePath)) return {};
19
+ try {
20
+ return JSON.parse(readFileSync(filePath, "utf-8"));
21
+ } catch {
22
+ return {};
23
+ }
24
+ }
25
+ /**
26
+ * Save checksums to the migrations directory.
27
+ */
28
+ function saveChecksums(migrationsDir, store) {
29
+ writeFileSync(resolve(migrationsDir, ".checksums.json"), JSON.stringify(store, null, 2));
30
+ }
31
+ /**
32
+ * Verify a migration file's checksum against the stored value.
33
+ * Returns true if match or no stored checksum exists.
34
+ */
35
+ function verifyChecksum(migrationsDir, name, filePath) {
36
+ const stored = loadChecksums(migrationsDir)[name];
37
+ if (!stored) return true;
38
+ return stored === computeChecksum(filePath);
39
+ }
40
+ //#endregion
41
+ //#region src/config.ts
42
+ function defineConfig(config) {
43
+ return config;
44
+ }
45
+ async function loadConfig() {
46
+ const candidates = [
47
+ "peta.config.ts",
48
+ "peta.config.js",
49
+ "peta.config.mjs"
50
+ ];
51
+ let mod = null;
52
+ for (const file of candidates) try {
53
+ mod = await import(resolve(process.cwd(), file));
54
+ break;
55
+ } catch {}
56
+ if (!mod) throw new Error("No peta.config.ts found. Create one in your project root.");
57
+ const config = mod.default ?? mod;
58
+ return {
59
+ migrationsDir: config.migrationsDir,
60
+ models: config.models,
61
+ getKysely: config.getKysely
62
+ };
63
+ }
64
+ async function loadMigrationFiles(dir) {
65
+ const { readdirSync } = await import("node:fs");
66
+ const files = readdirSync(dir).filter((f) => f.endsWith(".ts") || f.endsWith(".js")).sort();
67
+ const migrations = [];
68
+ for (const file of files) {
69
+ const mod = await import(resolve(dir, file));
70
+ if (mod.up) migrations.push({
71
+ name: file.replace(/\.(ts|js)$/, ""),
72
+ up: mod.up,
73
+ down: mod.down ?? (async () => {})
74
+ });
75
+ }
76
+ return migrations;
77
+ }
78
+ /**
79
+ * Load model definitions from glob patterns.
80
+ * Dynamically imports each matched file and collects ModelDefinition exports.
81
+ * Models are keyed by their `.name` property.
82
+ */
83
+ async function loadModels(patterns) {
84
+ const modelMap = /* @__PURE__ */ new Map();
85
+ const patternList = Array.isArray(patterns) ? patterns : [patterns];
86
+ const cwd = process.cwd();
87
+ for (const raw of patternList) {
88
+ let pattern = raw;
89
+ if (!pattern.startsWith("/")) pattern = resolve(cwd, pattern);
90
+ const glob = new Bun.Glob(pattern);
91
+ const files = Array.from(glob.scanSync(cwd));
92
+ for (const file of files) {
93
+ const fullPath = resolve(cwd, file);
94
+ try {
95
+ const mod = await import(fullPath);
96
+ for (const value of Object.values(mod)) if (isModelDefinition(value)) {
97
+ if (!modelMap.has(value.name)) modelMap.set(value.name, value);
98
+ }
99
+ } catch (err) {
100
+ console.warn(`⚠ Failed to load model file "${fullPath}":`, err.message);
101
+ }
102
+ }
103
+ }
104
+ return modelMap;
105
+ }
106
+ function isModelDefinition(value) {
107
+ if (value === null || value === void 0) return false;
108
+ const obj = value;
109
+ return typeof obj.table === "string" && obj.columns !== void 0 && typeof obj.columns === "object";
110
+ }
111
+ //#endregion
112
+ //#region src/differ.ts
113
+ /**
114
+ * Compare two SchemaSnapshots and produce a list of SchemaDiff operations.
115
+ * Compares `prev` (old) vs `next` (new) to generate a migration plan.
116
+ */
117
+ function diffSnapshots(prev, next) {
118
+ const diffs = [];
119
+ const prevTables = new Map(prev.tables.map((t) => [t.name, t]));
120
+ const nextTables = new Map(next.tables.map((t) => [t.name, t]));
121
+ for (const [name] of prevTables) if (!nextTables.has(name)) diffs.push({
122
+ type: "dropTable",
123
+ table: name
124
+ });
125
+ for (const [name, table] of nextTables) if (!prevTables.has(name)) diffs.push({
126
+ type: "createTable",
127
+ table: name,
128
+ details: {
129
+ columns: table.columns,
130
+ indexes: table.indexes
131
+ }
132
+ });
133
+ for (const [name, nextTable] of nextTables) {
134
+ const prevTable = prevTables.get(name);
135
+ if (!prevTable) continue;
136
+ const tableDiffs = diffTable(prevTable, nextTable);
137
+ diffs.push(...tableDiffs);
138
+ }
139
+ return diffs;
140
+ }
141
+ function diffTable(prev, next) {
142
+ const diffs = [];
143
+ const prevColumns = new Map(prev.columns.map((c) => [c.name, c]));
144
+ const nextColumns = new Map(next.columns.map((c) => [c.name, c]));
145
+ for (const [name] of prevColumns) if (!nextColumns.has(name)) diffs.push({
146
+ type: "dropColumn",
147
+ table: prev.name,
148
+ column: name
149
+ });
150
+ for (const [name, col] of nextColumns) if (!prevColumns.has(name)) diffs.push({
151
+ type: "addColumn",
152
+ table: prev.name,
153
+ column: name,
154
+ details: { ...col }
155
+ });
156
+ for (const [name, nextCol] of nextColumns) {
157
+ const prevCol = prevColumns.get(name);
158
+ if (!prevCol) continue;
159
+ if (columnsDiffer(prevCol, nextCol)) diffs.push({
160
+ type: "alterColumn",
161
+ table: prev.name,
162
+ column: name,
163
+ details: {
164
+ from: prevCol,
165
+ to: nextCol
166
+ }
167
+ });
168
+ }
169
+ const prevIndexes = new Map(prev.indexes.map((i) => [i.name, i]));
170
+ const nextIndexes = new Map(next.indexes.map((i) => [i.name, i]));
171
+ for (const [name] of prevIndexes) if (!nextIndexes.has(name)) diffs.push({
172
+ type: "dropIndex",
173
+ table: prev.name,
174
+ details: { indexName: name }
175
+ });
176
+ for (const [name, idx] of nextIndexes) if (!prevIndexes.has(name)) diffs.push({
177
+ type: "addIndex",
178
+ table: prev.name,
179
+ details: {
180
+ indexName: name,
181
+ columns: idx.columns,
182
+ unique: idx.unique
183
+ }
184
+ });
185
+ return diffs;
186
+ }
187
+ function columnsDiffer(a, b) {
188
+ if (a.type !== b.type) return true;
189
+ if (a.isNullable !== b.isNullable) return true;
190
+ if (a.isPrimaryKey !== b.isPrimaryKey) return true;
191
+ if (a.isUnique !== b.isUnique) return true;
192
+ if (JSON.stringify(a.defaultValue) !== JSON.stringify(b.defaultValue)) return true;
193
+ if (JSON.stringify(a.references) !== JSON.stringify(b.references)) return true;
194
+ return false;
195
+ }
196
+ //#endregion
197
+ //#region src/generator.ts
198
+ function createMigrationGenerator() {
199
+ function generateInitialMigration(models, _options = {}) {
200
+ const parts = [];
201
+ const indexParts = [];
202
+ const warnings = [];
203
+ const registeredTables = new Set([...models.values()].map((m) => m.table).filter(Boolean));
204
+ for (const [, modelDef] of models) {
205
+ const table = modelDef.table;
206
+ if (!table) continue;
207
+ parts.push(generateCreateTable(table, modelDef.columns));
208
+ for (const [colName, col] of Object.entries(modelDef.columns)) if (col.hasConstraint("index") && !col.isPrimaryKey && !col.isUnique) indexParts.push(generateCreateIndex(table, colName));
209
+ for (const [, rel] of Object.entries(modelDef.relations ?? {})) if (rel.type === "manyToMany") {
210
+ const through = rel.throughTable;
211
+ if (through && !registeredTables.has(through)) warnings.push(`// ⚠ Detected ManyToMany "${modelDef.name}" references table "${through}" but no model is registered for it.\n// Add a model to include the pivot table.`);
212
+ }
213
+ }
214
+ const upBody = [...parts, ...indexParts].join("\n\n");
215
+ const downTables = [...models.values()].filter((m) => m.table).map((m) => ` await db.schema.dropTable("${m.table}").ifExists().execute()`).join("\n");
216
+ return `import type { Kysely } from "kysely"\nimport { sql } from "kysely"\n\nexport async function up(db: Kysely<any>): Promise<void> {\n${warnings.length > 0 ? ` // Warnings:\n${warnings.join("\n")}\n\n` : ""}${upBody}\n}\n\nexport async function down(db: Kysely<any>): Promise<void> {\n${downTables}\n}\n`;
217
+ }
218
+ function generateMigrationFromDiff(diffs, _options = {}) {
219
+ const upParts = [];
220
+ const downParts = [];
221
+ const warnings = [];
222
+ for (const diff of diffs) switch (diff.type) {
223
+ case "createTable": {
224
+ const cols = diff.details?.columns ?? [];
225
+ const indexes = diff.details?.indexes ?? [];
226
+ upParts.push(generateCreateTableFromSchema(diff.table, cols));
227
+ for (const idx of indexes) upParts.push(generateCreateIndexFromSchema(diff.table, idx.name, idx.columns));
228
+ downParts.push(` await db.schema.dropTable("${diff.table}").ifExists().execute()`);
229
+ break;
230
+ }
231
+ case "dropTable":
232
+ upParts.push(` await db.schema.dropTable("${diff.table}").ifExists().execute()`);
233
+ downParts.push(` // ⚠ Cannot auto-restore dropped table "${diff.table}" — manual recovery needed`);
234
+ warnings.push(`// ⚠ Dropped table "${diff.table}". The down() function cannot restore it.`);
235
+ break;
236
+ case "addColumn": {
237
+ const col = diff.details;
238
+ upParts.push(` await db.schema.alterTable("${diff.table}").addColumn("${col.name}", "${col.type}"${columnCallbackFromSchema(col)}).execute()`);
239
+ downParts.push(` await db.schema.alterTable("${diff.table}").dropColumn("${col.name}").execute()`);
240
+ break;
241
+ }
242
+ case "dropColumn":
243
+ upParts.push(` await db.schema.alterTable("${diff.table}").dropColumn("${diff.column}").execute()`);
244
+ downParts.push(` // ⚠ Cannot auto-restore dropped column "${diff.table}.${diff.column}" — manual recovery needed`);
245
+ warnings.push(`// ⚠ Dropped column "${diff.table}.${diff.column}". The down() function cannot restore it.`);
246
+ break;
247
+ case "alterColumn": {
248
+ const details = diff.details;
249
+ upParts.push(` // ⚠ ALTER COLUMN "${diff.table}.${diff.column}" — manual review recommended`);
250
+ if (details) {
251
+ upParts.push(` // from: ${details.from.type} → to: ${details.to.type}`);
252
+ upParts.push(` // nullable: ${details.from.isNullable} → ${details.to.isNullable}`);
253
+ }
254
+ upParts.push(` await db.schema.alterTable("${diff.table}").alterColumn("${diff.column}", (col) => col.setDataType("${details?.to.type ?? "text"}")).execute()`);
255
+ warnings.push(`// ⚠ ALTER COLUMN "${diff.table}.${diff.column}". Down migration is not auto-generated.`);
256
+ break;
257
+ }
258
+ case "addIndex": {
259
+ const idxDetails = diff.details;
260
+ const idxName = idxDetails?.indexName ?? `${diff.table}_${diff.column ?? "idx"}_index`;
261
+ const idxCols = idxDetails?.columns ?? (diff.column ? [diff.column] : []);
262
+ upParts.push(generateCreateIndexFromSchema(diff.table, idxName, idxCols));
263
+ downParts.push(` await db.schema.dropIndex("${idxName}").ifExists().execute()`);
264
+ break;
265
+ }
266
+ case "dropIndex": {
267
+ const idxName = diff.details?.indexName ?? `${diff.table}_idx`;
268
+ upParts.push(` await db.schema.dropIndex("${idxName}").ifExists().execute()`);
269
+ downParts.push(` // ⚠ Cannot auto-restore dropped index "${idxName}" — manual recovery needed`);
270
+ warnings.push(`// ⚠ Dropped index "${idxName}". The down() function cannot restore it.`);
271
+ break;
272
+ }
273
+ }
274
+ const upBody = upParts.join("\n\n");
275
+ const downBody = downParts.join("\n\n");
276
+ return `import type { Kysely } from "kysely"\nimport { sql } from "kysely"\n\nexport async function up(db: Kysely<any>): Promise<void> {\n${warnings.length > 0 ? ` // Warnings:\n${warnings.join("\n")}\n\n` : ""}${upBody}\n}\n\nexport async function down(db: Kysely<any>): Promise<void> {\n${downBody}\n}\n`;
277
+ }
278
+ return {
279
+ generateInitialMigration,
280
+ generateMigrationFromDiff
281
+ };
282
+ }
283
+ function generateCreateTable(table, columns) {
284
+ const lines = [` await db.schema.createTable("${table}").ifNotExists()`];
285
+ for (const [name, col] of Object.entries(columns)) lines.push(` .addColumn("${name}", "${mapType(col)}"${columnCallback(col)})`);
286
+ lines.push(" .execute()");
287
+ return lines.join("\n");
288
+ }
289
+ function generateCreateTableFromSchema(table, columns) {
290
+ const lines = [` await db.schema.createTable("${table}").ifNotExists()`];
291
+ for (const col of columns) {
292
+ const ref = col.references ? `, (c) => c.references("${col.references.table}.${col.references.column}")` : "";
293
+ const extras = [];
294
+ if (col.isPrimaryKey) extras.push("primaryKey()");
295
+ if (!col.isNullable && !col.isPrimaryKey) extras.push("notNull()");
296
+ if (col.isUnique && !col.isPrimaryKey) extras.push("unique()");
297
+ if (col.defaultValue !== void 0 && col.defaultValue !== null) extras.push(`defaultTo(${JSON.stringify(col.defaultValue)})`);
298
+ const cb = extras.length > 0 ? `, (c) => c.${extras.join(".")}${ref ? `.${ref.slice(5)}` : ""}` : ref;
299
+ lines.push(` .addColumn("${col.name}", "${col.type}"${cb})`);
300
+ }
301
+ lines.push(" .execute()");
302
+ return lines.join("\n");
303
+ }
304
+ function generateCreateIndex(table, column) {
305
+ return [
306
+ ` await db.schema.createIndex("${table}_${column}_index")`,
307
+ ` .on("${table}")`,
308
+ ` .column("${column}")`,
309
+ " .execute()"
310
+ ].join("\n");
311
+ }
312
+ function generateCreateIndexFromSchema(table, indexName, columns) {
313
+ const lines = [` await db.schema.createIndex("${indexName}").on("${table}")`];
314
+ for (const col of columns) lines.push(` .column("${col}")`);
315
+ lines.push(" .execute()");
316
+ return lines.join("\n");
317
+ }
318
+ function columnCallback(col) {
319
+ const calls = [];
320
+ if (col.isPrimaryKey) {
321
+ if (col.dataType === "integer") calls.push("autoIncrement()");
322
+ calls.push("primaryKey()");
323
+ }
324
+ if (!col.isNullable && !col.isPrimaryKey) calls.push("notNull()");
325
+ const dv = col.defaultValue;
326
+ if (dv !== void 0 && typeof dv !== "function") calls.push(`defaultTo(${JSON.stringify(dv)})`);
327
+ if (col.isUnique && !col.isPrimaryKey) calls.push("unique()");
328
+ const refConstraint = col.constraints.find((c) => c.type === "references");
329
+ if (refConstraint?.args[0]) {
330
+ const targetTable = (typeof refConstraint.args[0] === "function" ? refConstraint.args[0]() : refConstraint.args[0])?.table;
331
+ const targetColumns = refConstraint.args[1];
332
+ if (typeof targetTable === "string" && targetTable && targetColumns?.length) calls.push(`references("${targetTable}.${targetColumns[0]}")`);
333
+ }
334
+ return calls.length === 0 ? "" : `, (c) => c.${calls.join(".")}`;
335
+ }
336
+ function columnCallbackFromSchema(col) {
337
+ const calls = [];
338
+ if (col.isPrimaryKey) calls.push("primaryKey()");
339
+ if (!col.isNullable && !col.isPrimaryKey) calls.push("notNull()");
340
+ if (col.defaultValue !== void 0 && col.defaultValue !== null && typeof col.defaultValue !== "function") calls.push(`defaultTo(${JSON.stringify(col.defaultValue)})`);
341
+ if (col.isUnique && !col.isPrimaryKey) calls.push("unique()");
342
+ if (col.references) calls.push(`references("${col.references.table}.${col.references.column}")`);
343
+ return calls.length === 0 ? "" : `, (c) => c.${calls.join(".")}`;
344
+ }
345
+ function mapType(col) {
346
+ switch (col.dataType) {
347
+ case "integer":
348
+ case "smallint":
349
+ case "bigint":
350
+ case "text":
351
+ case "boolean":
352
+ case "timestamp":
353
+ case "date":
354
+ case "float":
355
+ case "double":
356
+ case "uuid": return col.dataType;
357
+ case "string": {
358
+ const max = col.args[0];
359
+ return max != null ? `varchar(${max})` : "varchar";
360
+ }
361
+ case "json":
362
+ case "jsonb": return "json";
363
+ case "decimal": {
364
+ const p = col.args[0];
365
+ const s = col.args[1];
366
+ return p != null ? `decimal(${p}, ${s ?? 0})` : "decimal";
367
+ }
368
+ case "enum": return "text";
369
+ default: return col.dataType;
370
+ }
371
+ }
372
+ //#endregion
373
+ //#region src/runner.ts
374
+ function createMigrationRunner(db, table = "_peta_migrations") {
375
+ /**
376
+ * Create a Kysely MigrationProvider from our MigrationFile[].
377
+ */
378
+ function createProvider(files) {
379
+ return { async getMigrations() {
380
+ const result = {};
381
+ for (const f of files.sort(byName)) result[f.name] = {
382
+ up: f.up,
383
+ down: f.down
384
+ };
385
+ return result;
386
+ } };
387
+ }
388
+ /**
389
+ * Build a Migrator instance with the given migration files.
390
+ */
391
+ function buildMigrator(files) {
392
+ return new Migrator({
393
+ db,
394
+ provider: createProvider(files),
395
+ migrationTableName: table,
396
+ migrationLockTableName: `${table}_lock`
397
+ });
398
+ }
399
+ /**
400
+ * Query the migration tracking table directly.
401
+ * Kysely's Migrator stores with column "name" and "timestamp".
402
+ */
403
+ async function queryCompleted() {
404
+ try {
405
+ return (await db.selectFrom(table).select(["name", "timestamp"]).orderBy("name", "asc").execute()).map((r) => ({
406
+ name: String(r.name),
407
+ appliedAt: String(r.timestamp)
408
+ }));
409
+ } catch {
410
+ return [];
411
+ }
412
+ }
413
+ async function ensureTable() {
414
+ const result = await buildMigrator([]).migrateUp();
415
+ if (result.error) {
416
+ const msg = result.error.message ?? "";
417
+ if (!msg.includes("no migrations") && !msg.includes("no pending")) throw result.error;
418
+ }
419
+ }
420
+ async function getCompleted() {
421
+ return queryCompleted();
422
+ }
423
+ async function up(migrations) {
424
+ const result = await buildMigrator(migrations).migrateToLatest();
425
+ if (result.error) throw result.error;
426
+ }
427
+ async function down(migrations) {
428
+ const result = await buildMigrator(migrations).migrateDown();
429
+ if (result.error) throw result.error;
430
+ }
431
+ async function status(migrations) {
432
+ const completed = await queryCompleted();
433
+ const completedNames = new Set(completed.map((r) => r.name));
434
+ return {
435
+ completed,
436
+ pending: migrations.filter((m) => !completedNames.has(m.name)).sort(byName)
437
+ };
438
+ }
439
+ return {
440
+ ensureTable,
441
+ getCompleted,
442
+ up,
443
+ down,
444
+ status
445
+ };
446
+ }
447
+ function byName(a, b) {
448
+ return a.name.localeCompare(b.name);
449
+ }
450
+ //#endregion
451
+ //#region src/snapshot.ts
452
+ /**
453
+ * Extract a SchemaSnapshot from a map of model definitions.
454
+ */
455
+ function createSnapshot(models) {
456
+ const tables = [];
457
+ for (const [, model] of models) {
458
+ if (!model.table) continue;
459
+ const columns = [];
460
+ const indexes = [];
461
+ for (const [name, col] of Object.entries(model.columns)) {
462
+ columns.push(columnToSchema(name, col));
463
+ if (col.hasConstraint("index") && !col.isPrimaryKey && !col.isUnique) indexes.push({
464
+ name: `${model.table}_${name}_index`,
465
+ columns: [name]
466
+ });
467
+ }
468
+ tables.push({
469
+ name: model.table,
470
+ columns,
471
+ indexes
472
+ });
473
+ }
474
+ return {
475
+ version: 1,
476
+ tables
477
+ };
478
+ }
479
+ function columnToSchema(name, col) {
480
+ const refConstraint = col.constraints.find((c) => c.type === "references");
481
+ let references;
482
+ if (refConstraint?.args[0]) {
483
+ const targetTable = (typeof refConstraint.args[0] === "function" ? refConstraint.args[0]() : refConstraint.args[0])?.table;
484
+ const targetColumns = refConstraint.args[1];
485
+ if (typeof targetTable === "string" && targetTable && targetColumns?.length) {
486
+ const first = targetColumns[0];
487
+ if (first) references = {
488
+ table: targetTable,
489
+ column: first
490
+ };
491
+ }
492
+ }
493
+ return {
494
+ name,
495
+ type: mapSnapshotType(col),
496
+ isNullable: col.isNullable ?? false,
497
+ isPrimaryKey: col.isPrimaryKey ?? false,
498
+ isUnique: col.isUnique ?? false,
499
+ defaultValue: col.defaultValue,
500
+ references
501
+ };
502
+ }
503
+ function mapSnapshotType(col) {
504
+ switch (col.dataType) {
505
+ case "integer":
506
+ case "smallint":
507
+ case "bigint":
508
+ case "text":
509
+ case "boolean":
510
+ case "timestamp":
511
+ case "date":
512
+ case "float":
513
+ case "double":
514
+ case "uuid": return col.dataType;
515
+ case "string": {
516
+ const max = col.args[0];
517
+ return max != null ? `varchar(${max})` : "varchar";
518
+ }
519
+ case "json":
520
+ case "jsonb": return "json";
521
+ case "decimal": {
522
+ const p = col.args[0];
523
+ const s = col.args[1];
524
+ return p != null ? `decimal(${p}, ${s ?? 0})` : "decimal";
525
+ }
526
+ case "enum": return "text";
527
+ default: return col.dataType;
528
+ }
529
+ }
530
+ /**
531
+ * Load snapshot from a JSON file path.
532
+ */
533
+ async function loadSnapshot(filePath) {
534
+ try {
535
+ const { readFileSync } = await import("node:fs");
536
+ const data = readFileSync(filePath, "utf-8");
537
+ return JSON.parse(data);
538
+ } catch {
539
+ return null;
540
+ }
541
+ }
542
+ /**
543
+ * Save snapshot to a JSON file path.
544
+ */
545
+ async function saveSnapshot(filePath, snapshot) {
546
+ const { writeFileSync } = await import("node:fs");
547
+ writeFileSync(filePath, JSON.stringify(snapshot, null, 2));
548
+ }
549
+ //#endregion
550
+ export { createMigrationGenerator as a, loadConfig as c, computeChecksum as d, loadChecksums as f, createMigrationRunner as i, loadMigrationFiles as l, verifyChecksum as m, loadSnapshot as n, diffSnapshots as o, saveChecksums as p, saveSnapshot as r, defineConfig as s, createSnapshot as t, loadModels as u };
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "peta-migrate",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "private": false,
5
+ "version": "0.2.1",
5
6
  "description": "Migration tools for peta-orm",
6
7
  "license": "MIT",
7
8
  "repository": {
8
9
  "type": "git",
9
10
  "url": "git+https://github.com/zfadhli/peta-stack.git"
10
11
  },
11
- "module": "src/index.ts",
12
+ "module": "./dist/index.mjs",
12
13
  "main": "./dist/index.mjs",
13
14
  "types": "./dist/index.d.mts",
14
15
  "exports": {
@@ -32,15 +33,22 @@
32
33
  },
33
34
  "peerDependencies": {
34
35
  "kysely": "^0.29.2",
36
+ "peta-orm": "workspace:*",
35
37
  "typescript": "^6.0.0"
36
38
  },
37
39
  "devDependencies": {
40
+ "@libsql/client": "^0.8.0",
41
+ "@libsql/kysely-libsql": "^0.4.1",
38
42
  "@types/bun": "^1.3.14",
39
- "tsdown": "^0.22.2"
43
+ "kysely": "^0.29.2",
44
+ "peta-orm": "workspace:*",
45
+ "tsdown": "^0.22.2",
46
+ "typescript": "^6.0.0"
40
47
  },
41
48
  "scripts": {
42
49
  "build": "tsdown",
43
- "prepublish": "bun run build",
44
- "typecheck": "bun x tsc --noEmit"
50
+ "prepublishOnly": "bun run build",
51
+ "typecheck": "bun x tsc --noEmit",
52
+ "test": "bun test"
45
53
  }
46
54
  }