-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
35 lines (29 loc) · 810 Bytes
/
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
require 'sequel'
namespace :db do
DB = Sequel.connect(
adapter: 'postgres',
host: ENV.fetch('DB_HOST', 'localhost'),
port: ENV.fetch('DB_PORT', 5432),
database: ENV.fetch('DB_NAME', 'fraud_detection_development'),
user: ENV.fetch('DB_USER', 'fraud_detection'),
password: ENV.fetch('DB_PASSWORD', 'password')
)
migrate = lambda do |version|
Sequel.extension :migration
Sequel::Migrator.run(DB, 'db/migrations', target: version)
end
desc 'Run migrations'
task :migrate do
migrate.call(nil)
end
desc 'Rollback last migration'
task :rollback do
latest = DB[:schema_info].select_map(:version).first
migrate.call(latest - 1)
end
desc 'Reset database'
task :reset do
migrate.call(0)
Sequel::Migrator.run(DB, 'db/migrations')
end
end