From 262479663d607966fadc06ee44c6191d0dce88ed Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 18 Feb 2022 00:04:44 -0500 Subject: dbstore: add enableForeignKeys() --- dbstore/dbstore.go | 10 ++++++++-- 1 file 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 -- cgit v1.2.3