このコミットが含まれているのは:
2026-08-06 06:49:05 +09:00
コミット acd8046a77
3個のファイルの変更36行の追加15行の削除
+33 -13
ファイルの表示
@@ -30,19 +30,46 @@ class AddTagsJsonToPostVersions < ActiveRecord::Migration[8.0]
intervals_by_name = build_intervals_by_name
say_with_time 'Backfilling post_versions.tags_json' do
MigrationPostVersion
.where(tags_json: nil)
.find_each(batch_size: 500) do |version|
version.update_columns(
tags_json: build_tags_json(version, intervals_by_name))
MigrationPostVersion.where(tags_json: nil).find_each(batch_size: 500) do |version|
version.update_columns(tags_json: build_tags_json(version, intervals_by_name))
end
end
assert_backfill_complete!
change_column_null :post_versions, :tags_json, false
schema = connection.quote(JSON.generate({
type: 'array',
items: { type: 'object',
properties: { id: { type: 'integer', minimum: 1 },
version_no: { type: 'integer', minimum: 1 },
name: { type: 'string', minLength: 1 },
category: { type: 'string', enum: ['deerjikist',
'meme',
'character',
'general',
'material',
'meta',
'nico'] },
sections: { type: 'array',
items: { type: 'object',
properties: { begin_ms: { type: 'integer',
minimum: 0 },
end_ms: { type: ['integer',
'null'],
minimum: 0 } },
required: ['begin_ms', 'end_ms'],
additionalProperties: false } } },
required: ['id', 'version_no', 'name', 'category', 'sections'],
additionalProperties: false } }))
add_check_constraint :post_versions,
"JSON_SCHEMA_VALID(#{ schema }, tags_json)",
name: 'chk_post_versions_tags_json_schema'
end
def down
remove_check_constraint :post_versions, name: 'chk_post_versions_tags_json_schema'
remove_column :post_versions, :tags_json
end
@@ -269,11 +296,4 @@ class AddTagsJsonToPostVersions < ActiveRecord::Migration[8.0]
raise "Duplicate tag IDs: #{ details }"
end
def assert_backfill_complete!
missing_count = MigrationPostVersion.where(tags_json: nil).count
return if missing_count.zero?
raise "#{ missing_count } post versions were not backfilled"
end
end