Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Avoid expectation of dropped output by using IF EXISTS (#8285)

Oliver Güntherff0620c81dc2
diff --git a/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres b/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres
index 917c1b60dd3..97a6a484d7d 100755
--- a/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres
+++ b/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres
@@ -89,12 +89,12 @@ end
unless ENV['SKIP_OPENPROJECT_DB_RESET'] == 'true'
puts "Resetting target database..."
- drop_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d postgres -c 'DROP DATABASE #{db_name}'"
- drop_output, _ = run drop_cmd, silent: true
+ drop_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d postgres -c 'DROP DATABASE IF EXISTS #{db_name}'"
+ drop_output, dropped_status = run drop_cmd, silent: true
- if drop_output.include?("database \"#{db_name}\" does not exist") || drop_output == "DROP DATABASE"
+ if dropped_status == 0
# that's ok then we don't have to drop it or dropped database successfully
- puts "Database dropped"
+ puts "Database dropped (or was not present)"
else
puts drop_output
exit 1 # something went wrong