mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
better revision history
This commit is contained in:
25
db/migrate/20131209091702_create_post_revisions.rb
Normal file
25
db/migrate/20131209091702_create_post_revisions.rb
Normal file
@ -0,0 +1,25 @@
|
||||
class CreatePostRevisions < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :post_revisions do |t|
|
||||
t.belongs_to :user
|
||||
t.belongs_to :post
|
||||
t.text :modifications
|
||||
t.integer :number
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
execute "INSERT INTO post_revisions (user_id, post_id, modifications, number, created_at, updated_at)
|
||||
SELECT user_id, versioned_id, modifications, number, created_at, updated_at
|
||||
FROM versions
|
||||
WHERE versioned_type = 'Post'"
|
||||
|
||||
change_table :post_revisions do |t|
|
||||
t.index :post_id
|
||||
t.index [:post_id, :number]
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :post_revisions
|
||||
end
|
||||
end
|
25
db/migrate/20131209091742_create_topic_revisions.rb
Normal file
25
db/migrate/20131209091742_create_topic_revisions.rb
Normal file
@ -0,0 +1,25 @@
|
||||
class CreateTopicRevisions < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :topic_revisions do |t|
|
||||
t.belongs_to :user
|
||||
t.belongs_to :topic
|
||||
t.text :modifications
|
||||
t.integer :number
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
execute "INSERT INTO topic_revisions (user_id, topic_id, modifications, number, created_at, updated_at)
|
||||
SELECT user_id, versioned_id, modifications, number, created_at, updated_at
|
||||
FROM versions
|
||||
WHERE versioned_type = 'Topic'"
|
||||
|
||||
change_table :topic_revisions do |t|
|
||||
t.index :topic_id
|
||||
t.index [:topic_id, :number]
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :topic_revisions
|
||||
end
|
||||
end
|
9
db/migrate/20131210234530_rename_version_column.rb
Normal file
9
db/migrate/20131210234530_rename_version_column.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class RenameVersionColumn < ActiveRecord::Migration
|
||||
|
||||
def change
|
||||
add_column :posts, :version, :integer, default: 1, null: false
|
||||
execute "UPDATE posts SET version = cached_version"
|
||||
remove_column :posts, :cached_version
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user