diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-06 17:05:47 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-06 17:05:47 -0500 |
commit | 5a57a15f5e154b2e2dc312b1e92600449c6ca1f9 (patch) | |
tree | b97f20ca2e22f187be198564cc5bee52c10d0480 /src/guff | |
parent | 171cd044d70e2799a3f02f331e4585c91e3156b6 (diff) | |
download | old-guff-5a57a15f5e154b2e2dc312b1e92600449c6ca1f9.tar.bz2 old-guff-5a57a15f5e154b2e2dc312b1e92600449c6ca1f9.zip |
enforce foreign keys
Diffstat (limited to 'src/guff')
-rw-r--r-- | src/guff/database-updater.cr | 2 | ||||
-rw-r--r-- | src/guff/database.cr | 20 |
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 |