This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
class AddVersionNoToPosts < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
add_column :posts, :version_no, :integer
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE
|
||||
posts
|
||||
SET
|
||||
version_no = (
|
||||
SELECT
|
||||
MAX(version_no)
|
||||
FROM
|
||||
post_versions
|
||||
WHERE
|
||||
post_id = posts.id)
|
||||
SQL
|
||||
|
||||
change_column_null :posts, :version_no, false
|
||||
|
||||
add_check_constraint :posts, 'version_no > 0', name: 'chk_posts_version_no_positive'
|
||||
end
|
||||
|
||||
def down
|
||||
remove_check_constraint :posts, name: 'chk_posts_version_no_positive'
|
||||
remove_column :posts, :version_no
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
class AddVersionNoToTags < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
add_column :tags, :version_no, :integer
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE
|
||||
tags
|
||||
SET
|
||||
version_no = (
|
||||
CASE category
|
||||
WHEN 'nico' THEN
|
||||
(SELECT
|
||||
MAX(version_no)
|
||||
FROM
|
||||
nico_tag_versions
|
||||
WHERE
|
||||
tag_id = tags.id)
|
||||
ELSE
|
||||
(SELECT
|
||||
MAX(version_no)
|
||||
FROM
|
||||
tag_versions
|
||||
WHERE
|
||||
tag_id = tags.id)
|
||||
END)
|
||||
SQL
|
||||
|
||||
change_column_null :tags, :version_no, false
|
||||
|
||||
add_check_constraint :tags, 'version_no > 0', name: 'chk_tags_version_no_positive'
|
||||
end
|
||||
|
||||
def down
|
||||
remove_check_constraint :tags, name: 'chk_tags_version_no_positive'
|
||||
remove_column :tags, :version_no
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
class AddVersionNoToWikiPages < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
add_column :wiki_pages, :version_no, :integer
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE
|
||||
wiki_pages
|
||||
SET
|
||||
version_no = (
|
||||
SELECT
|
||||
MAX(version_no)
|
||||
FROM
|
||||
wiki_versions
|
||||
WHERE
|
||||
wiki_page_id = wiki_pages.id)
|
||||
SQL
|
||||
|
||||
change_column_null :wiki_pages, :version_no, false
|
||||
|
||||
add_check_constraint :wiki_pages, 'version_no > 0', name: 'chk_wiki_pages_version_no_positive'
|
||||
end
|
||||
|
||||
def down
|
||||
remove_check_constraint :wiki_pages, name: 'chk_wiki_pages_version_no_positive'
|
||||
remove_column :wiki_pages, :version_no
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user