13561: Add initial collection version information to the database
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 14 Sep 2018 16:11:42 +0000 (13:11 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Sat, 15 Sep 2018 16:13:11 +0000 (13:13 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/api/db/migrate/20180913175443_add_version_info_to_collections.rb [new file with mode: 0644]
services/api/db/migrate/20180915155335_set_current_version_uuid_on_collections.rb [new file with mode: 0644]
services/api/db/structure.sql

diff --git a/services/api/db/migrate/20180913175443_add_version_info_to_collections.rb b/services/api/db/migrate/20180913175443_add_version_info_to_collections.rb
new file mode 100644 (file)
index 0000000..b5378d3
--- /dev/null
@@ -0,0 +1,10 @@
+class AddVersionInfoToCollections < ActiveRecord::Migration
+  def change
+    # Do changes in bulk to save time on huge tables
+    change_table :collections, :bulk => true do |t|
+      t.string :current_version_uuid
+      t.integer :version, null: false, default: 1
+      t.index [:current_version_uuid, :version], unique: true
+    end
+  end
+end
diff --git a/services/api/db/migrate/20180915155335_set_current_version_uuid_on_collections.rb b/services/api/db/migrate/20180915155335_set_current_version_uuid_on_collections.rb
new file mode 100644 (file)
index 0000000..b205eae
--- /dev/null
@@ -0,0 +1,9 @@
+class SetCurrentVersionUuidOnCollections < ActiveRecord::Migration
+  def up
+    # Set the current version uuid as itself
+    Collection.where(current_version_uuid: nil).update_all("current_version_uuid=uuid")
+  end
+
+  def down
+  end
+end
index 427c9afb561f20eb4916517d766731de6c126b84..d646d609b1f58aa8065948e06fd5ddeb042a4295 100644 (file)
@@ -172,7 +172,9 @@ CREATE TABLE public.collections (
     is_trashed boolean DEFAULT false NOT NULL,
     storage_classes_desired jsonb DEFAULT '["default"]'::jsonb,
     storage_classes_confirmed jsonb DEFAULT '[]'::jsonb,
-    storage_classes_confirmed_at timestamp without time zone
+    storage_classes_confirmed_at timestamp without time zone,
+    current_version_uuid character varying,
+    version integer DEFAULT 1 NOT NULL
 );
 
 
@@ -1781,6 +1783,13 @@ CREATE UNIQUE INDEX index_authorized_keys_on_uuid ON public.authorized_keys USIN
 CREATE INDEX index_collections_on_created_at ON public.collections USING btree (created_at);
 
 
+--
+-- Name: index_collections_on_current_version_uuid_and_version; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE UNIQUE INDEX index_collections_on_current_version_uuid_and_version ON public.collections USING btree (current_version_uuid, version);
+
+
 --
 -- Name: index_collections_on_delete_at; Type: INDEX; Schema: public; Owner: -
 --
@@ -3169,3 +3178,7 @@ INSERT INTO schema_migrations (version) VALUES ('20180824155207');
 
 INSERT INTO schema_migrations (version) VALUES ('20180904110712');
 
+INSERT INTO schema_migrations (version) VALUES ('20180913175443');
+
+INSERT INTO schema_migrations (version) VALUES ('20180915155335');
+