From cfd1bcc5cc98465bfa89c6373034275a383ea40a Mon Sep 17 00:00:00 2001 From: Felix Schizlein Date: Thu, 26 Oct 2023 16:39:25 +0200 Subject: [PATCH] Change the migration to also move instance_data and do not reset the system_information on rollback --- ...814105634_move_hw_info_to_systems_table.rb | 8 ++--- db/schema.rb | 31 +++++++++---------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/db/migrate/20230814105634_move_hw_info_to_systems_table.rb b/db/migrate/20230814105634_move_hw_info_to_systems_table.rb index 234002dc0..ce9a3e3c7 100644 --- a/db/migrate/20230814105634_move_hw_info_to_systems_table.rb +++ b/db/migrate/20230814105634_move_hw_info_to_systems_table.rb @@ -9,12 +9,8 @@ def up 'arch', nullif(hw.arch, ''), \ 'uuid', nullif(hw.uuid, ''), \ 'cloud_provider', nullif(hw.cloud_provider, ''));" - end - end - - def down - safety_assured do - execute 'update systems set system_information = json_object();' + execute "update systems as s inner join hw_infos hw on s.id=hw.system_id \ + set s.instance_data = hw.instance_data;" end end end diff --git a/db/schema.rb b/db/schema.rb index 64be49b09..3a3543293 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,9 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_07_11_152732) do +ActiveRecord::Schema.define(version: 2023_08_14_105634) do - create_table "activations", charset: "utf8", force: :cascade do |t| + create_table "activations", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "service_id", null: false t.bigint "system_id", null: false t.datetime "created_at", null: false @@ -24,14 +24,14 @@ t.index ["system_id"], name: "index_activations_on_system_id" end - create_table "deregistered_systems", charset: "utf8", force: :cascade do |t| + create_table "deregistered_systems", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "scc_system_id", null: false, comment: "SCC IDs of deregistered systems; used for forwarding to SCC" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["scc_system_id"], name: "index_deregistered_systems_on_scc_system_id", unique: true end - create_table "downloaded_files", charset: "utf8", force: :cascade do |t| + create_table "downloaded_files", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.string "checksum_type" t.string "checksum" t.string "local_path" @@ -40,7 +40,7 @@ t.index ["local_path"], name: "index_downloaded_files_on_local_path", unique: true end - create_table "hw_infos", charset: "utf8", force: :cascade do |t| + create_table "hw_infos", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.integer "cpus" t.integer "sockets" t.string "hypervisor" @@ -51,12 +51,11 @@ t.datetime "updated_at", null: false t.text "instance_data", comment: "Additional client information, e.g. instance identity document" t.string "cloud_provider" - t.boolean "proxy_byos", default: false t.index ["hypervisor"], name: "index_hw_infos_on_hypervisor" t.index ["system_id"], name: "index_hw_infos_on_system_id", unique: true end - create_table "product_predecessors", charset: "utf8", force: :cascade do |t| + create_table "product_predecessors", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "product_id", null: false t.bigint "predecessor_id" t.integer "kind", default: 0, null: false @@ -65,7 +64,7 @@ t.index ["product_id"], name: "index_product_predecessors_on_product_id" end - create_table "products", charset: "utf8", force: :cascade do |t| + create_table "products", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.string "name" t.text "description" t.string "shortname" @@ -83,7 +82,7 @@ t.string "friendly_version" end - create_table "products_extensions", charset: "utf8", force: :cascade do |t| + create_table "products_extensions", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "product_id", null: false t.bigint "extension_id", null: false t.boolean "recommended" @@ -95,7 +94,7 @@ t.index ["root_product_id"], name: "fk_rails_7d0e68d364" end - create_table "repositories", charset: "utf8", force: :cascade do |t| + create_table "repositories", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "scc_id", unsigned: true t.string "name", null: false t.string "description" @@ -113,7 +112,7 @@ t.index ["scc_id"], name: "index_repositories_on_scc_id", unique: true end - create_table "repositories_services", charset: "utf8", force: :cascade do |t| + create_table "repositories_services", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "repository_id", null: false t.bigint "service_id", null: false t.index ["repository_id"], name: "index_repositories_services_on_repository_id" @@ -121,21 +120,21 @@ t.index ["service_id"], name: "index_repositories_services_on_service_id" end - create_table "services", charset: "utf8", force: :cascade do |t| + create_table "services", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "product_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["product_id"], name: "index_services_on_product_id", unique: true end - create_table "subscription_product_classes", charset: "utf8", force: :cascade do |t| + create_table "subscription_product_classes", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.bigint "subscription_id", null: false t.string "product_class", null: false t.index ["subscription_id", "product_class"], name: "index_product_class_unique", unique: true t.index ["subscription_id"], name: "index_subscription_product_classes_on_subscription_id" end - create_table "subscriptions", charset: "utf8", force: :cascade do |t| + create_table "subscriptions", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.string "regcode", null: false t.string "name", null: false t.string "kind", null: false @@ -150,7 +149,7 @@ t.index ["regcode"], name: "index_subscriptions_on_regcode" end - create_table "systems", charset: "utf8", force: :cascade do |t| + create_table "systems", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| t.string "login" t.string "password" t.string "hostname" @@ -162,7 +161,7 @@ t.bigint "scc_system_id", comment: "System ID in SCC (if the system registration was forwarded; needed for forwarding de-registrations)" t.boolean "proxy_byos", default: false t.string "system_token" - t.text "system_information", size: :long + t.text "system_information", size: :long, collation: "utf8mb4_bin" t.string "instance_data" t.index ["login", "password", "system_token"], name: "index_systems_on_login_and_password_and_system_token", unique: true t.index ["login", "password"], name: "index_systems_on_login_and_password"