Skip to content

Commit

Permalink
refactor(stub): Enable foreign key support in SQLite config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
akatora28 authored Nov 20, 2021
1 parent 459a84e commit 87ce418
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions templates/database.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 87ce418

Please sign in to comment.