retrospring/db/migrate/20210814134115_create_user_bans.rb
Karina Kwiatek e4241d2001 Create user ban model
Co-authored-by: Georg Gadinger <nilsding@nilsding.org>
2022-01-02 19:50:01 +01:00

28 lines
790 B
Ruby

class CreateUserBans < ActiveRecord::Migration[5.2]
def up
create_table :user_bans do |t|
t.bigint :user_id
t.string :reason
t.datetime :expires_at
t.bigint :banned_by_id, nullable: true
t.timestamps
end
# foxy's functional fqueries
execute "INSERT INTO user_bans
(user_id, reason, expires_at, created_at, updated_at)
SELECT users.id, users.ban_reason, users.banned_until, users.updated_at, NOW() FROM users
WHERE banned_until IS NOT NULL AND NOT permanently_banned;"
execute "INSERT INTO user_bans
(user_id, reason, expires_at, created_at, updated_at)
SELECT users.id, users.ban_reason, NULL, users.updated_at, NOW() FROM users
WHERE permanently_banned;"
end
def down
drop_table :user_bans
end
end