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
|
||||
Generated
+7
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_05_01_153900) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_05_07_213300) do
|
||||
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
@@ -186,8 +186,10 @@ ActiveRecord::Schema[8.0].define(version: 2026_05_01_153900) do
|
||||
t.datetime "original_created_from"
|
||||
t.datetime "original_created_before"
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "version_no", null: false
|
||||
t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id"
|
||||
t.index ["url"], name: "index_posts_on_url", unique: true
|
||||
t.check_constraint "`version_no` > 0", name: "chk_posts_version_no_positive"
|
||||
end
|
||||
|
||||
create_table "settings", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
@@ -262,8 +264,10 @@ ActiveRecord::Schema[8.0].define(version: 2026_05_01_153900) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "post_count", default: 0, null: false
|
||||
t.datetime "discarded_at"
|
||||
t.integer "version_no", null: false
|
||||
t.index ["discarded_at"], name: "index_tags_on_discarded_at"
|
||||
t.index ["tag_name_id"], name: "index_tags_on_tag_name_id", unique: true
|
||||
t.check_constraint "`version_no` > 0", name: "chk_tags_version_no_positive"
|
||||
end
|
||||
|
||||
create_table "theatre_comments", primary_key: ["theatre_id", "no"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
@@ -369,10 +373,12 @@ ActiveRecord::Schema[8.0].define(version: 2026_05_01_153900) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "discarded_at"
|
||||
t.integer "next_asset_no", default: 1, null: false
|
||||
t.integer "version_no", null: false
|
||||
t.index ["created_user_id"], name: "index_wiki_pages_on_created_user_id"
|
||||
t.index ["discarded_at"], name: "index_wiki_pages_on_discarded_at"
|
||||
t.index ["tag_name_id"], name: "index_wiki_pages_on_tag_name_id", unique: true
|
||||
t.index ["updated_user_id"], name: "index_wiki_pages_on_updated_user_id"
|
||||
t.check_constraint "`version_no` > 0", name: "chk_wiki_pages_version_no_positive"
|
||||
end
|
||||
|
||||
create_table "wiki_revision_lines", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
|
||||
Reference in New Issue
Block a user