Merge commit '32f0e619f0
' into kb_migration_development
This commit is contained in:
commit
7c118ed1d0
446 changed files with 6295 additions and 3456 deletions
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MoveUserSettings < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class User < ApplicationRecord; end
|
||||
|
||||
MAPPING = {
|
||||
|
@ -63,26 +65,29 @@ class MoveUserSettings < ActiveRecord::Migration[6.1]
|
|||
end
|
||||
|
||||
def up
|
||||
User.find_each do |user|
|
||||
previous_settings = LegacySetting.where(thing_type: 'User', thing_id: user.id).index_by(&:var)
|
||||
User.find_in_batches do |users|
|
||||
previous_settings_for_batch = LegacySetting.where(thing_type: 'User', thing_id: users.map(&:id)).group_by(&:thing_id)
|
||||
|
||||
user_settings = {}
|
||||
users.each do |user|
|
||||
previous_settings = previous_settings_for_batch[user.id]&.index_by(&:var) || {}
|
||||
user_settings = {}
|
||||
|
||||
MAPPING.each do |legacy_key, new_key|
|
||||
value = previous_settings[legacy_key]&.value
|
||||
MAPPING.each do |legacy_key, new_key|
|
||||
value = previous_settings[legacy_key]&.value
|
||||
|
||||
next if value.blank?
|
||||
next if value.blank?
|
||||
|
||||
if value.is_a?(Hash)
|
||||
value.each do |nested_key, nested_value|
|
||||
user_settings[MAPPING[legacy_key][nested_key.to_sym]] = nested_value
|
||||
if value.is_a?(Hash)
|
||||
value.each do |nested_key, nested_value|
|
||||
user_settings[MAPPING[legacy_key][nested_key.to_sym]] = nested_value
|
||||
end
|
||||
else
|
||||
user_settings[new_key] = value
|
||||
end
|
||||
else
|
||||
user_settings[new_key] = value
|
||||
end
|
||||
end
|
||||
|
||||
user.update_column('settings', Oj.dump(user_settings)) # rubocop:disable Rails/SkipsModelValidations
|
||||
user.update_column('settings', Oj.dump(user_settings)) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
22
db/migrate/20230330135507_create_bulk_imports.rb
Normal file
22
db/migrate/20230330135507_create_bulk_imports.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateBulkImports < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :bulk_imports do |t|
|
||||
t.integer :type, null: false
|
||||
t.integer :state, null: false
|
||||
t.integer :total_items, null: false, default: 0
|
||||
t.integer :imported_items, null: false, default: 0
|
||||
t.integer :processed_items, null: false, default: 0
|
||||
t.datetime :finished_at
|
||||
t.boolean :overwrite, null: false, default: false
|
||||
t.boolean :likely_mismatched, null: false, default: false
|
||||
t.string :original_filename, null: false, default: ''
|
||||
t.references :account, null: false, foreign_key: { on_delete: :cascade }
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :bulk_imports, [:id], name: :index_bulk_imports_unconfirmed, where: 'state = 0'
|
||||
end
|
||||
end
|
12
db/migrate/20230330140036_create_bulk_import_rows.rb
Normal file
12
db/migrate/20230330140036_create_bulk_import_rows.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateBulkImportRows < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :bulk_import_rows do |t|
|
||||
t.references :bulk_import, null: false, foreign_key: { on_delete: :cascade }
|
||||
t.jsonb :data
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddFollowRequestIdToListAccounts < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
safety_assured { add_reference :list_accounts, :follow_request, foreign_key: { on_delete: :cascade }, index: false }
|
||||
add_index :list_accounts, :follow_request_id, algorithm: :concurrently, where: 'follow_request_id IS NOT NULL'
|
||||
end
|
||||
end
|
34
db/schema.rb
34
db/schema.rb
|
@ -1,3 +1,5 @@
|
|||
# rubocop:disable all
|
||||
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
|
@ -361,6 +363,31 @@ ActiveRecord::Schema.define(version: 2023_04_30_110057) do
|
|||
t.index ["status_id"], name: "index_bookmarks_on_status_id"
|
||||
end
|
||||
|
||||
create_table "bulk_import_rows", force: :cascade do |t|
|
||||
t.bigint "bulk_import_id", null: false
|
||||
t.jsonb "data"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["bulk_import_id"], name: "index_bulk_import_rows_on_bulk_import_id"
|
||||
end
|
||||
|
||||
create_table "bulk_imports", force: :cascade do |t|
|
||||
t.integer "type", null: false
|
||||
t.integer "state", null: false
|
||||
t.integer "total_items", default: 0, null: false
|
||||
t.integer "imported_items", default: 0, null: false
|
||||
t.integer "processed_items", default: 0, null: false
|
||||
t.datetime "finished_at"
|
||||
t.boolean "overwrite", default: false, null: false
|
||||
t.boolean "likely_mismatched", default: false, null: false
|
||||
t.string "original_filename", default: "", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["account_id"], name: "index_bulk_imports_on_account_id"
|
||||
t.index ["id"], name: "index_bulk_imports_unconfirmed", where: "(state = 0)"
|
||||
end
|
||||
|
||||
create_table "canonical_email_blocks", force: :cascade do |t|
|
||||
t.string "canonical_email_hash", default: "", null: false
|
||||
t.bigint "reference_account_id"
|
||||
|
@ -624,8 +651,10 @@ ActiveRecord::Schema.define(version: 2023_04_30_110057) do
|
|||
t.bigint "list_id", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "follow_id"
|
||||
t.bigint "follow_request_id"
|
||||
t.index ["account_id", "list_id"], name: "index_list_accounts_on_account_id_and_list_id", unique: true
|
||||
t.index ["follow_id"], name: "index_list_accounts_on_follow_id", where: "(follow_id IS NOT NULL)"
|
||||
t.index ["follow_request_id"], name: "index_list_accounts_on_follow_request_id", where: "(follow_request_id IS NOT NULL)"
|
||||
t.index ["list_id", "account_id"], name: "index_list_accounts_on_list_id_and_account_id"
|
||||
end
|
||||
|
||||
|
@ -1266,6 +1295,8 @@ ActiveRecord::Schema.define(version: 2023_04_30_110057) do
|
|||
add_foreign_key "blocks", "accounts", name: "fk_4269e03e65", on_delete: :cascade
|
||||
add_foreign_key "bookmarks", "accounts", on_delete: :cascade
|
||||
add_foreign_key "bookmarks", "statuses", on_delete: :cascade
|
||||
add_foreign_key "bulk_import_rows", "bulk_imports", on_delete: :cascade
|
||||
add_foreign_key "bulk_imports", "accounts", on_delete: :cascade
|
||||
add_foreign_key "canonical_email_blocks", "accounts", column: "reference_account_id", on_delete: :cascade
|
||||
add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
|
||||
add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade
|
||||
|
@ -1294,6 +1325,7 @@ ActiveRecord::Schema.define(version: 2023_04_30_110057) do
|
|||
add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade
|
||||
add_foreign_key "invites", "users", on_delete: :cascade
|
||||
add_foreign_key "list_accounts", "accounts", on_delete: :cascade
|
||||
add_foreign_key "list_accounts", "follow_requests", on_delete: :cascade
|
||||
add_foreign_key "list_accounts", "follows", on_delete: :cascade
|
||||
add_foreign_key "list_accounts", "lists", on_delete: :cascade
|
||||
add_foreign_key "lists", "accounts", on_delete: :cascade
|
||||
|
@ -1450,3 +1482,5 @@ ActiveRecord::Schema.define(version: 2023_04_30_110057) do
|
|||
add_index "follow_recommendations", ["account_id"], name: "index_follow_recommendations_on_account_id", unique: true
|
||||
|
||||
end
|
||||
|
||||
# rubocop:enable all
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue