このコミットが含まれているのは:
2026-10-01 22:56:15 +09:00
コミット 0b9fa03f6d
6個のファイルの変更、112行の追加、9行の削除
+4 -1
ファイルの表示
@@ -4,13 +4,16 @@ class CreateScripts < ActiveRecord::Migration[8.0]
t.string :name, null: false
t.datetime :deprecated_at, index: true
t.datetime :created_at, null: false
t.check_constraint "REGEXP_LIKE(code, '^[A-Z][a-z]{3}$', 'c')",
name: 'scripts_code_check'
end
execute <<~SQL
INSERT INTO
scripts(code, name, created_at)
VALUES
('Jpan', '漢字および仮名文字', #{ connection.quote Time.current })
('Jpan', '漢字、仮名文字およびラテン文字', #{ connection.quote Time.current })
SQL
end
+25
ファイルの表示
@@ -0,0 +1,25 @@
class CreateRegions < ActiveRecord::Migration[8.0]
def up
create_table :regions, id: { type: :integer, limit: 2 }, primary_key: :code do |t|
t.column :alpha_code, 'CHAR(2)'
t.string :name, null: false
t.datetime :deprecated_at, index: true
t.datetime :created_at, null: false
t.check_constraint "REGEXP_LIKE(alpha_code, '^[A-Z]{2}$', 'c')",
name: 'regions_alpha_code_check'
t.index [:alpha_code], unique: true
end
execute <<~SQL
INSERT INTO
regions(code, alpha_code, name, created_at)
VALUES
(392, 'JP', '日本国', #{ connection.quote Time.current })
SQL
end
def down
drop_table :regions
end
end
+15 -2
ファイルの表示
@@ -3,19 +3,32 @@ class CreateLocales < ActiveRecord::Migration[8.0]
create_table :locales, id: { type: :string, limit: 32 }, primary_key: :code do |t|
t.string :language_code, limit: 16, null: false, index: true
t.column :script_code, 'CHAR(4)', null: false
t.integer :region_code, limit: 2, null: false
t.string :variants, limit: 255, null: false, default: ''
t.string :name, null: false
t.datetime :deprecated_at, index: true
t.datetime :created_at, null: false
t.foreign_key :languages, column: :language_code, primary_key: :code
t.foreign_key :scripts, column: :script_code, primary_key: :code
t.foreign_key :regions, column: :region_code, primary_key: :code
t.check_constraint ('REGEXP_LIKE(variants, ' +
"'^(" +
'(([a-z0-9]{5,8}|[0-9][a-z0-9]{3})' +
'(-([a-z0-9]{5,8}|[0-9][a-z0-9]{3}))*' +
'(-x(-[a-z0-9]{1,8})+)?)' +
'|(x(-[a-z0-9]{1,8})+)' +
")?$', 'c')"),
name: 'locales_variants_check'
t.index [:language_code, :script_code, :region_code, :variants], unique: true
end
execute <<~SQL
INSERT INTO
locales(code, language_code, script_code, name, created_at)
locales(code, language_code, script_code, region_code, name, created_at)
VALUES
('ja', 'ja', 'Jpan', '日本語', #{ connection.quote Time.current })
('ja', 'ja', 'Jpan', 392, '日本語', #{ connection.quote Time.current })
SQL
end
+8 -1
ファイルの表示
@@ -8,7 +8,7 @@ class AddColumnsToTagNames < ActiveRecord::Migration[8.0]
add_column :tag_names, :primary_flg, :boolean,
null: false, after: :script_code, default: true
add_column :tag_names, :auto_generated, :boolean,
null: false, default: true, after: :primary_flg
null: false, default: false, after: :primary_flg
add_foreign_key :tag_names, :languages, column: :language_code, primary_key: :code
add_foreign_key :tag_names, :scripts, column: :script_code, primary_key: :code
@@ -41,9 +41,16 @@ class AddColumnsToTagNames < ActiveRecord::Migration[8.0]
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
add_check_constraint :tag_names,
'primary_flg OR (NOT auto_generated)',
name: 'chk_tag_names_auto_generated_primary'
end
def down
remove_check_constraint :tag_names,
name: 'chk_tag_names_auto_generated_primary'
remove_index :tag_names, [:primary_tag_id, :language_code]
remove_column :tag_names, :primary_tag_id
+40 -4
ファイルの表示
@@ -10,10 +10,7 @@ class AddNamesToTagVersions < ActiveRecord::Migration[8.0]
say_with_time 'Backfilling multilingual tag version names' do
TagVersion.find_each do |version|
aliases = version.aliases.to_s.split.filter_map do |name|
name.present? &&
{ name:,
script_code: 'Jpan',
auto_generated: false }
name.present? && { name:, script_code: 'Jpan' }
end
names = { ja: { name: version.name,
script_code: 'Jpan',
@@ -23,10 +20,49 @@ class AddNamesToTagVersions < ActiveRecord::Migration[8.0]
end
end
add_names_constraint!
change_column_null :tag_versions, :names, false
end
def down
remove_check_constraint :tag_versions,
name: 'chk_tag_versions_names_schema'
remove_column :tag_versions, :names
end
private
def add_names_constraint!
schema = { type: 'object',
minProperties: 1,
patternProperties: { '^.{1,16}$': name_schema },
additionalProperties: false }
quoted_schema = connection.quote(JSON.generate(schema))
add_check_constraint :tag_versions,
"JSON_SCHEMA_VALID(#{ quoted_schema }, names)",
name: 'chk_tag_versions_names_schema'
end
def name_schema
{ type: 'object',
required: ['name', 'script_code', 'auto_generated', 'aliases'],
properties: { **name_schema_base,
auto_generated: { type: 'boolean' },
aliases: { type: 'array',
uniqueItems: true,
items: { type: 'object',
required: ['name', 'script_code'],
properties: name_schema_base,
additionalProperties: false } } },
additionalProperties: false }
end
def name_schema_base
{ name: { type: 'string', minLength: 1, maxLength: 255 },
script_code: { type: 'string', pattern: '^[A-Z][a-z]{3}$' } }
end
end