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

Allow to skip db drop/creation in migration script

Oliver Günther445b45a5e44a
diff --git a/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres b/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres
index ea93b494f46..aaa79f19408 100755
--- a/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres
+++ b/docker/mysql-to-postgres/bin/migrate-mysql-to-postgres
@@ -87,29 +87,32 @@ def run(cmd, silent: false, record_output: true)
[output.join("\n").strip, $?.to_i]
end
-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
-
-if drop_output.include?("database \"#{db_name}\" does not exist") || drop_output == "DROP DATABASE"
- # that's ok then we don't have to drop it or dropped database successfully
- puts "Database dropped"
-else
- puts drop_output
- exit 1 # something went wrong
-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
+
+ if drop_output.include?("database \"#{db_name}\" does not exist") || drop_output == "DROP DATABASE"
+ # that's ok then we don't have to drop it or dropped database successfully
+ puts "Database dropped"
+ else
+ puts drop_output
+ exit 1 # something went wrong
+ end
-puts "Creating database..."
-create_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d postgres -c 'CREATE DATABASE #{db_name}'"
-create_output, _ = run create_cmd, silent: true
+ puts "Creating database..."
+ create_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d postgres -c 'CREATE DATABASE #{db_name}'"
+ create_output, _ = run create_cmd, silent: true
-if create_output == "CREATE DATABASE"
- # created database successfully
-else
- puts create_output
- exit 1 # something went wrong
+ if create_output == "CREATE DATABASE"
+ # created database successfully
+ else
+ puts create_output
+ exit 1 # something went wrong
+ end
end
+
puts "Importing database ..."
mysql_url.query = nil