@vibeorm/migrate 1.3.0 → 2.0.0-alpha.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.
Files changed (60) hide show
  1. package/README.md +33 -66
  2. package/dist/ddl/drop-order.d.ts +25 -0
  3. package/dist/ddl/drop-order.d.ts.map +1 -0
  4. package/dist/ddl/mysql.d.ts +46 -0
  5. package/dist/ddl/mysql.d.ts.map +1 -0
  6. package/dist/ddl/postgres.d.ts +24 -0
  7. package/dist/ddl/postgres.d.ts.map +1 -0
  8. package/dist/ddl/render.d.ts +25 -0
  9. package/dist/ddl/render.d.ts.map +1 -0
  10. package/dist/ddl/sqlite.d.ts +62 -0
  11. package/dist/ddl/sqlite.d.ts.map +1 -0
  12. package/dist/differ.d.ts +33 -0
  13. package/dist/differ.d.ts.map +1 -0
  14. package/dist/down.d.ts +55 -0
  15. package/dist/down.d.ts.map +1 -0
  16. package/dist/enum-values.d.ts +19 -0
  17. package/dist/enum-values.d.ts.map +1 -0
  18. package/dist/execute.d.ts +41 -0
  19. package/dist/execute.d.ts.map +1 -0
  20. package/dist/extensions.d.ts +74 -0
  21. package/dist/extensions.d.ts.map +1 -0
  22. package/dist/index.d.ts +26 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +3813 -0
  25. package/dist/index.js.map +31 -0
  26. package/dist/introspect/mysql.d.ts +31 -0
  27. package/dist/introspect/mysql.d.ts.map +1 -0
  28. package/dist/introspect/postgres.d.ts +25 -0
  29. package/dist/introspect/postgres.d.ts.map +1 -0
  30. package/dist/introspect/shared.d.ts +71 -0
  31. package/dist/introspect/shared.d.ts.map +1 -0
  32. package/dist/introspect/sqlite.d.ts +53 -0
  33. package/dist/introspect/sqlite.d.ts.map +1 -0
  34. package/dist/mysql-types.d.ts +66 -0
  35. package/dist/mysql-types.d.ts.map +1 -0
  36. package/dist/normalize.d.ts +115 -0
  37. package/dist/normalize.d.ts.map +1 -0
  38. package/dist/postgres-types.d.ts +88 -0
  39. package/dist/postgres-types.d.ts.map +1 -0
  40. package/dist/push.d.ts +45 -0
  41. package/dist/push.d.ts.map +1 -0
  42. package/dist/relations.d.ts +30 -0
  43. package/dist/relations.d.ts.map +1 -0
  44. package/dist/runner.d.ts +120 -0
  45. package/dist/runner.d.ts.map +1 -0
  46. package/dist/sqlite-types.d.ts +87 -0
  47. package/dist/sqlite-types.d.ts.map +1 -0
  48. package/dist/types.d.ts +217 -0
  49. package/dist/types.d.ts.map +1 -0
  50. package/package.json +33 -23
  51. package/src/cascade-actions.ts +0 -88
  52. package/src/ddl-builder.ts +0 -444
  53. package/src/index.ts +0 -41
  54. package/src/introspector.ts +0 -684
  55. package/src/migration-runner.ts +0 -127
  56. package/src/schema-differ.ts +0 -895
  57. package/src/schema-printer.ts +0 -259
  58. package/src/snapshot.ts +0 -141
  59. package/src/sql-utils.ts +0 -45
  60. package/src/types.ts +0 -13
