Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For --force-reset use conditional drop table query #10587

Merged
merged 1 commit into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-islands-deny.md
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Conditionally drop table with --force-reset
3 changes: 2 additions & 1 deletion packages/db/src/core/cli/migration-queries.ts
Expand Up @@ -7,6 +7,7 @@ import { hasPrimaryKey } from '../../runtime/index.js';
import {
getCreateIndexQueries,
getCreateTableQuery,
getDropTableIfExistsQuery,
getModifiers,
getReferencesConfig,
hasDefault,
Expand Down Expand Up @@ -455,7 +456,7 @@ export async function getProductionCurrentSnapshot({
function getDropTableQueriesForSnapshot(snapshot: DBSnapshot) {
const queries = [];
for (const tableName of Object.keys(snapshot.schema)) {
const dropQuery = `DROP TABLE ${sqlite.escapeName(tableName)}`;
const dropQuery = getDropTableIfExistsQuery(tableName);
queries.unshift(dropQuery);
}
return queries;
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/unit/reset-queries.test.js
Expand Up @@ -32,7 +32,7 @@ describe('force reset', () => {
});

expect(queries).to.deep.equal([
`DROP TABLE "${TABLE_NAME}"`,
`DROP TABLE IF EXISTS "${TABLE_NAME}"`,
`CREATE TABLE "${TABLE_NAME}" (_id INTEGER PRIMARY KEY, "name" text NOT NULL, "age" integer NOT NULL, "email" text NOT NULL UNIQUE, "mi" text)`,
]);
});
Expand Down