discourse/db/migrate/20190110212005_create_revie...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class CreateReviewableHistories < ActiveRecord::Migration[5.2]
def change
create_table :reviewable_histories do |t|
t.integer :reviewable_id, null: false
t.integer :reviewable_history_type, null: false
t.integer :status, null: false
t.integer :created_by_id, null: false
t.json :edited, null: true
t.timestamps
end
add_index :reviewable_histories, :reviewable_id
2019-03-28 14:57:44 -04:00
# Migrate Created ReviewableUser History
execute(<<~SQL)
INSERT INTO reviewable_histories (
reviewable_id,
reviewable_history_type,
status,
created_by_id,
created_at,
updated_at
)
SELECT r.id,
0,
0,
r.created_by_id,
r.created_at,
r.created_at
FROM reviewables AS r
WHERE r.type = 'ReviewableUser'
SQL
2019-03-28 14:57:44 -04:00
execute(<<~SQL)
INSERT INTO reviewable_histories (
reviewable_id,
reviewable_history_type,
status,
created_by_id,
created_at,
updated_at
)
SELECT r.id,
1,
1,
r.created_by_id,
r.created_at,
r.created_at
FROM reviewables AS r
2019-03-28 15:31:14 -04:00
WHERE r.status = 1
AND r.type = 'ReviewableUser'
2019-03-28 14:57:44 -04:00
SQL
end
end