From 41dca1e413c2f1e38f0326bd6241ccbf9b8ee0e4 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sun, 10 Mar 2024 23:56:01 -0700 Subject: [PATCH] handle undefined snapshot from API (#10378) --- .changeset/rotten-snakes-sip.md | 5 +++++ packages/db/src/core/cli/commands/push/index.ts | 2 +- packages/db/src/core/cli/commands/verify/index.ts | 3 +-- packages/db/src/core/cli/migration-queries.ts | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .changeset/rotten-snakes-sip.md diff --git a/.changeset/rotten-snakes-sip.md b/.changeset/rotten-snakes-sip.md new file mode 100644 index 000000000000..294efd246daa --- /dev/null +++ b/.changeset/rotten-snakes-sip.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": patch +--- + +Handle new schema API response format diff --git a/packages/db/src/core/cli/commands/push/index.ts b/packages/db/src/core/cli/commands/push/index.ts index c847bc1eba2b..990ca05b9198 100644 --- a/packages/db/src/core/cli/commands/push/index.ts +++ b/packages/db/src/core/cli/commands/push/index.ts @@ -25,7 +25,7 @@ export async function cmd({ const appToken = await getManagedAppTokenOrExit(flags.token); const productionSnapshot = await getProductionCurrentSnapshot({ appToken: appToken.token }); const currentSnapshot = createCurrentSnapshot(dbConfig); - const isFromScratch = isForceReset || JSON.stringify(productionSnapshot) === '{}'; + const isFromScratch = isForceReset || !productionSnapshot; const { queries: migrationQueries, confirmations } = await getMigrationQueries({ oldSnapshot: isFromScratch ? createEmptySnapshot() : productionSnapshot, newSnapshot: currentSnapshot, diff --git a/packages/db/src/core/cli/commands/verify/index.ts b/packages/db/src/core/cli/commands/verify/index.ts index a83194599fe4..8c480344da86 100644 --- a/packages/db/src/core/cli/commands/verify/index.ts +++ b/packages/db/src/core/cli/commands/verify/index.ts @@ -23,8 +23,7 @@ export async function cmd({ const productionSnapshot = await getProductionCurrentSnapshot({ appToken: appToken.token }); const currentSnapshot = createCurrentSnapshot(dbConfig); const { queries: migrationQueries, confirmations } = await getMigrationQueries({ - oldSnapshot: - JSON.stringify(productionSnapshot) !== '{}' ? productionSnapshot : createEmptySnapshot(), + oldSnapshot: productionSnapshot || createEmptySnapshot(), newSnapshot: currentSnapshot, }); diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts index 425e81b02106..1cd9345acaaf 100644 --- a/packages/db/src/core/cli/migration-queries.ts +++ b/packages/db/src/core/cli/migration-queries.ts @@ -423,7 +423,7 @@ export async function getProductionCurrentSnapshot({ appToken, }: { appToken: string; -}): Promise { +}): Promise { const url = new URL('/db/schema', getRemoteDatabaseUrl()); const response = await fetch(url, {