diff options
| author | Teddy Wing | 2017-12-19 12:00:19 +0100 | 
|---|---|---|
| committer | Luc Donnet | 2017-12-21 15:32:42 +0100 | 
| commit | d9f3af834a06a6d4e73c083440926983ac5e2cfa (patch) | |
| tree | d1f30049630d35adddbb36a20dd12df1b195b1ef | |
| parent | 7f9a61d5823bd6611351fcc6dce79a2159976b34 (diff) | |
| download | chouette-core-d9f3af834a06a6d4e73c083440926983ac5e2cfa.tar.bz2 | |
Change `compliance_{controls,checks}` `control_attributes` to JSON
Make these columns JSON fields again. Do this because of bugs trying to
validate types with `hstore_accessor`
(https://github.com/devmynd/hstore_accessor/issues/78).
With a JSON field, types are preserved and we don't have to deal with
casting back and forth.
Previously we had converted to Hstore because the Java IEV application
used an older ORM version (maybe Hibernate) that didn't support the
Postgres JSON type. Because of the validation problems with Hstore, the
Java application has been updated to support JSON fields.
Thanks to this Stack Overflow post from 'a_horse_with_no_name' that
describes how to convert from Hstore to JSON types in Postgres:
https://stackoverflow.com/questions/33732529/postgres-how-to-convert-hstore-to-json-datatypes#comment55234342_33732529
Converting in this direction seems to me to be much safer because we're
not losing type information. All the values should be hashes of strings,
which should convert without issue into JSON.
Refs #5316
| -rw-r--r-- | db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb | 10 | ||||
| -rw-r--r-- | db/schema.rb | 6 | 
2 files changed, 13 insertions, 3 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..ec5a95ec9 --- /dev/null +++ b/db/migrate/20171218174509_change_compliance_control_compliance_check_control_attributes_format_from_hstore_to_json.rb @@ -0,0 +1,10 @@ +class ChangeComplianceControlComplianceCheckControlAttributesFormatFromHstoreToJson < ActiveRecord::Migration +  def change +    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 +end diff --git a/db/schema.rb b/db/schema.rb index f2642f8fc..50ee0dcf4 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: 20171214130636) do +ActiveRecord::Schema.define(version: 20171218174509) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -208,7 +208,7 @@ ActiveRecord::Schema.define(version: 20171214130636) 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: 20171214130636) 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" | 
