From 3a9fa7a902c55553c95fe6ec8e05f49b22ee5162 Mon Sep 17 00:00:00 2001 From: Felix Schizlein Date: Wed, 29 Nov 2023 18:27:15 +0100 Subject: [PATCH] Make systems.instance_data a text rather then a string and cleanup schema.rb --- ...814105634_move_hw_info_to_systems_table.rb | 25 +++++++++------- db/schema.rb | 30 +++++++++---------- 2 files changed, 30 insertions(+), 25 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 ce9a3e3c7..3be0b9772 100644 --- a/db/migrate/20230814105634_move_hw_info_to_systems_table.rb +++ b/db/migrate/20230814105634_move_hw_info_to_systems_table.rb @@ -1,16 +1,21 @@ class MoveHwInfoToSystemsTable < ActiveRecord::Migration[6.1] def up safety_assured do - execute "update systems as s inner join hw_infos hw on s.id=hw.system_id \ - set system_information = json_object(\ - 'cpus', hw.cpus, \ - 'sockets', hw.sockets, \ - 'hypervisor', nullif(hw.hypervisor, ''), \ - 'arch', nullif(hw.arch, ''), \ - 'uuid', nullif(hw.uuid, ''), \ - 'cloud_provider', nullif(hw.cloud_provider, ''));" - execute "update systems as s inner join hw_infos hw on s.id=hw.system_id \ - set s.instance_data = hw.instance_data;" + change_column :systems, :instance_data, :text + + execute "UPDATE systems AS s INNER JOIN hw_infos hw ON s.id=hw.system_id \ + SET s.system_information = json_object( \ + 'cpus', hw.cpus, \ + 'sockets', hw.sockets, \ + 'hypervisor', nullif(hw.hypervisor, ''), \ + 'arch', nullif(hw.arch, ''), \ + 'uuid', nullif(hw.uuid, ''), \ + 'cloud_provider', nullif(hw.cloud_provider, '')), \ + s.instance_data = hw.instance_data;" end end + + def down + change_column :systems, :instance_data, :string + end end diff --git a/db/schema.rb b/db/schema.rb index 3a3543293..1f3795dbe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ ActiveRecord::Schema.define(version: 2023_08_14_105634) do - create_table "activations", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "activations", charset: "utf8", 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: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "deregistered_systems", charset: "utf8", 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: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "downloaded_files", charset: "utf8", 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: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "hw_infos", charset: "utf8", force: :cascade do |t| t.integer "cpus" t.integer "sockets" t.string "hypervisor" @@ -55,7 +55,7 @@ t.index ["system_id"], name: "index_hw_infos_on_system_id", unique: true end - create_table "product_predecessors", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "product_predecessors", charset: "utf8", force: :cascade do |t| t.bigint "product_id", null: false t.bigint "predecessor_id" t.integer "kind", default: 0, null: false @@ -64,7 +64,7 @@ t.index ["product_id"], name: "index_product_predecessors_on_product_id" end - create_table "products", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "products", charset: "utf8", force: :cascade do |t| t.string "name" t.text "description" t.string "shortname" @@ -82,7 +82,7 @@ t.string "friendly_version" end - create_table "products_extensions", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "products_extensions", charset: "utf8", force: :cascade do |t| t.bigint "product_id", null: false t.bigint "extension_id", null: false t.boolean "recommended" @@ -94,7 +94,7 @@ t.index ["root_product_id"], name: "fk_rails_7d0e68d364" end - create_table "repositories", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "repositories", charset: "utf8", force: :cascade do |t| t.bigint "scc_id", unsigned: true t.string "name", null: false t.string "description" @@ -112,7 +112,7 @@ t.index ["scc_id"], name: "index_repositories_on_scc_id", unique: true end - create_table "repositories_services", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "repositories_services", charset: "utf8", 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" @@ -120,21 +120,21 @@ t.index ["service_id"], name: "index_repositories_services_on_service_id" end - create_table "services", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "services", charset: "utf8", 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: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "subscription_product_classes", charset: "utf8", 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: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "subscriptions", charset: "utf8", force: :cascade do |t| t.string "regcode", null: false t.string "name", null: false t.string "kind", null: false @@ -149,7 +149,7 @@ t.index ["regcode"], name: "index_subscriptions_on_regcode" end - create_table "systems", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t| + create_table "systems", charset: "utf8", force: :cascade do |t| t.string "login" t.string "password" t.string "hostname" @@ -161,8 +161,8 @@ 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, collation: "utf8mb4_bin" - t.string "instance_data" + t.text "system_information", size: :long + t.text "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" t.check_constraint "json_valid(`system_information`)", name: "system_information"