Skip to content

Commit

Permalink
postgres initialization scripts for dev and test
Browse files Browse the repository at this point in the history
also, add config/database.yml to linked_files in deploy config
  • Loading branch information
ndushay authored and jmartin-sul committed Sep 14, 2018
1 parent db58c82 commit 5a759e4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ env:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true

cache: bundler
services:
- postgresql

before_script:
- bundle exec rake travis_setup_postgres db:reset

rvm:
- 2.4.4
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem 'erubis' # implicit dependency for (old) rdf-rdfa, no longer default in Rail
gem 'honeybadger', '~> 3.1'
gem 'jquery-rails'
gem 'nokogiri'
gem 'pg' # postgres database
gem 'rails', '~> 5.2', '>= 5.2.1'
gem 'rake'
gem 'resque', '~> 1.27' # needs to match redis on VM
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ GEM
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
pg (1.1.3)
popper_js (1.14.3)
powerpack (0.1.2)
pry (0.11.3)
Expand Down Expand Up @@ -525,6 +526,7 @@ DEPENDENCIES
listen
modsulator
nokogiri
pg
pry-byebug
rails (~> 5.2, >= 5.2.1)
rails-controller-testing
Expand Down
5 changes: 4 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks

task :travis_setup_postgres do
sh("psql -f db/scripts/preassembly_test_setup.sql postgres")
end
25 changes: 8 additions & 17 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default
database: db/development.sqlite3
database: preassembly
username: preassembly

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

production:
<<: *default
database: db/production.sqlite3
database: preassembly_test
username: preassembly_test
3 changes: 1 addition & 2 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
# set :pty, true

# Default value for :linked_files is []
append :linked_files, 'config/master.key', 'config/honeybadger.yml'
# TODO: database.yml ...
append :linked_files, 'config/master.key', 'config/honeybadger.yml', 'config/database.yml'

# Default value for linked_dirs is []
# TODO: config/cli_environments can be removed after PRs addressing #169 are merged
Expand Down
5 changes: 5 additions & 0 deletions db/scripts/preassembly_setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE USER preassembly;
ALTER USER preassembly CREATEDB;
CREATE DATABASE preassembly;
ALTER DATABASE preassembly OWNER TO preassembly;
GRANT ALL PRIVILEGES ON DATABASE preassembly TO preassembly;
5 changes: 5 additions & 0 deletions db/scripts/preassembly_test_setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE USER preassembly_test;
ALTER USER preassembly_test CREATEDB;
CREATE DATABASE preassembly_test;
ALTER DATABASE preassembly_test OWNER TO preassembly_test;
GRANT ALL PRIVILEGES ON DATABASE preassembly_test TO preassembly_test;

0 comments on commit 5a759e4

Please sign in to comment.