Skip to content

Commit

Permalink
handle undefined snapshot from API
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Mar 10, 2024
1 parent dfdf6b3 commit 850c89e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-snakes-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Handle new schema API response format
2 changes: 1 addition & 1 deletion packages/db/src/core/cli/commands/push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/core/cli/commands/verify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/core/cli/migration-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 850c89e

Please sign in to comment.