2020-03-24 16:45:27 +01:00
|
|
|
# frozen_string_literal:true
|
|
|
|
|
|
|
|
class CreateWallets < ActiveRecord::Migration[4.2]
|
2016-07-18 18:16:54 +02:00
|
|
|
def up
|
|
|
|
create_table :wallets do |t|
|
|
|
|
t.belongs_to :user, index: true, foreign_key: true
|
|
|
|
t.integer :amount, default: 0
|
|
|
|
|
|
|
|
t.timestamps null: false
|
|
|
|
end
|
|
|
|
|
2020-04-08 15:00:22 +02:00
|
|
|
# create all wallets
|
|
|
|
execute <<-SQL
|
2020-04-08 15:55:08 +02:00
|
|
|
INSERT INTO wallets (user_id, amount, created_at, updated_at)
|
|
|
|
SELECT users.id, 0, '#{DateTime.current.iso8601}', '#{DateTime.current.iso8601}'
|
2020-04-08 15:00:22 +02:00
|
|
|
FROM users
|
|
|
|
SQL
|
2016-07-18 18:16:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
drop_table :wallets
|
|
|
|
end
|
|
|
|
end
|