@ductape/cli 0.2.9 → 0.2.10
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.
|
@@ -6,9 +6,9 @@ import { fail, printJson } from '../lib/output.js';
|
|
|
6
6
|
function buildDbContext(dbTag, envSlug, productTag) {
|
|
7
7
|
return { database: dbTag, env: envSlug, product: productTag };
|
|
8
8
|
}
|
|
9
|
-
async function getAppliedTags(proxy, dbContext
|
|
9
|
+
async function getAppliedTags(proxy, dbContext) {
|
|
10
10
|
try {
|
|
11
|
-
const result = await proxy.execute('migration.
|
|
11
|
+
const result = await proxy.execute('migration.history', [], dbContext);
|
|
12
12
|
const list = Array.isArray(result)
|
|
13
13
|
? result
|
|
14
14
|
: Array.isArray(result.data)
|
|
@@ -44,7 +44,7 @@ export async function runDbMigrate(opts) {
|
|
|
44
44
|
console.log(`[${db}] No migration files found. Run \`ductape db schema generate\` first.`);
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
|
-
const appliedTags = await getAppliedTags(proxy, dbContext
|
|
47
|
+
const appliedTags = await getAppliedTags(proxy, dbContext);
|
|
48
48
|
const pending = migrations.filter((m) => !appliedTags.includes(m.tag));
|
|
49
49
|
if (pending.length === 0) {
|
|
50
50
|
console.log(`[${db}] Already up to date.`);
|
|
@@ -92,7 +92,7 @@ export async function runDbMigrateStatus(opts) {
|
|
|
92
92
|
const { db } = entry;
|
|
93
93
|
const dbContext = buildDbContext(db, envSlug, productTag);
|
|
94
94
|
const migrations = loadMigrationFiles(dir, db);
|
|
95
|
-
const appliedTags = await getAppliedTags(proxy, dbContext
|
|
95
|
+
const appliedTags = await getAppliedTags(proxy, dbContext);
|
|
96
96
|
const applied = migrations.filter((m) => appliedTags.includes(m.tag)).map((m) => m.tag);
|
|
97
97
|
const pending = migrations.filter((m) => !appliedTags.includes(m.tag)).map((m) => m.tag);
|
|
98
98
|
statusReport[db] = { applied, pending };
|
|
@@ -132,7 +132,7 @@ export async function runDbMigrateRollback(opts) {
|
|
|
132
132
|
const { db } = entry;
|
|
133
133
|
const dbContext = buildDbContext(db, envSlug, productTag);
|
|
134
134
|
const migrations = loadMigrationFiles(dir, db);
|
|
135
|
-
const appliedTags = await getAppliedTags(proxy, dbContext
|
|
135
|
+
const appliedTags = await getAppliedTags(proxy, dbContext);
|
|
136
136
|
const applied = migrations.filter((m) => appliedTags.includes(m.tag));
|
|
137
137
|
const toRollback = applied.slice(-rollbackCount).reverse();
|
|
138
138
|
if (toRollback.length === 0) {
|
package/package.json
CHANGED
|
@@ -30,13 +30,11 @@ function buildDbContext(dbTag: string, envSlug: string, productTag: string): Dat
|
|
|
30
30
|
async function getAppliedTags(
|
|
31
31
|
proxy: ReturnType<typeof getDbProxy>,
|
|
32
32
|
dbContext: DatabaseContext,
|
|
33
|
-
productTag: string,
|
|
34
|
-
envSlug: string,
|
|
35
33
|
): Promise<string[]> {
|
|
36
34
|
try {
|
|
37
35
|
const result = await proxy.execute<unknown>(
|
|
38
|
-
'migration.
|
|
39
|
-
[
|
|
36
|
+
'migration.history',
|
|
37
|
+
[],
|
|
40
38
|
dbContext,
|
|
41
39
|
);
|
|
42
40
|
const list = Array.isArray(result)
|
|
@@ -80,7 +78,7 @@ export async function runDbMigrate(opts: MigrateOpts): Promise<void> {
|
|
|
80
78
|
continue;
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
const appliedTags = await getAppliedTags(proxy, dbContext
|
|
81
|
+
const appliedTags = await getAppliedTags(proxy, dbContext);
|
|
84
82
|
const pending = migrations.filter((m) => !appliedTags.includes(m.tag));
|
|
85
83
|
|
|
86
84
|
if (pending.length === 0) {
|
|
@@ -139,7 +137,7 @@ export async function runDbMigrateStatus(opts: MigrateStatusOpts): Promise<void>
|
|
|
139
137
|
const { db } = entry;
|
|
140
138
|
const dbContext = buildDbContext(db, envSlug, productTag);
|
|
141
139
|
const migrations = loadMigrationFiles(dir, db);
|
|
142
|
-
const appliedTags = await getAppliedTags(proxy, dbContext
|
|
140
|
+
const appliedTags = await getAppliedTags(proxy, dbContext);
|
|
143
141
|
|
|
144
142
|
const applied = migrations.filter((m) => appliedTags.includes(m.tag)).map((m) => m.tag);
|
|
145
143
|
const pending = migrations.filter((m) => !appliedTags.includes(m.tag)).map((m) => m.tag);
|
|
@@ -183,7 +181,7 @@ export async function runDbMigrateRollback(opts: MigrateRollbackOpts): Promise<v
|
|
|
183
181
|
const { db } = entry;
|
|
184
182
|
const dbContext = buildDbContext(db, envSlug, productTag);
|
|
185
183
|
const migrations = loadMigrationFiles(dir, db);
|
|
186
|
-
const appliedTags = await getAppliedTags(proxy, dbContext
|
|
184
|
+
const appliedTags = await getAppliedTags(proxy, dbContext);
|
|
187
185
|
|
|
188
186
|
const applied = migrations.filter((m) => appliedTags.includes(m.tag));
|
|
189
187
|
const toRollback = applied.slice(-rollbackCount).reverse();
|