-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRakefile
57 lines (45 loc) · 1.29 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
require 'yaml'
env = ENV['MIDORI_ENV'] ? ENV['MIDORI_ENV'] : 'development'
task 'rubocop' do
sh 'bundle exec rubocop'
end
task 'run' do
ruby 'main.rb'
end
namespace :vue do
task :install do
sh 'cd ./frontend; yarn'
end
task :build do
sh 'cd ./frontend; npm run build'
end
end
namespace :db do
require "sequel"
Sequel.extension :migration
DB = Sequel.connect(YAML.load_file('config/db.yml')[env])
desc 'Prints current schema version'
task :version do
version = if DB.tables.include?(:schema_info)
DB[:schema_info].first[:version]
end || 0
puts "Schema Version: #{version}"
end
desc 'Perform migration up to latest migration available'
task :migrate do
Sequel::Migrator.run(DB, "migrations")
Rake::Task['db:version'].execute
end
desc 'Perform rollback to specified target or full rollback as default'
task :rollback, :target do |_t, args|
args.with_defaults(:target => 0)
Sequel::Migrator.run(DB, "migrations", :target => args[:target].to_i)
Rake::Task['db:version'].execute
end
desc 'Perform migration reset (full rollback and migration)'
task :reset do
Sequel::Migrator.run(DB, "migrations", :target => 0)
Sequel::Migrator.run(DB, "migrations")
Rake::Task['db:version'].execute
end
end