-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
69 lines (57 loc) · 1.76 KB
/
Rakefile
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'sequel'
require 'yaml'
require 'carrierwave'
require 'carrierwave/sequel'
# Load config file
settings = YAML.load(File.open('config.yml'))
namespace :db do
Sequel.extension :migration, :core_extensions
migrator = Sequel::Migrator
migrations = settings['migrations_path']
environment = settings['environment']
env_settngs = settings[environment]
# Setup Database Connection
case environment
when 'development'
db_host = env_settngs['db_host']
db_name = env_settngs['db_name']
db_user = env_settngs['db_user']
DB = Sequel.postgres(db_name,
host: db_host,
user: db_user)
when 'production'
db_host = env_settngs['db_host']
db_name = env_settngs['db_name']
db_user = env_settngs['db_user']
db_password = env_settngs['db_password']
DB = Sequel.postgres(db_name,
host: db_host,
user: db_user,
password: db_password)
end
Sequel::Model.plugin :validation_helpers
Dir.glob('./{uploaders,models}/*.rb').each { |file| require file }
desc 'Reverts all migrations.'
task :drop do
puts 'Reverting all migrations...'
migrator.apply(DB, migrations, 0)
puts 'Done!'
end
desc 'Migrates to newest migration.'
task :migrate do
puts 'Migrating to newest migration...'
migrator.apply(DB, migrations)
puts 'Done!'
end
desc 'Reverts all migrations and migrates to newest migrations.'
task :reset do
Rake::Task['db:drop'].execute
Rake::Task['db:migrate'].execute
end
desc 'Fills the database with dummy data'
task :seed do
puts 'Populating database with dummy data...'
require './database/seed_dummy_data.rb'
puts 'Done!'
end
end