Skip to content

Commit

Permalink
Merge pull request #36 from hkim3162/additional_changes_to_prodder_ra…
Browse files Browse the repository at this point in the history
…ils_upgrade

change db config back to active record config
  • Loading branch information
rnubel authored and kaisen-san committed Nov 19, 2024
2 parents 2178135 + f9c3351 commit 48b0e4e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
47 changes: 31 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,53 @@ jobs:
ruby-version: [2.6, 2.7, 3.0]
services:
postgres:
image: postgres:12.1-alpine
image: postgres:15
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout Project
uses: actions/checkout@v3

uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Install Library Dependencies
run: sudo apt-get install libpq-dev

- name: Setup Database
- name: Create Database Config
run: |
cp config/database.yml.github-actions config/database.yml
env:
RAILS_ENV: test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

cat <<EOF > config/database.yml
test:
adapter: postgresql
encoding: unicode
pool: 20
database: prodder__blog_prod
migration_user: prodder
EOF
- name: Test with RSpec
env:
RAILS_ENV: "test"
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGHOST: localhost
PGPORT: 5432
PGDATABASE: prodder__blog_prod
PGUSER: postgres
PGPASSWORD: postgres
run: |
bundle exec rspec
- name: Test with Cucumber
env:
PGHOST: localhost
PGPORT: 5432
PGDATABASE: prodder__blog_prod
PGUSER: postgres
PGPASSWORD: postgres
run: |
bundle exec cucumber
8 changes: 0 additions & 8 deletions config/database.yml.github-actions

This file was deleted.

2 changes: 1 addition & 1 deletion features/step_definitions/prodder_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
db:
name: prodder__#{name}_prod
host: localhost
user: prodder
user: postgres
tables:
- posts
- authors
Expand Down
18 changes: 9 additions & 9 deletions lib/prodder/prodder.rake
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace :db do
desc "Load db/structure.sql into the current environment's database"
task :load => dependencies do
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env]
config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/structure.sql into database '#{config['database']}'"
`psql --no-psqlrc -f db/structure.sql #{Shellwords.escape(config['database'])}`
Expand All @@ -217,7 +217,7 @@ namespace :db do
task :seed => dependencies do
if File.exist?('db/seeds.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env]
config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/seeds.sql into database '#{config['database']}'"
`psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}`
Expand All @@ -232,7 +232,7 @@ namespace :db do
task :quality_check => dependencies do
if File.exist?('db/quality_checks.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env]
config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/quality_checks.sql into database '#{config['database']}'"
`psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}`
Expand All @@ -247,7 +247,7 @@ namespace :db do
task :permission => dependencies do
if File.exist?('db/permissions.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env]
config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/permissions.sql into database '#{config['database']}'"
result = ActiveRecord::Base.connection.execute(<<-SQL).first
Expand All @@ -268,7 +268,7 @@ namespace :db do
task :settings => dependencies do
if File.exist?('db/settings.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env]
config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/settings.sql into database '#{config['database']}'"
result = ActiveRecord::Base.connection.execute(<<-SQL).first
Expand Down Expand Up @@ -362,19 +362,19 @@ namespace :db do

def as(user, opts = {}, &block)
if File.exist?('db/permissions.sql')
config, config_was = Rails.configuration.database_configuration.deep_dup.to_h, Rails.configuration.database_configuration.deep_dup
config, config_was = Rails.configuration.database_configuration, ActiveRecord::Base.configurations.deep_dup
in_env = Array(opts[:in]) || config.keys
if config.all? { |env, config_hash| in_env.include?(env) ? config_hash[user] : true }
disconnect
config.each { |env, config_hash| config_hash["username"] = config_hash[user] if in_env.include?(env) }
Rails.configuration.database_configuration = config
ActiveRecord::Base.configurations = config
end
else
puts "No permissions file (db/permissions.sql) found, running everything in context of user"
end
yield
ensure
Rails.configuration.database_configuration = config_was if config_was
ActiveRecord::Base.configurations = config_was if config_was
in_env.each { |env| ActiveRecord::Base.establish_connection(env.intern) } if in_env
end

Expand All @@ -393,5 +393,5 @@ end

# Yes, I really want migrations to run against the test DB.
Rake::Task['db:migrate'].actions.unshift(proc {
ActiveRecord::Base.establish_connection(Rails.configuration.database_configuration[(ENV['RAILS_ENV'] || Rails.env).to_sym])
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access)
})
2 changes: 1 addition & 1 deletion lib/prodder/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Prodder
VERSION = "1.8.0"
VERSION = "1.8.1"
end

0 comments on commit 48b0e4e

Please sign in to comment.