0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

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

This commit is contained in:
Matthew Phillips 2024-03-27 16:30:59 -04:00 committed by GitHub
parent d43bcbeec3
commit 62a1d6df69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---
Conditionally drop table with --force-reset

View file

@ -7,6 +7,7 @@ import { hasPrimaryKey } from '../../runtime/index.js';
import {
getCreateIndexQueries,
getCreateTableQuery,
getDropTableIfExistsQuery,
getModifiers,
getReferencesConfig,
hasDefault,
@ -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;

View file

@ -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)`,
]);
});