2020-08-07 01:14:14 +02:00
|
|
|
class CreateUsers < ActiveRecord::Migration[4.2]
|
2009-01-06 11:49:19 +01:00
|
|
|
USER_ADMIN = 'admin'
|
|
|
|
USER_TEST = 'test'
|
|
|
|
|
|
|
|
def self.up
|
|
|
|
create_table :users do |t|
|
2023-05-12 13:01:12 +02:00
|
|
|
t.column :nick, :string, null: false
|
|
|
|
t.column :password_hash, :string, null: false
|
|
|
|
t.column :password_salt, :string, null: false
|
|
|
|
t.column :first_name, :string, null: false
|
|
|
|
t.column :last_name, :string, null: false
|
|
|
|
t.column :email, :string, null: false
|
2009-01-06 11:49:19 +01:00
|
|
|
t.column :phone, :string
|
|
|
|
t.column :address, :string
|
2023-05-12 13:01:12 +02:00
|
|
|
t.column :created_on, :timestamp, null: false
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2023-05-12 13:01:12 +02:00
|
|
|
add_index(:users, :nick, unique: true)
|
|
|
|
add_index(:users, :email, unique: true)
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Create the default admin user...
|
|
|
|
puts "Creating user #{USER_ADMIN} with password 'secret'..."
|
2023-05-12 13:01:12 +02:00
|
|
|
user = User.new(nick: USER_ADMIN, first_name: 'Anton', last_name: 'Administrator',
|
|
|
|
email: 'admin@foo.test')
|
|
|
|
user.password = 'secret'
|
|
|
|
raise 'Failed!' unless user.save && User.find_by_nick(USER_ADMIN).has_password('secret')
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Create a normal user...
|
|
|
|
puts "Creating user #{USER_TEST} with password 'foobar'..."
|
2023-05-12 13:01:12 +02:00
|
|
|
user = User.new(nick: USER_TEST, first_name: 'Tim', last_name: 'Tester', email: 'test@foo.test')
|
|
|
|
user.password = 'foobar'
|
|
|
|
raise 'Failed!' unless user.save && User.find_by_nick(USER_TEST).has_password('foobar')
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
drop_table :users
|
|
|
|
end
|
|
|
|
end
|