-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_setup.rb
32 lines (26 loc) · 954 Bytes
/
database_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
require 'sequel'
require 'dotenv/load'
#create database
Sequel.connect(adapter: :"#{ENV['DB_ADAPTER']}", user: ENV['DB_USER'], password: ENV['DB_PASS'], host: ENV['DB_HOST']) {|db| db.execute "CREATE DATABASE #{ENV['DB_BASE']}"}
#create tables
DB = Sequel.connect(adapter: :"#{ENV['DB_ADAPTER']}", user: ENV['DB_USER'], password: ENV['DB_PASS'], host: ENV['DB_HOST'], database: ENV['DB_BASE'])
#migration
DB.create_table :apps do
primary_key :id
String :name, unique: true, null: false
String :ref_icon
String :category
String :dowload_count
String :author
String :author_email
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
end
DB.create_table :ratings do
primary_key :id
String :rating, null: false
foreign_key :app_id, :apps, null: false
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
index :app_id
end
puts 'Successfully created database and tables'
puts '########################################'