このコミットが含まれているのは:
@@ -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
|
||||
|
||||
新しい課題から参照
ユーザをブロックする