From 3aedd9d443825dd5ccaea0543be718525e3250f5 Mon Sep 17 00:00:00 2001 From: Felix Schizlein Date: Thu, 26 Oct 2023 16:05:40 +0200 Subject: [PATCH 1/5] Print database migration information when upgrading --- package/obs/rmt-server.spec | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package/obs/rmt-server.spec b/package/obs/rmt-server.spec index 9ffaa3088..65954a5ea 100644 --- a/package/obs/rmt-server.spec +++ b/package/obs/rmt-server.spec @@ -337,6 +337,11 @@ if [ $1 -eq 2 ]; then mv %{app_dir}/config/system_uuid /var/lib/rmt/system_uuid fi bash %{script_dir}/update_rmt_app_dir_permissions.sh %{app_dir} + + echo "RMT database migration in progress. This could take some time." + echo "" + echo "To check current migration status:" + echo " systemctl status rmt-server-migration.service" fi if [ ! -e %{_datadir}/rmt/public/repo ]; then @@ -348,7 +353,7 @@ if [ ! -e %{_datadir}/rmt/public/suma ]; then fi %preun -%service_del_preun rmt-server.target rmt-server.service rmt-server-migration.service rmt-server-mirror.service rmt-server-sync.service rmt-server-systems-scc-sync.service +%service_del_preun rmt-server.target rmt-server.service rmt-server-mirror.service rmt-server-sync.service rmt-server-systems-scc-sync.service %postun %service_del_postun rmt-server.target rmt-server.service rmt-server-migration.service rmt-server-mirror.service rmt-server-sync.service rmt-server-systems-scc-sync.service From cfd1bcc5cc98465bfa89c6373034275a383ea40a Mon Sep 17 00:00:00 2001 From: Felix Schizlein Date: Thu, 26 Oct 2023 16:39:25 +0200 Subject: [PATCH 2/5] 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" From 3a9fa7a902c55553c95fe6ec8e05f49b22ee5162 Mon Sep 17 00:00:00 2001 From: Felix Schizlein Date: Wed, 29 Nov 2023 18:27:15 +0100 Subject: [PATCH 3/5] 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" From e00e468849061c9f45562c2f20f7cdf931c521d1 Mon Sep 17 00:00:00 2001 From: Felix Schizlein Date: Fri, 1 Dec 2023 17:59:28 +0100 Subject: [PATCH 4/5] Allow instance_data officially in rmt to rmt regsharing context --- .../controllers/registration_sharing/rmt_to_rmt_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/registration_sharing/app/controllers/registration_sharing/rmt_to_rmt_controller.rb b/engines/registration_sharing/app/controllers/registration_sharing/rmt_to_rmt_controller.rb index 52594f9f4..7d06ddef6 100644 --- a/engines/registration_sharing/app/controllers/registration_sharing/rmt_to_rmt_controller.rb +++ b/engines/registration_sharing/app/controllers/registration_sharing/rmt_to_rmt_controller.rb @@ -34,7 +34,7 @@ def destroy protected def system_params - params.permit(:login, :password, :hostname, :proxy_byos, :system_token, :registered_at, :created_at, :last_seen_at) + params.permit(:login, :password, :hostname, :proxy_byos, :system_token, :registered_at, :created_at, :last_seen_at, :instance_data) end def authenticate From dc41c732a8e8eba64fa61f3531dda49d8f9b0f2b Mon Sep 17 00:00:00 2001 From: Felix Schizlein Date: Thu, 7 Dec 2023 12:33:43 +0100 Subject: [PATCH 5/5] Bring back rmt-server-migration.service in rpm service pre uninstall section --- package/obs/rmt-server.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/obs/rmt-server.spec b/package/obs/rmt-server.spec index 65954a5ea..f9e34fe90 100644 --- a/package/obs/rmt-server.spec +++ b/package/obs/rmt-server.spec @@ -353,7 +353,7 @@ if [ ! -e %{_datadir}/rmt/public/suma ]; then fi %preun -%service_del_preun rmt-server.target rmt-server.service rmt-server-mirror.service rmt-server-sync.service rmt-server-systems-scc-sync.service +%service_del_preun rmt-server.target rmt-server.service rmt-server-migration.service rmt-server-mirror.service rmt-server-sync.service rmt-server-systems-scc-sync.service %postun %service_del_postun rmt-server.target rmt-server.service rmt-server-migration.service rmt-server-mirror.service rmt-server-sync.service rmt-server-systems-scc-sync.service