Skip to content

Commit 81511c1

Browse files
committed
TECH-4995: generalize rails_4 exception to sqlite
1 parent 266c828 commit 81511c1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/declare_schema/model/index_definition.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class << self
3737
def for_model(model, old_table_name = nil)
3838
t = old_table_name || model.table_name
3939

40-
primary_key_columns = Array(model.connection.primary_key(t)).presence || rails_4_compound_primary_key(model, t) or
40+
primary_key_columns = Array(model.connection.primary_key(t)).presence || sqlite_compound_primary_key(model, t) or
4141
raise "could not find primary key for table #{t} in #{model.connection.columns(t).inspect}"
4242

4343
primary_key_found = false
@@ -62,9 +62,9 @@ def for_model(model, old_table_name = nil)
6262

6363
private
6464

65-
# This is the old approach for Rails 4. Delete it when we drop support!
66-
def rails_4_compound_primary_key(model, table)
67-
Rails::VERSION::MAJOR >= 5 and return nil
65+
# This is the old approach which is still needed for SQLite, at least through Rails 5
66+
def sqlite_compound_primary_key(model, table)
67+
!ActiveRecord::Base.connection.class.name.match?(/SQLite3Adapter/) || Rails::VERSION::MAJOR > 5 and return nil
6868

6969
connection = model.connection.dup
7070

0 commit comments

Comments
 (0)