diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2017-01-17 15:24:17 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 15:24:17 +0000 |
commit | d665c611096ece7579475e381bfe45235515e8fb (patch) | |
tree | 353403787a9b5ec77cbea0606fd10282bc60ba53 /activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | |
parent | ab91a2be3aef3e2ca3bf4201186cde0afbbf7cf5 (diff) | |
parent | 24f264e9ca0f1ce3b16392b8ee6360480251f556 (diff) | |
download | rails-d665c611096ece7579475e381bfe45235515e8fb.tar.gz rails-d665c611096ece7579475e381bfe45235515e8fb.tar.bz2 rails-d665c611096ece7579475e381bfe45235515e8fb.zip |
Merge pull request #24743 from kamipo/sqlite_foreing_key_support
SQLite: Foreign Key Support
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 2e3419991e..ca6de37a6b 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -130,6 +130,10 @@ module ActiveRecord true end + def supports_foreign_keys_in_create? + sqlite_version >= "3.6.19" + end + def supports_views? true end @@ -439,6 +443,19 @@ module ActiveRecord rename_column_indexes(table_name, column.name, new_column_name) end + def foreign_keys(table_name) + fk_info = select_all("PRAGMA foreign_key_list(#{quote(table_name)})", "SCHEMA") + fk_info.map do |row| + options = { + column: row["from"], + primary_key: row["to"], + on_delete: extract_foreign_key_action(row["on_delete"]), + on_update: extract_foreign_key_action(row["on_update"]) + } + ForeignKeyDefinition.new(table_name, row["table"], options) + end + end + private def table_structure(table_name) @@ -592,6 +609,14 @@ module ActiveRecord SQLite3::TableDefinition.new(*args) end + def extract_foreign_key_action(specifier) + case specifier + when "CASCADE"; :cascade + when "SET NULL"; :nullify + when "RESTRICT"; :restrict + end + end + def configure_connection execute("PRAGMA foreign_keys = ON", "SCHEMA") end |