summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2024-03-10 23:56:01 -0700
committerGravatar GitHub <noreply@github.com> 2024-03-10 23:56:01 -0700
commit41dca1e413c2f1e38f0326bd6241ccbf9b8ee0e4 (patch)
treec4a2ff17a737b588ea5ac4c93dbca60a2fa80194
parentdfdf6b3a0b50e14754abdbcc62fd714f80bf0666 (diff)
downloadastro-41dca1e413c2f1e38f0326bd6241ccbf9b8ee0e4.tar.gz
astro-41dca1e413c2f1e38f0326bd6241ccbf9b8ee0e4.tar.zst
astro-41dca1e413c2f1e38f0326bd6241ccbf9b8ee0e4.zip
handle undefined snapshot from API (#10378)
-rw-r--r--.changeset/rotten-snakes-sip.md5
-rw-r--r--packages/db/src/core/cli/commands/push/index.ts2
-rw-r--r--packages/db/src/core/cli/commands/verify/index.ts3
-rw-r--r--packages/db/src/core/cli/migration-queries.ts2
4 files changed, 8 insertions, 4 deletions
diff --git a/.changeset/rotten-snakes-sip.md b/.changeset/rotten-snakes-sip.md
new file mode 100644
index 000000000..294efd246
--- /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 c847bc1eb..990ca05b9 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 a83194599..8c480344d 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 425e81b02..1cd9345ac 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<DBSnapshot> {
+}): Promise<DBSnapshot | undefined> {
const url = new URL('/db/schema', getRemoteDatabaseUrl());
const response = await fetch(url, {