Skip to content

Commit 2d2b8cd

Browse files
committed
Use different approach for marking ar_internal_metadata on restore
The previous attempt in e5e025a to mark the `ar_internal_metadata` environment row as non-production does not work reliably. The change here fixes the issue with a slightly more brute-force approach, but one that does not require capabilities beyond pure SQL. If the `ar_internal_metadata` table does not exist, we'll create a blank one with no rows. The following update operation will no-op.
1 parent e5e025a commit 2d2b8cd

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

lib/parity/backup.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,9 @@ def delete_local_temp_backup
8383
end
8484

8585
def delete_rails_production_environment_settings
86-
Kernel.system(
87-
"psql #{development_db} -c "\
88-
"\"DO $$ BEGIN IF EXISTS "\
89-
"(SELECT 1 FROM pg_tables WHERE tablename = 'ar_internal_metadata') "\
90-
"THEN UPDATE ar_internal_metadata "\
91-
"SET value = 'development' "\
92-
"WHERE key = 'environment'; ELSE END IF; END $$;\"",
93-
)
86+
Kernel.system(<<-SHELL)
87+
psql #{development_db} -c "CREATE TABLE IF NOT EXISTS public.ar_internal_metadata (key character varying NOT NULL, value character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key)); UPDATE ar_internal_metadata SET value = 'development' WHERE key = 'environment'"
88+
SHELL
9489
end
9590

9691
def restore_to_remote_environment

spec/parity/backup_spec.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,8 @@ def default_db_name
185185
end
186186

187187
def set_db_metadata_sql
188-
"psql parity_development -c "\
189-
"\"DO $$ BEGIN IF EXISTS "\
190-
"(SELECT 1 FROM pg_tables WHERE tablename = 'ar_internal_metadata') "\
191-
"THEN UPDATE ar_internal_metadata "\
192-
"SET value = 'development' "\
193-
"WHERE key = 'environment'; ELSE END IF; END $$;\""
188+
<<-SHELL
189+
psql parity_development -c "CREATE TABLE IF NOT EXISTS public.ar_internal_metadata (key character varying NOT NULL, value character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key)); UPDATE ar_internal_metadata SET value = 'development' WHERE key = 'environment'"
190+
SHELL
194191
end
195192
end

0 commit comments

Comments
 (0)