aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-10-03 15:01:14 +0200
committercedricnjanga2017-10-03 15:09:20 +0200
commit014c5bdceb91ab876d10939c308611748ee0ee9c (patch)
tree6cee17e4461910cdb2c04996a5bd9bbbb595eeec
parent7775030c3f84e0673bbf68e7a60a3ed4798f6b91 (diff)
downloadchouette-core-014c5bdceb91ab876d10939c308611748ee0ee9c.tar.bz2
Refs #4678 Add migration to convert control attributes to hstore
-rw-r--r--db/migrate/20171003123007_change_control_attributes_format_in_compliance_control_and_in_compliance_check.rb20
-rw-r--r--db/schema.rb8
2 files changed, 24 insertions, 4 deletions
diff --git a/db/migrate/20171003123007_change_control_attributes_format_in_compliance_control_and_in_compliance_check.rb b/db/migrate/20171003123007_change_control_attributes_format_in_compliance_control_and_in_compliance_check.rb
new file mode 100644
index 000000000..cf1e31970
--- /dev/null
+++ b/db/migrate/20171003123007_change_control_attributes_format_in_compliance_control_and_in_compliance_check.rb
@@ -0,0 +1,20 @@
+class ChangeControlAttributesFormatInComplianceControlAndInComplianceCheck < ActiveRecord::Migration
+ def change
+
+ 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 91ffdd60c..608a611a3 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20171002080526) do
+ActiveRecord::Schema.define(version: 20171003123007) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -205,7 +205,7 @@ ActiveRecord::Schema.define(version: 20171002080526) do
t.integer "compliance_check_set_id"
t.integer "compliance_check_block_id"
t.string "type"
- t.json "control_attributes"
+ t.hstore "control_attributes"
t.string "name"
t.string "code"
t.integer "criticity"
@@ -240,7 +240,7 @@ ActiveRecord::Schema.define(version: 20171002080526) do
create_table "compliance_controls", id: :bigserial, force: :cascade do |t|
t.integer "compliance_control_set_id"
t.string "type"
- t.json "control_attributes"
+ t.hstore "control_attributes"
t.string "name"
t.string "code"
t.string "criticity"
@@ -402,9 +402,9 @@ ActiveRecord::Schema.define(version: 20171002080526) do
t.string "type"
t.integer "parent_id", limit: 8
t.string "parent_type"
- t.datetime "notified_parent_at"
t.integer "current_step", default: 0
t.integer "total_steps", default: 0
+ t.datetime "notified_parent_at"
t.string "creator"
end