Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Jan 18, 2024
1 parent 6ecd0c3 commit b1e3fe4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,19 @@ def sqlite?

# Require our gem
require 'closure_tree'

ActiveRecord::Tasks::DatabaseTasks.drop_current(:primary)
begin
ActiveRecord::Base.establish_connection(:primary)
rescue
ActiveRecord::Tasks::DatabaseTasks.create_current('primary')
ActiveRecord::Tasks::DatabaseTasks.create_current(:primary)
end

ActiveRecord::Tasks::DatabaseTasks.drop_current(:secondary)
begin
ActiveRecord::Base.establish_connection(:secondary)
ActiveRecord::Base.database_exists?(:secondary)
rescue
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary')
ActiveRecord::Tasks::DatabaseTasks.create_current(:secondary)
end

# Load test helpers
Expand Down
5 changes: 4 additions & 1 deletion spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

connects_to database: { writing: :primary, reading: :primary }
end

class SecondDatabaseRecord < ActiveRecord::Base
self.abstract_class = true

establish_connection :secondary
connects_to database: { writing: :secondary, reading: :secondary }
end

ActiveRecord::Schema.define(version: 0) do
Expand Down Expand Up @@ -151,6 +153,7 @@ class SecondDatabaseRecord < ActiveRecord::Base
add_foreign_key(:tag_hierarchies, :tags, column: 'descendant_id', on_delete: :cascade)
end

SecondDatabaseRecord.establish_connection
SecondDatabaseRecord.connection_pool.with_connection do |connection|
ActiveRecord::Schema.define(version: 0) do
connection.create_table 'menu_items', force: :cascade do |t|
Expand Down

0 comments on commit b1e3fe4

Please sign in to comment.