Skip to content

Commit

Permalink
Use different approach for marking ar_internal_metadata on restore
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geoffharcourt committed Oct 1, 2018
1 parent e5e025a commit 2d2b8cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
11 changes: 3 additions & 8 deletions lib/parity/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,9 @@ def delete_local_temp_backup
end

def delete_rails_production_environment_settings
Kernel.system(
"psql #{development_db} -c "\
"\"DO $$ BEGIN IF EXISTS "\
"(SELECT 1 FROM pg_tables WHERE tablename = 'ar_internal_metadata') "\
"THEN UPDATE ar_internal_metadata "\
"SET value = 'development' "\
"WHERE key = 'environment'; ELSE END IF; END $$;\"",
)
Kernel.system(<<-SHELL)
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'"
SHELL
end

def restore_to_remote_environment
Expand Down
9 changes: 3 additions & 6 deletions spec/parity/backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,8 @@ def default_db_name
end

def set_db_metadata_sql
"psql parity_development -c "\
"\"DO $$ BEGIN IF EXISTS "\
"(SELECT 1 FROM pg_tables WHERE tablename = 'ar_internal_metadata') "\
"THEN UPDATE ar_internal_metadata "\
"SET value = 'development' "\
"WHERE key = 'environment'; ELSE END IF; END $$;\""
<<-SHELL
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'"
SHELL
end
end

0 comments on commit 2d2b8cd

Please sign in to comment.