Skip to content

Commit

Permalink
Make systems.instance_data a text rather then a string and cleanup sc…
Browse files Browse the repository at this point in the history
…hema.rb
  • Loading branch information
felixsch committed Nov 29, 2023
1 parent cfd1bcc commit df6c128
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
25 changes: 15 additions & 10 deletions db/migrate/20230814105634_move_hw_info_to_systems_table.rb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 14 additions & 14 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -112,29 +112,29 @@
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"
t.index ["service_id", "repository_id"], name: "index_repositories_services_on_service_id_and_repository_id", unique: true
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
Expand All @@ -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"
Expand All @@ -162,7 +162,7 @@
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 "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"
Expand Down

0 comments on commit df6c128

Please sign in to comment.