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:
parent
d43bcbeec3
commit
62a1d6df69
3 changed files with 8 additions and 2 deletions
5
.changeset/ninety-islands-deny.md
Normal file
5
.changeset/ninety-islands-deny.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@astrojs/db": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Conditionally drop table with --force-reset
|
|
@ -7,6 +7,7 @@ import { hasPrimaryKey } from '../../runtime/index.js';
|
||||||
import {
|
import {
|
||||||
getCreateIndexQueries,
|
getCreateIndexQueries,
|
||||||
getCreateTableQuery,
|
getCreateTableQuery,
|
||||||
|
getDropTableIfExistsQuery,
|
||||||
getModifiers,
|
getModifiers,
|
||||||
getReferencesConfig,
|
getReferencesConfig,
|
||||||
hasDefault,
|
hasDefault,
|
||||||
|
@ -455,7 +456,7 @@ export async function getProductionCurrentSnapshot({
|
||||||
function getDropTableQueriesForSnapshot(snapshot: DBSnapshot) {
|
function getDropTableQueriesForSnapshot(snapshot: DBSnapshot) {
|
||||||
const queries = [];
|
const queries = [];
|
||||||
for (const tableName of Object.keys(snapshot.schema)) {
|
for (const tableName of Object.keys(snapshot.schema)) {
|
||||||
const dropQuery = `DROP TABLE ${sqlite.escapeName(tableName)}`;
|
const dropQuery = getDropTableIfExistsQuery(tableName);
|
||||||
queries.unshift(dropQuery);
|
queries.unshift(dropQuery);
|
||||||
}
|
}
|
||||||
return queries;
|
return queries;
|
||||||
|
|
|
@ -32,7 +32,7 @@ describe('force reset', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(queries).to.deep.equal([
|
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)`,
|
`CREATE TABLE "${TABLE_NAME}" (_id INTEGER PRIMARY KEY, "name" text NOT NULL, "age" integer NOT NULL, "email" text NOT NULL UNIQUE, "mi" text)`,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue