File tree 2 files changed +19
-4
lines changed
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -81,11 +81,18 @@ def post_configure
81
81
end
82
82
83
83
def prepare_database
84
+ logger . info "Database schema version is #{ PactBroker ::DB . version ( configuration . database_connection ) } "
84
85
if configuration . auto_migrate_db
85
- logger . info "Migrating database"
86
- PactBroker ::DB . run_migrations configuration . database_connection , allow_missing_migration_files : configuration . allow_missing_migration_files
86
+ migration_options = { allow_missing_migration_files : configuration . allow_missing_migration_files }
87
+ if PactBroker ::DB . is_current? ( configuration . database_connection , migration_options )
88
+ logger . info "Skipping database migrations as the latest migration has already been applied"
89
+ else
90
+ logger . info "Migrating database schema"
91
+ PactBroker ::DB . run_migrations configuration . database_connection , migration_options
92
+ logger . info "Database schema version is now #{ PactBroker ::DB . version ( configuration . database_connection ) } "
93
+ end
87
94
else
88
- logger . info "Skipping database migrations"
95
+ logger . info "Skipping database schema migrations as database auto migrate is disabled "
89
96
end
90
97
91
98
if configuration . auto_migrate_db_data
Original file line number Diff line number Diff line change 2
2
require 'pact_broker/db/validate_encoding'
3
3
require 'pact_broker/db/migrate'
4
4
require 'pact_broker/db/migrate_data'
5
+ require 'pact_broker/db/version'
5
6
6
7
Sequel . datetime_class = DateTime
7
8
8
9
module PactBroker
9
10
module DB
10
-
11
11
MIGRATIONS_DIR = File . expand_path ( "../../../db/migrations" , __FILE__ )
12
12
13
13
def self . connection = connection
@@ -27,6 +27,14 @@ def self.run_data_migrations database_connection
27
27
PactBroker ::DB ::MigrateData . ( database_connection )
28
28
end
29
29
30
+ def self . is_current? database_connection , options = { }
31
+ Sequel ::TimestampMigrator . is_current? ( database_connection , PactBroker ::DB ::MIGRATIONS_DIR , options )
32
+ end
33
+
34
+ def self . version database_connection
35
+ PactBroker ::DB ::Version . call ( database_connection )
36
+ end
37
+
30
38
def self . validate_connection_config
31
39
PactBroker ::DB ::ValidateEncoding . ( connection )
32
40
end
You can’t perform that action at this time.
0 commit comments