ingang/db/migrate/20230123193409_create_votes.rb

17 lines
552 B
Ruby

class CreateVotes < ActiveRecord::Migration[6.0]
def change
create_table :votes do |t|
t.references :room, null: false, foreign_key: true
t.references :user, null: false, foreign_key: true
t.string :election_slug
t.string :voter_login_id
t.string :voter_password
t.timestamps
end
change_column_default :votes, :created_at, from: nil, to: ->{ 'now()' }
change_column_default :votes, :updated_at, from: nil, to: ->{ 'now()' }
add_index :votes, [:user_id, :election_slug], unique: true
end
end