From 41ca94e5136a80a58d000f3eb87029442599a4a3 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Tue, 12 Mar 2024 07:30:45 -0400 Subject: [PATCH] chore: remove drop table check for added table (#10396) * chore: remove drop table check for added table * chore: remove drop table from test * chore: changeset --- .changeset/lazy-tools-reply.md | 5 +++++ packages/db/src/core/cli/migration-queries.ts | 1 - packages/db/test/unit/column-queries.test.js | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .changeset/lazy-tools-reply.md diff --git a/.changeset/lazy-tools-reply.md b/.changeset/lazy-tools-reply.md new file mode 100644 index 000000000000..fbde70cd5481 --- /dev/null +++ b/.changeset/lazy-tools-reply.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": patch +--- + +Remove risk of data loss when pushing an out-of-date table schema. diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts index 81911faaef36..0301d2e11945 100644 --- a/packages/db/src/core/cli/migration-queries.ts +++ b/packages/db/src/core/cli/migration-queries.ts @@ -61,7 +61,6 @@ export async function getMigrationQueries({ } for (const [collectionName, collection] of Object.entries(addedCollections)) { - queries.push(getDropTableIfExistsQuery(collectionName)); queries.push(getCreateTableQuery(collectionName, collection)); queries.push(...getCreateIndexQueries(collectionName, collection)); } diff --git a/packages/db/test/unit/column-queries.test.js b/packages/db/test/unit/column-queries.test.js index c4b07a493786..d7f65dff2735 100644 --- a/packages/db/test/unit/column-queries.test.js +++ b/packages/db/test/unit/column-queries.test.js @@ -53,7 +53,6 @@ describe('column queries', () => { const newCollections = { [TABLE_NAME]: userInitial }; const { queries } = await configChangeQueries(oldCollections, newCollections); expect(queries).to.deep.equal([ - `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)`, ]); });