From a5d54e6af76822bcd828eeb6766616765fce64e1 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 10 Oct 2020 09:54:53 +0200 Subject: [PATCH] fix database migrations #616 --- .../20170807091814_create_all_tables.rb | 24 +++++++----- ...70914055227_convert_to_has_many_through.rb | 31 --------------- .../20190629072238_add_researchers_table.rb | 39 ------------------- db/migrate/20200718191826_add_type_to_doi.rb | 1 - db/schema.rb | 28 +++---------- 5 files changed, 20 insertions(+), 103 deletions(-) delete mode 100644 db/migrate/20170914055227_convert_to_has_many_through.rb delete mode 100644 db/migrate/20190629072238_add_researchers_table.rb diff --git a/db/migrate/20170807091814_create_all_tables.rb b/db/migrate/20170807091814_create_all_tables.rb index 7bc7c6ca8..005c11661 100644 --- a/db/migrate/20170807091814_create_all_tables.rb +++ b/db/migrate/20170807091814_create_all_tables.rb @@ -20,9 +20,11 @@ def change t.index ["symbol"], name: "symbol", unique: true end - create_table "allocator_prefixes", primary_key: ["allocator", "prefixes"], force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| + create_table "allocator_prefixes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.integer "allocator", limit: 8, null: false t.integer "prefixes", limit: 8, null: false + t.datetime "created" + t.datetime "updated" t.index ["allocator"], name: "FKE7FBD67446EBD781" t.index ["prefixes"], name: "FKE7FBD674AF86A1C7" end @@ -48,9 +50,11 @@ def change t.index ["symbol"], name: "symbol", unique: true end - create_table "datacentre_prefixes", primary_key: ["datacentre", "prefixes"], force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| + create_table "datacentre_prefixes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.integer "datacentre", limit: 8, null: false t.integer "prefixes", limit: 8, null: false + t.datetime "created" + t.datetime "updated" t.index ["datacentre"], name: "FK13A1B3BA47B5F5FF" t.index ["prefixes"], name: "FK13A1B3BAAF86A1C7" end @@ -101,13 +105,13 @@ def change t.index ["prefix"], name: "prefix", unique: true end - add_foreign_key "allocator_prefixes", "allocator", column: "allocator", name: "FKE7FBD67446EBD781" - add_foreign_key "allocator_prefixes", "prefix", column: "prefixes", name: "FKE7FBD674AF86A1C7" - add_foreign_key "datacentre", "allocator", column: "allocator", name: "FK6695D60546EBD781" - add_foreign_key "datacentre_prefixes", "datacentre", column: "datacentre", name: "FK13A1B3BA47B5F5FF" - add_foreign_key "datacentre_prefixes", "prefix", column: "prefixes", name: "FK13A1B3BAAF86A1C7" - add_foreign_key "dataset", "datacentre", column: "datacentre", name: "FK5605B47847B5F5FF" - add_foreign_key "media", "dataset", column: "dataset", name: "FK62F6FE44D3D6B1B" - add_foreign_key "metadata", "dataset", column: "dataset", name: "FKE52D7B2F4D3D6B1B" + # add_foreign_key "allocator_prefixes", "allocator", column: "allocator", name: "FKE7FBD67446EBD781" + # add_foreign_key "allocator_prefixes", "prefix", column: "prefixes", name: "FKE7FBD674AF86A1C7" + # add_foreign_key "datacentre", "allocator", column: "allocator", name: "FK6695D60546EBD781" + # add_foreign_key "datacentre_prefixes", "datacentre", column: "datacentre", name: "FK13A1B3BA47B5F5FF" + # add_foreign_key "datacentre_prefixes", "prefix", column: "prefixes", name: "FK13A1B3BAAF86A1C7" + # add_foreign_key "dataset", "datacentre", column: "datacentre", name: "FK5605B47847B5F5FF" + # add_foreign_key "media", "dataset", column: "dataset", name: "FK62F6FE44D3D6B1B" + # add_foreign_key "metadata", "dataset", column: "dataset", name: "FKE52D7B2F4D3D6B1B" end end diff --git a/db/migrate/20170914055227_convert_to_has_many_through.rb b/db/migrate/20170914055227_convert_to_has_many_through.rb deleted file mode 100644 index 342b1073a..000000000 --- a/db/migrate/20170914055227_convert_to_has_many_through.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -class ConvertToHasManyThrough < ActiveRecord::Migration[5.1] - def up - execute "ALTER TABLE `allocator_prefixes` DROP PRIMARY KEY" - add_index :allocator_prefixes, [:allocator, :prefixes], unique: true - add_column :allocator_prefixes, :id, :primary_key - add_column :allocator_prefixes, :created, :datetime - add_column :allocator_prefixes, :updated, :datetime - - execute "ALTER TABLE `datacentre_prefixes` DROP PRIMARY KEY" - add_index :datacentre_prefixes, [:datacentre, :prefixes], unique: true - add_column :datacentre_prefixes, :id, :primary_key - add_column :datacentre_prefixes, :created, :datetime - add_column :datacentre_prefixes, :updated, :datetime - end - - def down - remove_index :allocator_prefixes, name: "index_allocator_prefixes_on_allocator_and_prefixes" - remove_column :allocator_prefixes, :id - remove_column :allocator_prefixes, :created - remove_column :allocator_prefixes, :updated - execute "ALTER TABLE `allocator_prefixes` ADD PRIMARY KEY (allocator,prefixes);" - - remove_index :datacentre_prefixes, name: "index_datacentre_prefixes_on_datacentre_and_prefixes" - remove_column :datacentre_prefixes, :id - remove_column :datacentre_prefixes, :created - remove_column :datacentre_prefixes, :updated - execute "ALTER TABLE `datacentre_prefixes` ADD PRIMARY KEY (datacentre,prefixes);" - end -end diff --git a/db/migrate/20190629072238_add_researchers_table.rb b/db/migrate/20190629072238_add_researchers_table.rb deleted file mode 100644 index a0f5a017f..000000000 --- a/db/migrate/20190629072238_add_researchers_table.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -class AddResearchersTable < ActiveRecord::Migration[5.2] - def up - create_table "researchers", force: :cascade do |t| - t.string "name", limit: 191 - t.string "family_name", limit: 191 - t.string "given_names", limit: 191 - t.string "email", limit: 191 - t.string "provider", limit: 255, default: "orcid" - t.string "uid", limit: 191 - t.string "authentication_token", limit: 191 - t.string "role_id", limit: 255, default: "user" - t.boolean "auto_update", default: true - t.datetime "expires_at", default: "1970-01-01 00:00:00", null: false - t.datetime "created_at", precision: 3 - t.datetime "updated_at", precision: 3 - t.text "other_names", limit: 65535 - t.string "confirmation_token", limit: 191 - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email", limit: 255 - t.string "github", limit: 191 - t.string "github_uid", limit: 191 - t.string "github_token", limit: 191 - t.string "google_uid", limit: 191 - t.string "google_token", limit: 191 - t.integer "github_put_code", limit: 4 - t.boolean "is_public", default: true - t.boolean "beta_tester", default: false - end - - add_index "researchers", ["uid"], name: "index_researchers_on_uid", unique: true, using: :btree - end - - def down - drop_table :researchers - end -end diff --git a/db/migrate/20200718191826_add_type_to_doi.rb b/db/migrate/20200718191826_add_type_to_doi.rb index d45e36bd1..fbb4e9ce5 100644 --- a/db/migrate/20200718191826_add_type_to_doi.rb +++ b/db/migrate/20200718191826_add_type_to_doi.rb @@ -2,7 +2,6 @@ class AddTypeToDoi < ActiveRecord::Migration[5.2] def up - remove_foreign_key "dataset", "datacentre" add_column :dataset, :type, :string, limit: 16 change_column_default :dataset, :type, "DataCiteDoi" change_column_default :dataset, :agency, "datacite" diff --git a/db/schema.rb b/db/schema.rb index 3b9080ece..e280cdfc0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ ActiveRecord::Schema.define(version: 2020_08_26_173254) do - create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", force: :cascade do |t| t.string "name", limit: 191, null: false t.string "record_type", null: false t.bigint "record_id", null: false @@ -22,7 +22,7 @@ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end - create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", force: :cascade do |t| t.string "key", limit: 191, null: false t.string "filename", limit: 191, null: false t.string "content_type", limit: 191 @@ -76,14 +76,12 @@ t.string "logo_content_type" t.bigint "logo_file_size" t.datetime "logo_updated_at" - t.string "uid", limit: 32 t.index ["globus_uuid"], name: "index_allocator_on_globus_uuid" t.index ["organization_type"], name: "index_allocator_organization_type" t.index ["symbol"], name: "symbol", unique: true - t.index ["uid"], name: "index_allocator_on_uid" end - create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", force: :cascade do |t| t.integer "auditable_id" t.string "auditable_type" t.integer "associated_id" @@ -111,8 +109,7 @@ t.datetime "created_at" t.datetime "updated_at" t.bigint "provider_prefix_id" - t.string "uid" - t.index ["client_id", "prefix_id"], name: "index_client_prefixes_on_client_id_and_prefix_id", unique: true + t.string "uid", null: false t.index ["client_id"], name: "FK13A1B3BA47B5F5FF" t.index ["prefix_id"], name: "FK13A1B3BAAF86A1C7" t.index ["provider_prefix_id"], name: "index_client_prefixes_on_provider_prefix_id" @@ -150,12 +147,10 @@ t.string "salesforce_id", limit: 191 t.json "service_contact" t.string "globus_uuid", limit: 191 - t.string "uid", limit: 32 t.index ["allocator"], name: "FK6695D60546EBD781" t.index ["globus_uuid"], name: "index_datacentre_on_globus_uuid" t.index ["re3data_id"], name: "index_datacentre_on_re3data_id" t.index ["symbol"], name: "symbol", unique: true - t.index ["uid"], name: "index_datacentre_on_uid" t.index ["url"], name: "index_datacentre_on_url", length: 100 end @@ -216,7 +211,7 @@ t.index ["url"], name: "index_dataset_on_url", length: 100 end - create_table "events", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", force: :cascade do |t| + create_table "events", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.text "uuid", null: false t.text "subj_id", null: false t.text "obj_id" @@ -276,7 +271,6 @@ create_table "prefixes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.datetime "created_at" t.string "uid", limit: 80, null: false - t.string "ra", default: "DataCite" t.index ["uid"], name: "prefix", unique: true end @@ -285,19 +279,9 @@ t.bigint "prefix_id", null: false t.datetime "created_at" t.datetime "updated_at" - t.string "uuid" - t.string "uid" + t.string "uid", null: false t.index ["prefix_id"], name: "FKE7FBD674AF86A1C7" - t.index ["provider_id", "prefix_id"], name: "index_provider_prefixes_on_provider_id_and_prefix_id", unique: true t.index ["provider_id"], name: "FKE7FBD67446EBD781" t.index ["uid"], name: "index_provider_prefixes_on_uid", length: 128 end - - add_foreign_key "client_prefixes", "datacentre", column: "client_id", name: "FK13A1B3BA47B5F5FF" - add_foreign_key "client_prefixes", "prefixes", name: "FK13A1B3BAAF86A1C7" - add_foreign_key "datacentre", "allocator", column: "allocator", name: "FK6695D60546EBD781" - add_foreign_key "media", "dataset", column: "dataset", name: "FK62F6FE44D3D6B1B" - add_foreign_key "metadata", "dataset", column: "dataset", name: "FKE52D7B2F4D3D6B1B" - add_foreign_key "provider_prefixes", "allocator", column: "provider_id", name: "FKE7FBD67446EBD781" - add_foreign_key "provider_prefixes", "prefixes", name: "FKE7FBD674AF86A1C7" end