forked from lighthouse-labs/ar-exercises
/
setup.rb
44 lines (39 loc) · 1.21 KB
/
setup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'pry' # in case you want to use binding.pry
require 'active_record'
require_relative 'lib/store'
require_relative 'lib/employee'
# Output messages from Active Record to standard out
ActiveRecord::Base.logger = Logger.new(STDOUT)
puts 'Establishing connection to database ...'
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'ar_exercises',
username: 'development',
password: 'development',
host: 'localhost',
port: 5432,
pool: 5,
encoding: 'unicode',
min_messages: 'error'
)
puts 'CONNECTED'
puts 'Setting up Database (recreating tables) ...'
ActiveRecord::Schema.define do
drop_table :stores if ActiveRecord::Base.connection.table_exists?(:stores)
drop_table :employees if ActiveRecord::Base.connection.table_exists?(:employees)
create_table :stores do |t|
t.column :name, :string
t.column :annual_revenue, :integer
t.column :mens_apparel, :boolean
t.column :womens_apparel, :boolean
t.timestamps null: false
end
create_table :employees do |table|
table.references :store
table.column :first_name, :string
table.column :last_name, :string
table.column :hourly_rate, :integer
table.timestamps null: false
end
end
puts 'Setup DONE'