mirror of
https://github.com/withastro/astro.git
synced 2025-02-03 22:29:08 -05:00
feat: remove useForeignKey checks
This commit is contained in:
parent
f477386423
commit
06fec3dab1
2 changed files with 4 additions and 14 deletions
|
@ -71,7 +71,6 @@ function astroDBIntegration(): AstroIntegration {
|
|||
data: configWithDb.db?.data,
|
||||
logger,
|
||||
mode: command === 'dev' ? 'dev' : 'build',
|
||||
useForeignKeys: true,
|
||||
});
|
||||
logger.debug('Database setup complete.');
|
||||
|
||||
|
|
|
@ -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?.();
|
||||
|
|
Loading…
Add table
Reference in a new issue