Skip to content

Commit

Permalink
fix: correctly identify database version when schema_migrations table…
Browse files Browse the repository at this point in the history
… is empty
  • Loading branch information
bethesque committed Aug 30, 2022
1 parent 69d9e07 commit dcb5920
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/pact_broker/db/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ module DB
class Version
def self.call database_connection
if database_connection.tables.include?(:schema_migrations)
last_migration_filename = database_connection[:schema_migrations].order(:filename).last[:filename]
last_migration_filename.split("_", 2).first.to_i
version_from_schema_migrations(database_connection)
elsif database_connection.tables.include?(:schema_info)
database_connection[:schema_info].first[:version]
version_from_schema_info(database_connection)
else
0
end
end

private_class_method def self.version_from_schema_migrations(database_connection)
last_migration = database_connection[:schema_migrations].order(:filename).last
if last_migration
last_migration[:filename].split("_", 2).first.to_i
else
0
end
end

private_class_method def self.version_from_schema_info(database_connection)
schema_info = database_connection[:schema_info].first
if schema_info
schema_info[:version]
else
0
end
Expand Down

0 comments on commit dcb5920

Please sign in to comment.