@@ -1,127 +0,0 @@
1
- /**
2
- * Migration Runner — Apply SQL files with tracking
3
- *
4
- * Handles creating the migration tracking table, querying applied migrations,
5
- * executing migration SQL files, and recording results.
6
- */
7
-
8
- import type { SqlExecutor } from "./types.ts";
9
- import { splitSqlStatements } from "./sql-utils.ts";
10
-
11
- // ─── Types ────────────────────────────────────────────────────────
12
-
13
- export type AppliedMigration = {
14
- id: number;
15
- migrationName: string;
16
- checksum: string;
17
- appliedAt: Date;
18
- executionTime: number | null;
19
- };
20
-
21
- // ─── Migration Table Management ───────────────────────────────────
22
-
23
- const CREATE_TABLE_SQL = `
24
- CREATE TABLE IF NOT EXISTS "_vibeorm_migrations" (
25
- "id" SERIAL PRIMARY KEY,
26
- "migration_name" TEXT NOT NULL UNIQUE,
27
- "checksum" TEXT NOT NULL,
28
- "applied_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
29
- "execution_time" INTEGER
30
- );
31
- `;
32
-
33
- export async function ensureMigrationTable(params: { executor: SqlExecutor }): Promise<void> {
34
- await params.executor({ text: CREATE_TABLE_SQL });
35
- }
36
-
37
- export async function getAppliedMigrations(params: { executor: SqlExecutor }): Promise<AppliedMigration[]> {
38
- const rows = await params.executor({
39
- text: `SELECT id, migration_name, checksum, applied_at, execution_time FROM "_vibeorm_migrations" ORDER BY id;`,
40
- });
41
-
42
- return rows.map((row) => ({
43
- id: row.id as number,
44
- migrationName: row.migration_name as string,
45
- checksum: row.checksum as string,
46
- appliedAt: new Date(row.applied_at as string),
47
- executionTime: row.execution_time as number | null,
48
- }));
49
- }
50
-
51
- // ─── Apply Migration ──────────────────────────────────────────────
52
-
53
- export async function applyMigration(params: {
54
- executor: SqlExecutor;
55
- migrationName: string;
56
- sql: string;
57
- checksum: string;
58
- }): Promise<{ executionTime: number }> {
59
- const { executor, migrationName, sql, checksum } = params;
60
- const start = Date.now();
61
-
62
- // Split migration SQL into individual statements to handle
63
- // DO $$ blocks and multi-statement migrations correctly
64
- const statements = splitSqlStatements({ sql });
65
- for (const stmt of statements) {
66
- await executor({ text: stmt });
67
- }
68
-
69
- const executionTime = Date.now() - start;
70
-
71
- // Record the applied migration
72
- await executor({
73
- text: `INSERT INTO "_vibeorm_migrations" ("migration_name", "checksum", "execution_time") VALUES ($1, $2, $3);`,
74
- values: [migrationName, checksum, executionTime],
75
- });
76
-
77
- return { executionTime };
78
- }
79
-
80
- // ─── Repair Tools ─────────────────────────────────────────────────
81
-
82
- export async function markMigrationApplied(params: {
83
- executor: SqlExecutor;
84
- migrationName: string;
85
- checksum: string;
86
- }): Promise<void> {
87
- const { executor, migrationName, checksum } = params;
88
- await executor({
89
- text: `INSERT INTO "_vibeorm_migrations" ("migration_name", "checksum", "execution_time") VALUES ($1, $2, $3) ON CONFLICT ("migration_name") DO NOTHING;`,
90
- values: [migrationName, checksum, 0],
91
- });
92
- }
93
-
94
- export async function removeMigrationRecord(params: {
95
- executor: SqlExecutor;
96
- migrationName: string;
97
- }): Promise<void> {
98
- const { executor, migrationName } = params;
99
- await executor({
100
- text: `DELETE FROM "_vibeorm_migrations" WHERE "migration_name" = $1;`,
101
- values: [migrationName],
102
- });
103
- }
104
-
105
- // ─── Rollback Migration ───────────────────────────────────────────
106
-
107
- export async function rollbackMigration(params: {
108
- executor: SqlExecutor;
109
- migrationName: string;
110
- sql: string;
111
- }): Promise<{ executionTime: number }> {
112
- const { executor, migrationName, sql } = params;
113
- const start = Date.now();
114
-
115
- // Split down migration SQL into individual statements
116
- const statements = splitSqlStatements({ sql });
117
- for (const stmt of statements) {
118
- await executor({ text: stmt });
119
- }
120
-
121
- const executionTime = Date.now() - start;
122
-
123
- // Remove the migration tracking record
124
- await removeMigrationRecord({ executor, migrationName });
125
-
126
- return { executionTime };
127
- }