このコミットが含まれているのは:
@@ -1,9 +1,12 @@
|
||||
class AddColumnsToTagNames < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
add_reference :tag_names, :tag, after: :id, foreign_key: true
|
||||
add_column :tag_names, :language_code, :string,
|
||||
limit: 16, null: false, after: :id, default: 'ja'
|
||||
limit: 16, null: false, after: :tag_id, default: 'ja'
|
||||
add_column :tag_names, :script_code, 'CHAR(4)',
|
||||
null: false, after: :name, default: 'Jpan'
|
||||
add_column :tag_names, :primary_flg, :boolean,
|
||||
null: false, after: :script_code, default: true
|
||||
|
||||
add_foreign_key :tag_names, :languages, column: :language_code, primary_key: :code
|
||||
add_foreign_key :tag_names, :scripts, column: :script_code, primary_key: :code
|
||||
@@ -13,16 +16,44 @@ class AddColumnsToTagNames < ActiveRecord::Migration[8.0]
|
||||
|
||||
change_column_default :tag_names, :language_code, from: 'ja', to: nil
|
||||
change_column_default :tag_names, :script_code, from: 'Jpan', to: nil
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE
|
||||
tag_names tn
|
||||
LEFT JOIN
|
||||
tags AS t
|
||||
ON
|
||||
t.tag_name_id = COALESCE(tn.canonical_id, tn.id)
|
||||
SET
|
||||
tn.tag_id = t.id
|
||||
, tn.primary_flg = CASE
|
||||
WHEN tn.canonical_id IS NULL THEN
|
||||
1
|
||||
ELSE
|
||||
0
|
||||
END
|
||||
SQL
|
||||
|
||||
change_column_default :tag_names, :primary_flg, from: true, to: nil
|
||||
|
||||
add_column :tag_names, :primary_tag_id, :bigint,
|
||||
as: 'CASE WHEN primary_flg THEN tag_id ELSE NULL END'
|
||||
add_index :tag_names, [:primary_tag_id, :language_code], unique: true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :tag_names, [:primary_tag_id, :language_code]
|
||||
remove_column :tag_names, :primary_tag_id
|
||||
|
||||
remove_foreign_key :tag_names, column: :language_code
|
||||
remove_foreign_key :tag_names, column: :script_code
|
||||
|
||||
remove_index :tag_names, [:language_code, :name]
|
||||
add_index :tag_names, :name, unique: true
|
||||
|
||||
remove_column :tag_names, :primary_flg
|
||||
remove_column :tag_names, :script_code
|
||||
remove_column :tag_names, :language_code
|
||||
remove_reference :tag_names, :tag, foreign_key: true
|
||||
end
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする