@onreza/sqlx-js 0.1.0 → 0.2.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.
@@ -3,9 +3,22 @@ export type MigrateOptions = {
3
3
  databaseUrl: string;
4
4
  migrationsDir: string;
5
5
  };
6
+ export type MigrationWorkflowOptions = MigrateOptions & {
7
+ root: string;
8
+ cacheDir: string;
9
+ dtsPath: string;
10
+ prune?: boolean;
11
+ shadowUrl?: string;
12
+ shadowAdminUrl?: string;
13
+ lockKey?: number | bigint;
14
+ lockTimeoutMs?: number;
15
+ };
16
+ export type MigrationStore = {
17
+ table: string;
18
+ };
6
19
  export declare const DEFAULT_MIGRATE_LOCK_KEY = 18750938867203960n;
7
- export declare function ensureTable(c: PgClient): Promise<void>;
8
- export declare function listApplied(c: PgClient): Promise<Map<number, {
20
+ export declare function ensureTable(c: PgClient): Promise<MigrationStore>;
21
+ export declare function listApplied(c: PgClient, store?: MigrationStore): Promise<Map<number, {
9
22
  name: string;
10
23
  hash: string;
11
24
  }>>;
@@ -13,6 +26,11 @@ export type ApplyOutcome = {
13
26
  kind: "applied";
14
27
  version: number;
15
28
  name: string;
29
+ } | {
30
+ kind: "adopted";
31
+ version: number;
32
+ name: string;
33
+ replaced: number;
16
34
  } | {
17
35
  kind: "tampered";
18
36
  version: number;
@@ -25,6 +43,123 @@ export type ApplyOutcome = {
25
43
  name: string;
26
44
  error: string;
27
45
  };
46
+ export type PlanOutcome = {
47
+ kind: "pending";
48
+ version: number;
49
+ name: string;
50
+ } | {
51
+ kind: "adoptable";
52
+ version: number;
53
+ name: string;
54
+ replaced: number;
55
+ } | {
56
+ kind: "tampered";
57
+ version: number;
58
+ name: string;
59
+ applied: string;
60
+ current: string;
61
+ } | {
62
+ kind: "failed";
63
+ version: number;
64
+ name: string;
65
+ error: string;
66
+ };
67
+ export type MigrationPlanItem = {
68
+ kind: "apply";
69
+ version: number;
70
+ name: string;
71
+ } | {
72
+ kind: "adopt";
73
+ version: number;
74
+ name: string;
75
+ replaced: number;
76
+ };
77
+ export type MigrationPlanDiagnostic = Extract<PlanOutcome, {
78
+ kind: "tampered" | "failed";
79
+ }>;
80
+ export type MigrationPlanSnapshot = {
81
+ ok: boolean;
82
+ pending: number;
83
+ adoptable: number;
84
+ tampered: number;
85
+ failed: number;
86
+ steps: MigrationPlanItem[];
87
+ diagnostics: MigrationPlanDiagnostic[];
88
+ };
89
+ export type MigrationInfoStatus = "applied" | "pending" | "adoptable" | "superseded" | "tampered" | "failed";
90
+ export type MigrationInfoItem = {
91
+ version: number;
92
+ name: string;
93
+ status: MigrationInfoStatus;
94
+ detail?: string;
95
+ };
96
+ export type MigrationInfoSnapshot = {
97
+ historyTable: string | null;
98
+ summary: Record<MigrationInfoStatus, number>;
99
+ items: MigrationInfoItem[];
100
+ };
101
+ export type MigrationArchive = {
102
+ name: string;
103
+ path: string;
104
+ files: string[];
105
+ };
106
+ export type MigrationCheckIssue = {
107
+ severity: "error";
108
+ code: "invalid-file-name" | "invalid-version" | "duplicate-version" | "orphan-down" | "invalid-squash-metadata" | "invalid-squash-replacement" | "tampered-squash-replacement";
109
+ message: string;
110
+ file?: string;
111
+ version?: number;
112
+ name?: string;
113
+ };
114
+ export type MigrationCheckReport = {
115
+ ok: boolean;
116
+ migrations: number;
117
+ archives: number;
118
+ issues: MigrationCheckIssue[];
119
+ };
120
+ export type SchemaObjectDiff = {
121
+ added: string[];
122
+ removed: string[];
123
+ changed: string[];
124
+ };
125
+ export type SchemaDiffSummary = {
126
+ relations: SchemaObjectDiff;
127
+ types: SchemaObjectDiff;
128
+ functions: SchemaObjectDiff;
129
+ };
130
+ export type RevertDryRunPhase = "validate" | "begin" | "isolate" | "previous-up" | "snapshot-before" | "target-up" | "down" | "snapshot-after" | "rollback";
131
+ export type RevertDryRunOutcome = {
132
+ kind: "noop";
133
+ } | {
134
+ kind: "no-down";
135
+ version: number;
136
+ name: string;
137
+ } | {
138
+ kind: "passed";
139
+ version: number;
140
+ name: string;
141
+ } | {
142
+ kind: "schema-mismatch";
143
+ version: number;
144
+ name: string;
145
+ diff: SchemaDiffSummary;
146
+ } | {
147
+ kind: "failed";
148
+ version?: number;
149
+ name?: string;
150
+ phase: RevertDryRunPhase;
151
+ error: string;
152
+ };
153
+ export declare function checkMigrationFiles(migrationsDir: string): MigrationCheckReport;
154
+ export declare function planPending(c: PgClient, migrationsDir: string, onEvent?: (e: PlanOutcome) => void): Promise<{
155
+ pending: number;
156
+ adoptable: number;
157
+ tampered: number;
158
+ failed: number;
159
+ steps: MigrationPlanItem[];
160
+ }>;
161
+ export declare function inspectMigrationPlan(c: PgClient, migrationsDir: string): Promise<MigrationPlanSnapshot>;
162
+ export declare function inspectMigrations(c: PgClient, migrationsDir: string): Promise<MigrationInfoSnapshot>;
28
163
  export declare function applyPending(c: PgClient, migrationsDir: string, onEvent?: (e: ApplyOutcome) => void): Promise<{
29
164
  applied: number;
30
165
  tampered: number;
@@ -32,11 +167,53 @@ export declare function applyPending(c: PgClient, migrationsDir: string, onEvent
32
167
  }>;
33
168
  export declare function acquireMigrateLock(c: PgClient, lockKey?: number | bigint, timeoutMs?: number): Promise<void>;
34
169
  export declare function releaseMigrateLock(c: PgClient, lockKey?: number | bigint): Promise<void>;
170
+ export declare function sanitizePgDumpSchema(sql: string): string;
171
+ export declare function listMigrationArchives(migrationsDir: string): MigrationArchive[];
172
+ export declare function restoreMigrationArchive(migrationsDir: string, archiveName: string, opts?: {
173
+ force?: boolean;
174
+ }): {
175
+ archiveName: string;
176
+ restored: string[];
177
+ };
178
+ export declare function createSquashMigration(opts: {
179
+ migrationsDir: string;
180
+ name: string;
181
+ schemaSql: string;
182
+ replace?: boolean;
183
+ }): {
184
+ version: number;
185
+ name: string;
186
+ upPath: string;
187
+ replaced: number;
188
+ archiveDir?: string;
189
+ };
190
+ export declare function dumpSchema(databaseUrl: string, pgDumpPath?: string): string;
191
+ export declare function migrateSquash(opts: {
192
+ databaseUrl?: string;
193
+ migrationsDir: string;
194
+ name: string;
195
+ shadowUrl?: string;
196
+ shadowAdminUrl?: string;
197
+ replace?: boolean;
198
+ pgDumpPath?: string;
199
+ lockKey?: number | bigint;
200
+ lockTimeoutMs?: number;
201
+ }): Promise<void>;
35
202
  export declare function migrateRun(opts: MigrateOptions & {
36
203
  lockKey?: number | bigint;
37
204
  lockTimeoutMs?: number;
205
+ dryRun?: boolean;
206
+ json?: boolean;
207
+ }): Promise<void>;
208
+ export declare function migrateInfo(opts: MigrateOptions & {
209
+ json?: boolean;
38
210
  }): Promise<void>;
39
- export declare function migrateInfo(opts: MigrateOptions): Promise<void>;
211
+ export declare function migrateCheck(opts: {
212
+ migrationsDir: string;
213
+ json?: boolean;
214
+ }): void;
215
+ export declare function migrateDev(opts: MigrationWorkflowOptions): Promise<void>;
216
+ export declare function migrateVerify(opts: MigrationWorkflowOptions): Promise<void>;
40
217
  export type RevertOutcome = {
41
218
  kind: "noop";
42
219
  } | {
@@ -54,10 +231,20 @@ export type RevertOutcome = {
54
231
  error: string;
55
232
  };
56
233
  export declare function revertLast(c: PgClient, migrationsDir: string): Promise<RevertOutcome>;
234
+ export declare function checkLastDownMigration(c: PgClient, migrationsDir: string): Promise<RevertDryRunOutcome>;
57
235
  export declare function migrateRevert(opts: MigrateOptions & {
58
236
  lockKey?: number | bigint;
59
237
  lockTimeoutMs?: number;
238
+ dryRun?: boolean;
239
+ shadowUrl?: string;
240
+ shadowAdminUrl?: string;
241
+ json?: boolean;
60
242
  }): Promise<void>;
243
+ export declare function migrateArchiveList(opts: Pick<MigrateOptions, "migrationsDir">): void;
244
+ export declare function migrateArchiveRestore(opts: Pick<MigrateOptions, "migrationsDir"> & {
245
+ name: string;
246
+ force?: boolean;
247
+ }): void;
61
248
  export declare function migrateAdd(opts: MigrateOptions & {
62
249
  name: string;
63
250
  }): void;