2019-01-03 12:03:01 -05:00
|
|
|
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
|
2019-03-28 15:25:26 -04:00
|
|
|
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
|
2019-03-28 15:22:39 -04:00
|
|
|
AND r.type = 'ReviewableUser'
|
2019-03-28 14:57:44 -04:00
|
|
|
SQL
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
|
|
|
end
|