Skip to content

Commit

Permalink
chore: raise error to indicate when new table needs to be added to li…
Browse files Browse the repository at this point in the history
…st of TABLES to drop
  • Loading branch information
bethesque committed Dec 15, 2017
1 parent f201d1d commit 26c18d9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
module PactBroker
module Database

# A manually ordered list of all the tables in the project.
# This is required so that the tables can be dropped in the right order
# without upsetting the foreign key constraints.
# I'm sure there is a better way to do this, but there are
# more urgent things that I need to spend my time on right now.

TABLES = [:labels, :webhook_executions, :triggered_webhooks, :config, :pacts, :pact_version_contents, :tags, :verifications, :pact_publications, :pact_versions, :webhook_headers, :webhooks, :versions, :pacticipants].freeze

extend self
Expand All @@ -35,6 +41,7 @@ def ensure_database_dir_exists
def drop_objects
drop_views
drop_tables
check_for_undeleted_tables
end

def drop_tables
Expand All @@ -57,6 +64,12 @@ def drop_views
end
end

def check_for_undeleted_tables
if database.tables.any?
raise "Please add the following table(s) to the list of TABLES to drop, in the file where this error was raised: #{database.tables.join(', ')}"
end
end

def create
if psql?
system('psql postgres -c "create database pact_broker"')
Expand Down

0 comments on commit 26c18d9

Please sign in to comment.