Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ group :development, :test do
gem 'pry-byebug'
gem 'rspec-rails', '~> 3.5.2'
gem 'slim_lint'
gem 'strong_migrations'
gem 'thin'
end

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stringex (2.8.4)
strong_migrations (0.2.2)
activerecord (>= 3.2.0)
sysexits (1.2.0)
systemu (2.6.5)
temple (0.8.0)
Expand Down Expand Up @@ -744,6 +746,7 @@ DEPENDENCIES
slim-rails
slim_lint
stringex
strong_migrations
thin
timecop
twilio-ruby
Expand Down
3 changes: 3 additions & 0 deletions config/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ development:
database_pool_worker: '5'
database_readonly_password: ''
database_readonly_username: ''
database_statement_timeout: '2500'
database_timeout: '5000'
database_username: ''
domain_name: 'localhost:3000'
Expand Down Expand Up @@ -175,6 +176,7 @@ production:
basic_auth_password:
disable_email_sending: 'false'
dashboard_api_token:
database_statement_timeout: '2500'
domain_name: 'login.gov'
enable_agency_based_uuids: 'true'
enable_identity_verification: 'false'
Expand Down Expand Up @@ -268,6 +270,7 @@ test:
database_pool_worker:
database_readonly_password: ''
database_readonly_username: ''
database_statement_timeout: '2500'
database_timeout: '5000'
database_username: ''
dashboard_api_token: '123ABC'
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defaults: &defaults
checkout_timeout: 5
reaping_frequency: 10
variables:
statement_timeout: 2500 # ms
statement_timeout: <%= Figaro.env.database_statement_timeout.to_i %>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add validation somewhere that database_statement_timeout is present? Looks like if it's nil this will set the timeout to 0, not sure what effect that will have.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Will add it to figaro.rb.


development:
<<: *defaults
Expand Down
1 change: 1 addition & 0 deletions config/initializers/figaro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Figaro.require_keys(
'attribute_cost',
'attribute_encryption_key',
'database_statement_timeout',
'domain_name',
'enable_agency_based_uuids',
'enable_identity_verification',
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/safe_migrations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'deploy/migration_statement_timeout'

ActiveSupport.on_load(:active_record) do
ActiveRecord::Migration.prepend(Deploy::MigrationStatementTimeout)
end
24 changes: 24 additions & 0 deletions deploy/migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# This script is called by identity-devops cookbooks as part of the deployment
# process. It runs any pending migrations.

set -euo pipefail

echo "deploy/migrate starting"
echo "HOME: ${HOME-}"
cd "$(dirname "$0")/.."

set -x

id
which bundle

export RAILS_ENV=production
export MIGRATION_STATEMENT_TIMEOUT=60000

bundle exec rake db:create db:migrate db:seed --trace

set +x

echo "deploy/migrate finished"
13 changes: 13 additions & 0 deletions lib/deploy/migration_statement_timeout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Deploy
module MigrationStatementTimeout
def connection
connection = super
new_statement_timeout = ENV['MIGRATION_STATEMENT_TIMEOUT']
if new_statement_timeout && !@migration_statement_timeout_set
connection.execute("SET statement_timeout = #{new_statement_timeout.to_i}")
@migration_statement_timeout_set = true
end
connection
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
add_filter '/config/'
add_filter '/lib/rspec/formatters/user_flow_formatter.rb'
add_filter '/lib/user_flow_exporter.rb'
add_filter '/lib/deploy/migration_statement_timeout.rb'
end
end

Expand Down