Skip to content

Instantly share code, notes, and snippets.

@KitaitiMakoto
Created May 5, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KitaitiMakoto/84a85528494f1caa07ff429d2d5b75ae to your computer and use it in GitHub Desktop.
Save KitaitiMakoto/84a85528494f1caa07ff429d2d5b75ae to your computer and use it in GitHub Desktop.
require "active_record"
config = {
adapter: "sqlserver",
host: "localhost",
port: 1433,
username: "sa",
password: "yourStrong(!)Password",
database: "groupby"
}
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :role
end
end
end
class User < ActiveRecord::Base
end
ActiveRecord::Base.establish_connection config
unless ActiveRecord::Base.connection.data_source_exists? :users
CreateUsers.new.change
3.times do
User.create(role: "member")
User.create(role: "admin")
end
end
p User.group(:role).pluck(:role)
p User.group(:role)
p User.group(:role).exists?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment