Skip to content

Instantly share code, notes, and snippets.

@byronmejia
Created September 2, 2016 01:03
Show Gist options
  • Save byronmejia/af5507b5f340bb8bacba45c7bdc22fc0 to your computer and use it in GitHub Desktop.
Save byronmejia/af5507b5f340bb8bacba45c7bdc22fc0 to your computer and use it in GitHub Desktop.
# Migration (This sits in db/migration folder) -------------------------
Sequel.migration do
up do
# Create Users table
create_table(:logins) do
primary_key :id
String :user_name, unique: true, null: false
String :password_hash, null: false
end
end
down do
drop_table(:logins)
end
end
# ORM (This sits in models folder) ---------------------------------
class Login < Sequel::Model
plugin :secure_password, cost: 12, digest_column: :password_hash
end
# Seed (This sits in db/seed.rb) -------------------------------------
require_relative '../app/app'
login = Login.new
login.user_name = 'admin'
login.password = 'password'
login.password_confirmation = 'password'
puts 'Created Login' if login.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment