Skip to content

Commit

Permalink
ignore fts5 tables when dumping schema in AR fixes #115
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmoe committed May 29, 2024
1 parent b533c5c commit 9cdf123
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/litestack/litesearch/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def self.included(klass)
klass.extend Litesearch::Model::ActiveRecordClassMethods
ActiveRecord::Base.extend Litesearch::Model::BaseClassMethods
Litesearch::Schema.prepend Litesearch::Model::ActiveRecordSchemaMethods
# ignore FTS5 virtual and shadow tables when dumping the schema
ActiveRecord::SchemaDumper.ignore_tables << /^#{klass.table_name}_search_idx.*$/
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/litestack/litesearch/schema_adapters/backed_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_primary_triggers_sql(active = false)
when_stmt = "NEW.#{filter} = TRUE"
cols << filter
end
update_filter = ""
update_filter = String.new
if cols.length > 0
" OF #{cols.join(', ')} "
end
Expand Down Expand Up @@ -82,7 +82,7 @@ def create_secondary_trigger_poly_sql(target_table, target_col, col, conditions)


def drop_secondary_triggers_sql
sql = ""
sql = String.new
@schema[:fields].each do |name, field|
if field[:trigger_sql]
if field[:col]
Expand All @@ -96,7 +96,7 @@ def drop_secondary_triggers_sql
end

def create_secondary_triggers_sql
sql = ""
sql = String.new
@schema[:fields].each do |name, field|
if field[:trigger_sql]
if field[:col]
Expand Down Expand Up @@ -145,7 +145,7 @@ def enrich_schema
end

def filter_sql
sql = ""
sql = String.new
sql << " WHERE #{@schema[:filter_column]} = TRUE " if @schema[:filter_column]
sql
end
Expand All @@ -166,7 +166,7 @@ def joins_sql
joins = [@schema[:table]]
active_fields.each do |name, field|
if field[:trigger_sql]
join_table = ""
join_table = String.new
join_table << "#{field[:target_table]} AS #{field[:target_table_alias]} ON "
if field[:col]
join_table << "#{field[:target_table_alias]}.id = #{@schema[:table]}.#{field[:col]}" if field[:col]
Expand Down
6 changes: 6 additions & 0 deletions test/test_ar_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,10 @@ def test_uncreated_table
assert_equal 2, rs.length
end

def test_ignore_tables
assert_equal false, ActiveRecord::SchemaDumper.ignore_tables.empty?
# we have created 6 models, one ignore regex for each
assert_equal 6, ActiveRecord::SchemaDumper.ignore_tables.count
end

end

0 comments on commit 9cdf123

Please sign in to comment.