From f48ce2f4c934fde3862cdad593eececc7a567d61 Mon Sep 17 00:00:00 2001 From: hellekin Date: Fri, 9 Oct 2020 10:24:06 +0200 Subject: Add Classifications and Resource validations - Turn `has_and_belongs_to_many` into `has_many :through`: now, resources and sections are related through Classifications. - Refactor usage of jsonb column to use ActiveRecord validations - Attention! store_accessor: NOTE: If you are using structured database data types (eg. PostgreSQL hstore/json, or MySQL 5.7+ json) there is no need for the serialization provided by .store. Simply use .store_accessor instead to generate the accessor methods. Be aware that these columns use a string keyed hash and do not allow access using a symbol. NOTE: The default validations with the exception of uniqueness will work. For example, if you want to check for uniqueness with hstore you will need to use a custom validation to handle it. https://api.rubyonrails.org/classes/ActiveRecord/Store.html --- ...201009025353_add_default_to_resource_feature.rb | 30 ++++++++++++++++++++++ ...rename_resources_sections_to_classifications.rb | 5 ++++ 2 files changed, 35 insertions(+) create mode 100644 db/migrate/20201009025353_add_default_to_resource_feature.rb create mode 100644 db/migrate/20201009061548_rename_resources_sections_to_classifications.rb (limited to 'db/migrate') diff --git a/db/migrate/20201009025353_add_default_to_resource_feature.rb b/db/migrate/20201009025353_add_default_to_resource_feature.rb new file mode 100644 index 0000000..06cad6c --- /dev/null +++ b/db/migrate/20201009025353_add_default_to_resource_feature.rb @@ -0,0 +1,30 @@ +class AddDefaultToResourceFeature < ActiveRecord::Migration[6.0] + def up + change_column_default :resources, :feature, + { + "geometry": { + "type": "Point", + "coordinates": [0,0] + }, + "properties": { + "name":"", + "description":"", + "address":"", + "postal_code":"", + "city":"", + "email":"", + "phone_number":"", + "website":"", + "categories":[], + "source":"incommon", + "entry_number":nil, + "srid":4326 + } + } + add_index :resources, :feature, using: :gin + end + def down + change_column_default :resources, :feature, nil + remove_index :resources, :feature + end +end diff --git a/db/migrate/20201009061548_rename_resources_sections_to_classifications.rb b/db/migrate/20201009061548_rename_resources_sections_to_classifications.rb new file mode 100644 index 0000000..4f7972b --- /dev/null +++ b/db/migrate/20201009061548_rename_resources_sections_to_classifications.rb @@ -0,0 +1,5 @@ +class RenameResourcesSectionsToClassifications < ActiveRecord::Migration[6.0] + def change + rename_table :resources_sections, :classifications + end +end -- cgit v1.2.3