aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/guff/database-updater.cr2
-rw-r--r--src/guff/database.cr20
2 files changed, 21 insertions, 1 deletions
diff --git a/src/guff/database-updater.cr b/src/guff/database-updater.cr
index daa3ebd..c1d4188 100644
--- a/src/guff/database-updater.cr
+++ b/src/guff/database-updater.cr
@@ -129,7 +129,7 @@ module Guff
def run
# get version from database
- db_version = @db.table_exists?("metadata") ? get_version : 0_i32
+ db_version = @db.table_exists?("metadata") ? get_version : 0
app_version = MIGRATIONS.size - 1
if db_version < app_version
diff --git a/src/guff/database.cr b/src/guff/database.cr
index 5b971b6..6882712 100644
--- a/src/guff/database.cr
+++ b/src/guff/database.cr
@@ -11,8 +11,28 @@ module Guff
WHERE type = 'table'
AND name = ?
",
+
+ pragma_foreign_keys: "
+ PRAGMA foreign_keys = true
+ ",
}
+ def initialize(path)
+ super(path)
+ query(SQL[:pragma_foreign_keys])
+ end
+
+ def initialize(path, &block)
+ super(path)
+ query(SQL[:pragma_foreign_keys])
+
+ begin
+ block.call(self)
+ ensure
+ close unless closed?
+ end
+ end
+
def table_exists?(table : String) : Bool
one(SQL[:table_exists], [table]) == table
end