Skip to content
Snippets Groups Projects

Add rake task for copying 'main' database to 'ci' database

2 files
+ 41
7
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -16,6 +16,7 @@ class Migrate
select count(*) as total
from information_schema.tables
where table_catalog = :table_catalog and table_type = 'BASE TABLE'
and table_schema not in ('information_schema', 'pg_catalog')
SQL
attr_reader :backup_location
@@ -87,8 +88,28 @@ def ci_database_created?
true
end
def ci_database_empty?
sql = ApplicationRecord.sanitize_sql([
TABLE_COUNT_QUERY,
{ table_catalog: ci_database_name }
])
std, status = with_transient_pg_env(ci_config[:pg_env]) do
psql_args = ["--dbname=#{ci_database_name}", "-tAc", sql]
Open3.capture2e('psql', *psql_args)
end
unless status.success? && std.chomp.to_i == 0
raise MigrateError,
"Database '#{ci_database_name}' is not empty"
end
true
end
def can_migrate?
single_database_setup? && ci_database_created? && required_diskspace_available?
single_database_setup? && ci_database_created? && ci_database_empty? && required_diskspace_available?
end
def with_transient_pg_env(extended_env)
Loading