aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb33
-rw-r--r--db/schema.rb4
2 files changed, 35 insertions, 2 deletions
diff --git a/db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb b/db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb
new file mode 100644
index 000000000..0576dddf2
--- /dev/null
+++ b/db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb
@@ -0,0 +1,33 @@
+class ChangeComplianceControlComplianceCheckControlAttributesFormatFromHstoreToJson < ActiveRecord::Migration
+ def up
+ change_column :compliance_controls,
+ :control_attributes,
+ 'json USING hstore_to_json(control_attributes)'
+ change_column :compliance_checks,
+ :control_attributes,
+ 'json USING hstore_to_json(control_attributes)'
+ end
+
+ def down
+ execute <<-SQL
+ CREATE OR REPLACE FUNCTION my_json_to_hstore(json)
+ RETURNS hstore
+ IMMUTABLE
+ STRICT
+ LANGUAGE sql
+ AS $func$
+ SELECT hstore(array_agg(key), array_agg(value))
+ FROM json_each_text($1)
+ $func$;
+ SQL
+
+ change_column :compliance_controls,
+ :control_attributes,
+ 'hstore USING my_json_to_hstore(control_attributes)'
+ change_column :compliance_checks,
+ :control_attributes,
+ 'hstore USING my_json_to_hstore(control_attributes)'
+
+ execute "DROP FUNCTION my_json_to_hstore(json)"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 81966575b..182df3159 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -208,7 +208,7 @@ ActiveRecord::Schema.define(version: 20171220164059) do
t.integer "compliance_check_set_id", limit: 8
t.integer "compliance_check_block_id", limit: 8
t.string "type"
- t.hstore "control_attributes"
+ t.json "control_attributes"
t.string "name"
t.string "code"
t.string "criticity"
@@ -243,7 +243,7 @@ ActiveRecord::Schema.define(version: 20171220164059) do
create_table "compliance_controls", id: :bigserial, force: :cascade do |t|
t.integer "compliance_control_set_id", limit: 8
t.string "type"
- t.hstore "control_attributes"
+ t.json "control_attributes"
t.string "name"
t.string "code"
t.string "criticity"