From 87ce418f12db2b61c2207d2546ade3f32c052e8f Mon Sep 17 00:00:00 2001 From: Adam Katora Date: Fri, 19 Nov 2021 22:20:23 -0500 Subject: [PATCH] refactor(stub): Enable foreign key support in SQLite config SQLite does not enforce foreign key constraints on cascade deletes / updates by default, this can be turned on with the PRAGMA foreign_keys=true command, but that must be run each time a database connection is established. This changes the default SQLite connection to enable foreign key support so that .onDelete() and .onUpdate methods work as expected --- templates/database.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/database.txt b/templates/database.txt index 473b3604..ce904039 100644 --- a/templates/database.txt +++ b/templates/database.txt @@ -42,6 +42,11 @@ const databaseConfig: DatabaseConfig = { connection: { filename: Application.tmpPath('db.sqlite3'), }, + pool: { + afterCreate: (conn, cb) => { + conn.run('PRAGMA foreign_keys=true', cb) + } + }, migrations: { naturalSort: true, },