From 06fec3dab1ce45394863fa0dfa80ed4aa6e5ef44 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 6 Feb 2024 17:27:35 -0500 Subject: [PATCH] feat: remove useForeignKey checks --- packages/db/src/core/integration/index.ts | 1 - packages/db/src/core/queries.ts | 17 ++++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts index 523d4e6ebb..c627cd12ee 100644 --- a/packages/db/src/core/integration/index.ts +++ b/packages/db/src/core/integration/index.ts @@ -71,7 +71,6 @@ function astroDBIntegration(): AstroIntegration { data: configWithDb.db?.data, logger, mode: command === 'dev' ? 'dev' : 'build', - useForeignKeys: true, }); logger.debug('Database setup complete.'); diff --git a/packages/db/src/core/queries.ts b/packages/db/src/core/queries.ts index d64149ee84..06ea43be18 100644 --- a/packages/db/src/core/queries.ts +++ b/packages/db/src/core/queries.ts @@ -26,19 +26,17 @@ export async function setupDbTables({ logger, mode, // TODO: Remove once Turso has foreign key PRAGMA support - useForeignKeys = false, }: { db: SqliteRemoteDatabase; data?: DBUserConfig['data']; collections: DBCollections; logger?: AstroIntegrationLogger; mode: 'dev' | 'build'; - useForeignKeys?: boolean; }) { const setupQueries: SQL[] = []; for (const [name, collection] of Object.entries(collections)) { const dropQuery = sql.raw(`DROP TABLE IF EXISTS ${name}`); - const createQuery = sql.raw(getCreateTableQuery(name, collection, useForeignKeys)); + const createQuery = sql.raw(getCreateTableQuery(name, collection)); const indexQueries = getCreateIndexQueries(name, collection); setupQueries.push(dropQuery, createQuery, ...indexQueries.map((s) => sql.raw(s))); } @@ -72,12 +70,7 @@ export async function setupDbTables({ } } -export function getCreateTableQuery( - collectionName: string, - collection: DBCollection, - // TODO: Remove once Turso has foreign key PRAGMA support - useForeignKeys = false -) { +export function getCreateTableQuery(collectionName: string, collection: DBCollection) { let query = `CREATE TABLE ${sqlite.escapeName(collectionName)} (`; const colQueries = []; @@ -94,9 +87,7 @@ export function getCreateTableQuery( colQueries.push(colQuery); } - if (useForeignKeys) { - colQueries.push(...getCreateForeignKeyQueries(collectionName, collection)); - } + colQueries.push(...getCreateForeignKeyQueries(collectionName, collection)); query += colQueries.join(', ') + ')'; return query; @@ -191,7 +182,7 @@ export function getModifiers(fieldName: string, field: DBField) { return modifiers; } -function getReferencesConfig(field: DBField) { +export function getReferencesConfig(field: DBField) { const canHaveReferences = field.type === 'number' || field.type === 'text'; if (!canHaveReferences) return undefined; return field.references?.();