From 5f75e2db42cea65e6f4e6b8c2b1b1dfb8e748c05 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 8 Jun 2018 08:59:56 -0400 Subject: [PATCH] 13562: Add "properties" field to groups, supports subproperty query. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- services/api/app/models/group.rb | 3 +++ .../20180608123145_add_properties_to_groups.rb | 11 +++++++++++ services/api/db/structure.sql | 12 +++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 services/api/db/migrate/20180608123145_add_properties_to_groups.rb diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb index fe183678c1..7a7f0a3a60 100644 --- a/services/api/app/models/group.rb +++ b/services/api/app/models/group.rb @@ -12,6 +12,8 @@ class Group < ArvadosModel include CanBeAnOwner include Trashable + serialize :properties, Hash + after_create :invalidate_permissions_cache after_update :maybe_invalidate_permissions_cache before_create :assign_name @@ -24,6 +26,7 @@ class Group < ArvadosModel t.add :delete_at t.add :trash_at t.add :is_trashed + t.add :properties end def maybe_invalidate_permissions_cache diff --git a/services/api/db/migrate/20180608123145_add_properties_to_groups.rb b/services/api/db/migrate/20180608123145_add_properties_to_groups.rb new file mode 100644 index 0000000000..a969456423 --- /dev/null +++ b/services/api/db/migrate/20180608123145_add_properties_to_groups.rb @@ -0,0 +1,11 @@ +class AddPropertiesToGroups < ActiveRecord::Migration + def up + add_column :groups, :properties, :jsonb, default: {} + ActiveRecord::Base.connection.execute("CREATE INDEX group_index_on_properties ON groups USING gin (properties);") + end + + def down + ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS group_index_on_properties") + remove_column :groups, :properties + end +end diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql index 0ab30c5e1c..20ce89c22d 100644 --- a/services/api/db/structure.sql +++ b/services/api/db/structure.sql @@ -396,7 +396,8 @@ CREATE TABLE groups ( group_class character varying(255), trash_at timestamp without time zone, is_trashed boolean DEFAULT false NOT NULL, - delete_at timestamp without time zone + delete_at timestamp without time zone, + properties jsonb DEFAULT '{}'::jsonb ); @@ -1654,6 +1655,13 @@ CREATE INDEX container_requests_search_index ON container_requests USING btree ( CREATE INDEX containers_search_index ON containers USING btree (uuid, owner_uuid, modified_by_client_uuid, modified_by_user_uuid, state, log, cwd, output_path, output, container_image, auth_uuid, locked_by_uuid); +-- +-- Name: group_index_on_properties; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX group_index_on_properties ON groups USING gin (properties); + + -- -- Name: groups_full_text_search_idx; Type: INDEX; Schema: public; Owner: - -- @@ -3080,3 +3088,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180501182859'); INSERT INTO schema_migrations (version) VALUES ('20180514135529'); +INSERT INTO schema_migrations (version) VALUES ('20180608123145'); + -- 2.30.2