migraguard 0.10.3 → 0.10.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/cli.js CHANGED
@@ -810,6 +810,22 @@ function createDb(config) {
810
810
  return new MigraguardDb(config);
811
811
  }
812
812
  }
813
+ async function safeGetAllRecords(db) {
814
+ try {
815
+ return await db.getAllRecords();
816
+ } catch (err) {
817
+ if (isTableNotFound(err)) return [];
818
+ throw err;
819
+ }
820
+ }
821
+ function isTableNotFound(err) {
822
+ if (!(err instanceof Error)) return false;
823
+ const code = err["code"];
824
+ if (code === "42P01") return true;
825
+ if (code === "ER_NO_SUCH_TABLE") return true;
826
+ if (err.message.includes("no such table")) return true;
827
+ return false;
828
+ }
813
829
  var CONNECTION_TIMEOUT_MS2 = 1e4;
814
830
  var SESSION_STATEMENT_TIMEOUT_MS = 3e4;
815
831
  var DDL_LOCK_TIMEOUT = "5s";
@@ -2501,8 +2517,7 @@ async function commandGroupStatus(config, groupName) {
2501
2517
  const db = createDb(config);
2502
2518
  try {
2503
2519
  await db.connect();
2504
- await db.ensureTable();
2505
- const allRecords = await db.getAllRecords();
2520
+ const allRecords = await safeGetAllRecords(db);
2506
2521
  let groups;
2507
2522
  if (groupName) {
2508
2523
  const state = deriveGroupState(allRecords, groupName);
@@ -2618,8 +2633,7 @@ async function commandGate(config, options) {
2618
2633
  const db = createDb(config);
2619
2634
  try {
2620
2635
  await db.connect();
2621
- await db.ensureTable();
2622
- const allRecords = await db.getAllRecords();
2636
+ const allRecords = await safeGetAllRecords(db);
2623
2637
  const groupStates = deriveAllGroupStates(allRecords);
2624
2638
  const reasons = [];
2625
2639
  for (const req of contract.required) {
@@ -5113,8 +5127,7 @@ async function commandEditable(config) {
5113
5127
  await db.connect();
5114
5128
  dbConnected = true;
5115
5129
  try {
5116
- await db.ensureTable();
5117
- const allRecords = await db.getAllRecords();
5130
+ const allRecords = await safeGetAllRecords(db);
5118
5131
  const recordsByFile = /* @__PURE__ */ new Map();
5119
5132
  for (const r of allRecords) {
5120
5133
  const list = recordsByFile.get(r.fileName) ?? [];
@@ -5166,9 +5179,8 @@ async function commandStatus(config) {
5166
5179
  let groups = [];
5167
5180
  try {
5168
5181
  await db.connect();
5169
- await db.ensureTable();
5170
5182
  const files = await scanMigrations(config);
5171
- const allRecords = await db.getAllRecords();
5183
+ const allRecords = await safeGetAllRecords(db);
5172
5184
  const recordsByFile = /* @__PURE__ */ new Map();
5173
5185
  for (const r of allRecords) {
5174
5186
  const list = recordsByFile.get(r.fileName) ?? [];
@@ -5556,8 +5568,7 @@ async function getAppliedFiles(config) {
5556
5568
  const db = createDb(config);
5557
5569
  try {
5558
5570
  await db.connect();
5559
- await db.ensureTable();
5560
- const records = await db.getAllRecords();
5571
+ const records = await safeGetAllRecords(db);
5561
5572
  return new Set(
5562
5573
  records.filter((r) => r.status === "applied" || r.status === "skipped").map((r) => r.fileName)
5563
5574
  );