From 6017f40cefc1749f354776cffa0f51b20574d6bf Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Mon, 7 Jan 2019 17:18:17 +0100 Subject: [PATCH] Add migration to remove samples' associated data from DB --- .../20190726102200_remove_samples_from_db.rb | 74 ++++++++++ db/schema.rb | 133 +++--------------- 2 files changed, 93 insertions(+), 114 deletions(-) create mode 100644 db/migrate/20190726102200_remove_samples_from_db.rb diff --git a/db/migrate/20190726102200_remove_samples_from_db.rb b/db/migrate/20190726102200_remove_samples_from_db.rb new file mode 100644 index 000000000..e466a4a41 --- /dev/null +++ b/db/migrate/20190726102200_remove_samples_from_db.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +class RemoveSamplesFromDb < ActiveRecord::Migration[5.1] + def change + # Revert 20171003082333_add_connections_and_sample_tasks_indexes + remove_index :sample_my_modules, :my_module_id + + # Revert 20170407082423_update_indexes_for_faster_search + remove_index :samples, name: :index_samples_on_name + remove_index :samples, name: :index_sample_types_on_name + remove_index :samples, name: :index_sample_groups_on_name + remove_index :samples, name: :index_sample_custom_fields_on_value + + # Revert 20161123161514_create_samples_tables + remove_index :samples_tables, :user_id + remove_index :samples_tables, :team_id + drop_table :samples_tables + + # Revert 20151215103642_add_foreign_keys_to_tables + remove_foreign_key :custom_fields, column: :last_modified_by_id + + # Revert 20151028091615_add_counter_cache_to_samples + remove_column :samples, :nr_of_modules_assigned_to, :integer, default: 0 + remove_column :my_modules, :nr_of_assigned_samples, :integer, default: 0 + + # Revert 20151005122041_add_created_by_to_assets + remove_column :sample_my_modules, :assigned_on, :datetime + + # Revert 20150827130822_create_sample_custom_fields + remove_index :sample_custom_fields, :custom_field_id + remove_index :sample_custom_fields, :sample_id + remove_foreign_key :sample_custom_fields, :custom_fields + remove_foreign_key :sample_custom_fields, :samples + drop_table :sample_custom_fields + + # Revert 20150827130647_create_custom_fields + remove_index :custom_fields, :user_id + remove_index :custom_fields, :team_id + remove_foreign_key :custom_fields, :users + remove_foreign_key :custom_fields, :teams + drop_table :custom_fields + + # Revert 20150820124022_add_default_columns_to_samples + remove_index :samples, :sample_group_id + remove_index :samples, :sample_type_id + remove_foreign_key :samples, :sample_groups + remove_foreign_key :samples, :sample_types + remove_column :samples, :sample_group_id, :integer + remove_column :samples, :sample_type_id, :integer + + # Revert 20150820123018_create_sample_types + remove_index :sample_types, :team_id + remove_foreign_key :sample_types, :teams + drop_table :sample_types + + # Revert 20150820120553_create_sample_groups + remove_index :sample_groups, :team_id + remove_foreign_key :sample_groups, :teams + drop_table :sample_groups + + # Revert 20150716120130_create_sample_my_modules + remove_index :sample_my_modules, %i(sample_id my_module_id) + remove_foreign_key :sample_my_modules, :samples + remove_foreign_key :sample_my_modules, :my_modules + drop_table :sample_my_modules + + # Revert 20150716062801_create_samples + remove_index :samples, :user_id + remove_index :samples, :team_id + remove_foreign_key :samples, :users + remove_foreign_key :samples, :teams + drop_table :samples + end +end diff --git a/db/schema.rb b/db/schema.rb index ba5dc8029..727cf082a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190520135317) do +ActiveRecord::Schema.define(version: 20190726102200) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - enable_extension "pg_trgm" enable_extension "btree_gist" + enable_extension "pg_stat_statements" + enable_extension "pg_trgm" create_table "activities", force: :cascade do |t| t.bigint "my_module_id" @@ -62,10 +63,10 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.bigint "last_modified_by_id" t.integer "estimated_size", default: 0, null: false t.boolean "file_present", default: false, null: false + t.boolean "file_processing" t.string "lock", limit: 1024 t.integer "lock_ttl" t.integer "version", default: 1 - t.boolean "file_processing" t.integer "team_id" t.integer "file_image_quality" t.index "trim_html_tags((file_file_name)::text) gin_trgm_ops", name: "index_assets_on_file_file_name", using: :gin @@ -126,19 +127,7 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.index ["output_id"], name: "index_connections_on_output_id" end - create_table "custom_fields", force: :cascade do |t| - t.string "name", null: false - t.bigint "user_id", null: false - t.bigint "team_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.bigint "last_modified_by_id" - t.index ["last_modified_by_id"], name: "index_custom_fields_on_last_modified_by_id" - t.index ["team_id"], name: "index_custom_fields_on_team_id" - t.index ["user_id"], name: "index_custom_fields_on_user_id" - end - - create_table "delayed_jobs", force: :cascade do |t| + create_table "delayed_jobs", id: :serial, force: :cascade do |t| t.integer "priority", default: 0, null: false t.integer "attempts", default: 0, null: false t.text "handler", null: false @@ -224,7 +213,6 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.bigint "archived_by_id" t.bigint "restored_by_id" t.datetime "restored_on" - t.integer "nr_of_assigned_samples", default: 0 t.integer "workflow_order", default: -1, null: false t.bigint "experiment_id", default: 0, null: false t.integer "state", limit: 2, default: 0 @@ -434,8 +422,8 @@ ActiveRecord::Schema.define(version: 20190520135317) do create_table "repository_cells", force: :cascade do |t| t.bigint "repository_row_id" t.integer "repository_column_id" - t.string "value_type" t.bigint "value_id" + t.string "value_type" t.datetime "created_at" t.datetime "updated_at" t.index ["repository_column_id"], name: "index_repository_cells_on_repository_column_id" @@ -557,82 +545,6 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.index ["user_id"], name: "index_results_on_user_id" end - create_table "sample_custom_fields", force: :cascade do |t| - t.string "value", null: false - t.bigint "custom_field_id", null: false - t.bigint "sample_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index "trim_html_tags((value)::text) gin_trgm_ops", name: "index_sample_custom_fields_on_value", using: :gin - t.index ["custom_field_id"], name: "index_sample_custom_fields_on_custom_field_id" - t.index ["sample_id"], name: "index_sample_custom_fields_on_sample_id" - end - - create_table "sample_groups", force: :cascade do |t| - t.string "name", null: false - t.string "color", default: "#ff0000", null: false - t.bigint "team_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.bigint "created_by_id" - t.bigint "last_modified_by_id" - t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_sample_groups_on_name", using: :gin - t.index ["created_by_id"], name: "index_sample_groups_on_created_by_id" - t.index ["last_modified_by_id"], name: "index_sample_groups_on_last_modified_by_id" - t.index ["team_id"], name: "index_sample_groups_on_team_id" - end - - create_table "sample_my_modules", force: :cascade do |t| - t.bigint "sample_id", null: false - t.bigint "my_module_id", null: false - t.bigint "assigned_by_id" - t.datetime "assigned_on" - t.index ["assigned_by_id"], name: "index_sample_my_modules_on_assigned_by_id" - t.index ["my_module_id"], name: "index_sample_my_modules_on_my_module_id" - t.index ["sample_id", "my_module_id"], name: "index_sample_my_modules_on_sample_id_and_my_module_id" - end - - create_table "sample_types", force: :cascade do |t| - t.string "name", null: false - t.bigint "team_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.bigint "created_by_id" - t.bigint "last_modified_by_id" - t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_sample_types_on_name", using: :gin - t.index ["created_by_id"], name: "index_sample_types_on_created_by_id" - t.index ["last_modified_by_id"], name: "index_sample_types_on_last_modified_by_id" - t.index ["team_id"], name: "index_sample_types_on_team_id" - end - - create_table "samples", force: :cascade do |t| - t.string "name", null: false - t.bigint "user_id", null: false - t.bigint "team_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.bigint "sample_group_id" - t.bigint "sample_type_id" - t.bigint "last_modified_by_id" - t.integer "nr_of_modules_assigned_to", default: 0 - t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_samples_on_name", using: :gin - t.index ["last_modified_by_id"], name: "index_samples_on_last_modified_by_id" - t.index ["sample_group_id"], name: "index_samples_on_sample_group_id" - t.index ["sample_type_id"], name: "index_samples_on_sample_type_id" - t.index ["team_id"], name: "index_samples_on_team_id" - t.index ["user_id"], name: "index_samples_on_user_id" - end - - create_table "samples_tables", force: :cascade do |t| - t.jsonb "status", default: {"time"=>0, "order"=>[[2, "desc"]], "start"=>0, "length"=>10, "search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "columns"=>[{"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}], "assigned"=>"all", "ColReorder"=>[0, 1, 2, 3, 4, 5, 6]}, null: false - t.integer "user_id", null: false - t.integer "team_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["team_id"], name: "index_samples_tables_on_team_id" - t.index ["user_id"], name: "index_samples_tables_on_user_id" - end - create_table "settings", force: :cascade do |t| t.text "type", null: false t.jsonb "values", default: {}, null: false @@ -726,6 +638,9 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.bigint "last_modified_by_id" t.string "description" t.bigint "space_taken", default: 1048576, null: false + t.integer "billing_account_id" + t.bigint "hub_spot_deal_id" + t.index ["billing_account_id"], name: "index_teams_on_billing_account_id" t.index ["created_by_id"], name: "index_teams_on_created_by_id" t.index ["last_modified_by_id"], name: "index_teams_on_last_modified_by_id" t.index ["name"], name: "index_teams_on_name" @@ -868,11 +783,13 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" t.integer "invitation_limit" - t.string "invited_by_type" t.integer "invited_by_id" + t.string "invited_by_type" t.integer "invitations_count", default: 0 t.bigint "current_team_id" t.string "authentication_token", limit: 30 + t.integer "ai_manuscripts_limit", default: 0 + t.bigint "hub_spot_contact_id" t.jsonb "settings", default: {}, null: false t.jsonb "variables", default: {}, null: false t.index "trim_html_tags((full_name)::text) gin_trgm_ops", name: "index_users_on_full_name", using: :gin @@ -937,6 +854,10 @@ ActiveRecord::Schema.define(version: 20190520135317) do add_foreign_key "asset_text_data", "assets" add_foreign_key "assets", "users", column: "created_by_id" add_foreign_key "assets", "users", column: "last_modified_by_id" + add_foreign_key "billing_subscription_addons", "billing_addons" + add_foreign_key "billing_subscription_addons", "billing_subscriptions" + add_foreign_key "billing_subscriptions", "billing_accounts" + add_foreign_key "billing_subscriptions", "billing_plans" add_foreign_key "checklist_items", "checklists" add_foreign_key "checklist_items", "users", column: "created_by_id" add_foreign_key "checklist_items", "users", column: "last_modified_by_id" @@ -947,9 +868,6 @@ ActiveRecord::Schema.define(version: 20190520135317) do add_foreign_key "comments", "users", column: "last_modified_by_id" add_foreign_key "connections", "my_modules", column: "input_id" add_foreign_key "connections", "my_modules", column: "output_id" - add_foreign_key "custom_fields", "teams" - add_foreign_key "custom_fields", "users" - add_foreign_key "custom_fields", "users", column: "last_modified_by_id" add_foreign_key "experiments", "users", column: "archived_by_id" add_foreign_key "experiments", "users", column: "created_by_id" add_foreign_key "experiments", "users", column: "last_modified_by_id" @@ -1021,22 +939,8 @@ ActiveRecord::Schema.define(version: 20190520135317) do add_foreign_key "results", "users", column: "archived_by_id" add_foreign_key "results", "users", column: "last_modified_by_id" add_foreign_key "results", "users", column: "restored_by_id" - add_foreign_key "sample_custom_fields", "custom_fields" - add_foreign_key "sample_custom_fields", "samples" - add_foreign_key "sample_groups", "teams" - add_foreign_key "sample_groups", "users", column: "created_by_id" - add_foreign_key "sample_groups", "users", column: "last_modified_by_id" - add_foreign_key "sample_my_modules", "my_modules" - add_foreign_key "sample_my_modules", "samples" - add_foreign_key "sample_my_modules", "users", column: "assigned_by_id" - add_foreign_key "sample_types", "teams" - add_foreign_key "sample_types", "users", column: "created_by_id" - add_foreign_key "sample_types", "users", column: "last_modified_by_id" - add_foreign_key "samples", "sample_groups" - add_foreign_key "samples", "sample_types" - add_foreign_key "samples", "teams" - add_foreign_key "samples", "users" - add_foreign_key "samples", "users", column: "last_modified_by_id" + add_foreign_key "scinote_ai_manuscripts", "users" + add_foreign_key "scinote_core_gamification_scores", "users" add_foreign_key "step_assets", "assets" add_foreign_key "step_assets", "steps" add_foreign_key "step_tables", "steps" @@ -1049,6 +953,7 @@ ActiveRecord::Schema.define(version: 20190520135317) do add_foreign_key "tags", "projects" add_foreign_key "tags", "users", column: "created_by_id" add_foreign_key "tags", "users", column: "last_modified_by_id" + add_foreign_key "teams", "billing_accounts" add_foreign_key "teams", "users", column: "created_by_id" add_foreign_key "teams", "users", column: "last_modified_by_id" add_foreign_key "tokens", "users"