Skip to content

Commit

Permalink
feat: run data migrations on startup to ensure data created by old no…
Browse files Browse the repository at this point in the history
…des is migrated when performing a rolling update
  • Loading branch information
bethesque committed Jul 31, 2018
1 parent 1bf61af commit ec59ba5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/pact_broker/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def prepare_database
else
logger.info "Skipping database migrations"
end

if configuration.auto_migrate_db_data
logger.info "Migrating data"
PactBroker::DB.run_data_migrations configuration.database_connection
else
logger.info "Skipping data migrations"
end

require 'pact_broker/webhooks/service'
PactBroker::Webhooks::Service.fail_retrying_triggered_webhooks
end
Expand Down
3 changes: 2 additions & 1 deletion lib/pact_broker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Configuration
:base_equality_only_on_content_that_affects_verification_results
]

attr_accessor :log_dir, :database_connection, :auto_migrate_db, :use_hal_browser, :html_pact_renderer
attr_accessor :log_dir, :database_connection, :auto_migrate_db, :auto_migrate_db_data, :use_hal_browser, :html_pact_renderer
attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints, :version_parser, :sha_generator
attr_accessor :use_case_sensitive_resource_names, :order_versions_by_date
attr_accessor :check_for_potential_duplicate_pacticipant_names
Expand Down Expand Up @@ -63,6 +63,7 @@ def self.default_configuration
config = Configuration.new
config.log_dir = File.expand_path("./log")
config.auto_migrate_db = true
config.auto_migrate_db_data = true
config.use_hal_browser = true
config.validate_database_connection_config = true
config.enable_diagnostic_endpoints = true
Expand Down
6 changes: 6 additions & 0 deletions lib/pact_broker/db.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'sequel'
require 'pact_broker/db/validate_encoding'
require 'pact_broker/db/migrate'
require 'pact_broker/db/migrate_data'

Sequel.datetime_class = DateTime

Expand All @@ -21,6 +23,10 @@ def self.run_migrations database_connection
Sequel::TimestampMigrator.new(database_connection, PactBroker::DB::MIGRATIONS_DIR).run
end

def self.run_data_migrations database_connection
PactBroker::DB::MigrateData.(connection)
end

def self.validate_connection_config
PactBroker::DB::ValidateEncoding.(connection)
end
Expand Down
9 changes: 9 additions & 0 deletions lib/pact_broker/db/migrate_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module PactBroker
module DB
class MigrateData
def self.call database_connection, options = {}

end
end
end
end

0 comments on commit ec59ba5

Please sign in to comment.