@coffre/db 0.1.2 → 0.1.4
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/migrate.d.ts +11 -2
- package/dist/migrate.js +12 -3
- package/package.json +2 -2
- package/src/migrate.ts +12 -3
package/dist/migrate.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ import { Engine } from "./dialect.js";
|
|
|
5
5
|
* in the built package, where the build copies them.
|
|
6
6
|
*/
|
|
7
7
|
export declare function migrationsFolder(engine: Engine): string;
|
|
8
|
-
/**
|
|
9
|
-
export
|
|
8
|
+
/** A migration run's plan: `applied` of the `total` migrations there before it, the rest applied by it. */
|
|
9
|
+
export type MigrationPlan = {
|
|
10
|
+
applied: number;
|
|
11
|
+
total: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Apply missing migrations, check their history and reassert database
|
|
15
|
+
* privileges. `onPlan` hears how many there are to apply before they are:
|
|
16
|
+
* all of them go in one call, with no word of each.
|
|
17
|
+
*/
|
|
18
|
+
export declare function migrateDatabase(url: string, onPlan?: (plan: MigrationPlan) => void): Promise<void>;
|
|
10
19
|
//#endregion
|
package/dist/migrate.js
CHANGED
|
@@ -102,8 +102,12 @@ async function sqliteMigrator(url) {
|
|
|
102
102
|
close
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
/**
|
|
106
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Apply missing migrations, check their history and reassert database
|
|
107
|
+
* privileges. `onPlan` hears how many there are to apply before they are:
|
|
108
|
+
* all of them go in one call, with no word of each.
|
|
109
|
+
*/
|
|
110
|
+
async function migrateDatabase(url, onPlan) {
|
|
107
111
|
const engine = engineOfUrl(url);
|
|
108
112
|
const expected = await expectedMigrations(engine);
|
|
109
113
|
const migrator = await {
|
|
@@ -114,7 +118,12 @@ async function migrateDatabase(url) {
|
|
|
114
118
|
try {
|
|
115
119
|
await migrator.lock();
|
|
116
120
|
locked = true;
|
|
117
|
-
|
|
121
|
+
const applied = await migrator.applied();
|
|
122
|
+
verifyHistory(expected, applied, false);
|
|
123
|
+
onPlan?.({
|
|
124
|
+
applied: applied?.length ?? 0,
|
|
125
|
+
total: expected.length
|
|
126
|
+
});
|
|
118
127
|
await migrator.migrate(migrationsFolder(engine));
|
|
119
128
|
verifyHistory(expected, await migrator.applied(), true);
|
|
120
129
|
await migrator.restrict();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffre/db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "coffre's database: the schema, its migrations and the connections, on Postgres or SQLite.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"drizzle-orm": "0.45.2",
|
|
75
75
|
"pg": "8.16.3",
|
|
76
76
|
"pg-connection-string": "2.14.0",
|
|
77
|
-
"@coffre/core": "0.1.
|
|
77
|
+
"@coffre/core": "0.1.4"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/node": "26.1.1",
|
package/src/migrate.ts
CHANGED
|
@@ -182,8 +182,15 @@ async function sqliteMigrator(url: string): Promise<Migrator> {
|
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
/**
|
|
186
|
-
export
|
|
185
|
+
/** A migration run's plan: `applied` of the `total` migrations there before it, the rest applied by it. */
|
|
186
|
+
export type MigrationPlan = { applied: number; total: number };
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Apply missing migrations, check their history and reassert database
|
|
190
|
+
* privileges. `onPlan` hears how many there are to apply before they are:
|
|
191
|
+
* all of them go in one call, with no word of each.
|
|
192
|
+
*/
|
|
193
|
+
export async function migrateDatabase(url: string, onPlan?: (plan: MigrationPlan) => void): Promise<void> {
|
|
187
194
|
const engine = engineOfUrl(url);
|
|
188
195
|
const expected = await expectedMigrations(engine);
|
|
189
196
|
const migrator = await { postgres: postgresMigrator, sqlite: sqliteMigrator }[engine](url);
|
|
@@ -193,7 +200,9 @@ export async function migrateDatabase(url: string): Promise<void> {
|
|
|
193
200
|
await migrator.lock();
|
|
194
201
|
locked = true;
|
|
195
202
|
|
|
196
|
-
|
|
203
|
+
const applied = await migrator.applied();
|
|
204
|
+
verifyHistory(expected, applied, false);
|
|
205
|
+
onPlan?.({ applied: applied?.length ?? 0, total: expected.length });
|
|
197
206
|
await migrator.migrate(migrationsFolder(engine));
|
|
198
207
|
verifyHistory(expected, await migrator.applied(), true);
|
|
199
208
|
await migrator.restrict();
|