Skip to content

Commit

Permalink
Add support Rails 6.0 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavSokov authored Jun 14, 2024
1 parent 2cc7cdf commit 91b4959
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
strategy:
matrix:
include:
- { ruby: '2.7', rails: '6.0' }
- { ruby: '2.7', rails: '6.1' }
- { ruby: '3.0', rails: '6.1' }
- { ruby: '3.1', rails: '7.0' }
Expand Down
9 changes: 7 additions & 2 deletions lib/actual_db_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def self.default_migrated_folder
end

def self.migrations_paths
ActiveRecord::Base.connection_db_config.migrations_paths
if ActiveRecord::Base.respond_to?(:connection_db_config)
ActiveRecord::Base.connection_db_config.migrations_paths
else
ActiveRecord::Base.connection_config[:migrations_paths]
end
end

def self.migration_filename(fullpath)
Expand All @@ -60,7 +64,8 @@ def self.migration_filename(fullpath)
def self.for_each_db_connection
configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
configs.each do |db_config|
ActiveRecord::Base.establish_connection(db_config)
config = db_config.respond_to?(:config) ? db_config.config : db_config
ActiveRecord::Base.establish_connection(config)
yield
end
end
Expand Down
11 changes: 10 additions & 1 deletion lib/actual_db_schema/commands/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ def preambule
puts "\nPhantom migrations\n\n"
puts "Below is a list of irrelevant migrations executed in unmerged branches."
puts "To bring your database schema up to date, the migrations marked as \"up\" should be rolled back."
puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.database}\n\n"
database_path = db_config[:database]
puts "\ndatabase: #{database_path}\n\n"
puts header.join(" ")
puts "-" * separator_width
end

def db_config
if ActiveRecord::Base.respond_to?(:connection_db_config)
ActiveRecord::Base.connection_db_config.configuration_hash
else
ActiveRecord::Base.connection_config
end
end

def separator_width
header.map(&:length).sum + (header.size - 1) * 2
end
Expand Down
11 changes: 11 additions & 0 deletions test/dummy_app/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test:
primary:
adapter: sqlite3
database: tmp/primary.sqlite3
migrations_paths:
- <%= Rails.root.join('db', 'migrate').to_s %>
secondary:
adapter: sqlite3
database: tmp/secondary.sqlite3
migrations_paths:
- <%= Rails.root.join('db', 'migrate_secondary').to_s %>
7 changes: 4 additions & 3 deletions test/dummy_app/db/secondary_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2013_09_06_111513) do
ActiveRecord::Schema.define(version: 2013_09_06_111515) do

end

0 comments on commit 91b4959

Please sign in to comment.