diff options
| author | Luc Donnet | 2017-12-23 08:49:28 +0100 |
|---|---|---|
| committer | GitHub | 2017-12-23 08:49:28 +0100 |
| commit | 9fe0ca13d7caba486561f52557c1fa3d2f9f0a52 (patch) | |
| tree | 590ff7afe9f061b5ad5836b10b7f59ed32fe1809 /db | |
| parent | e29d22aa6402c10ab1712cad44316c8f034dd0e6 (diff) | |
| parent | 1d7a0cb4ce78603dac88c4054a658f02bf9fbb22 (diff) | |
| download | chouette-core-9fe0ca13d7caba486561f52557c1fa3d2f9f0a52.tar.bz2 | |
Merge pull request #161 from af83/5316-migrate-compliance-control-and-check-attributes-from-hs
5316 migrate compliance control and check attributes from hstore to json column type
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb | 33 | ||||
| -rw-r--r-- | db/schema.rb | 4 |
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" |
