aboutsummaryrefslogtreecommitdiff
path: root/dbstore
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-18 00:04:44 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-18 00:04:44 -0500
commit262479663d607966fadc06ee44c6191d0dce88ed (patch)
treed496b7b952b6045146d67633ec8b29f711368aea /dbstore
parentd3ae0601b33a6cb73301e664dd1cceb2faf96df3 (diff)
downloadcvez-262479663d607966fadc06ee44c6191d0dce88ed.tar.bz2
cvez-262479663d607966fadc06ee44c6191d0dce88ed.zip
dbstore: add enableForeignKeys()
Diffstat (limited to 'dbstore')
-rw-r--r--dbstore/dbstore.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/dbstore/dbstore.go b/dbstore/dbstore.go
index d30d0a8..25c3564 100644
--- a/dbstore/dbstore.go
+++ b/dbstore/dbstore.go
@@ -56,13 +56,19 @@ func (me DbStore) isInitialized(ctx context.Context) (bool, error) {
return (version == initDbVersion), nil
}
+// enable foreign keys
+func (me DbStore) enableForeignKeys(ctx context.Context) error {
+ _, err := me.db.ExecContext(ctx, "PRAGMA foreign_keys = true;")
+ return err
+}
+
// initialize database
func (me DbStore) Init(ctx context.Context) error {
if inited, err := me.isInitialized(ctx); err != nil {
return err
} else if inited {
- // already initialized, return success
- return nil
+ // already initialized, enable foreign keys
+ return me.enableForeignKeys(ctx)
}
// read init query