-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
56 lines (46 loc) · 2.02 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
# frozen_string_literal: true
require "minitest/test_task"
Minitest::TestTask.create
namespace :db do
task :load do # rubocop:disable Rake/Desc # We do not want to describe this one because it's only here as dependency for the other tasks
require_relative "lib/rake_support/load_env"
require_relative "config/database"
require_relative "lib/rake_support/colors"
require_relative "lib/rake_support/migrations"
end
desc "Sets up the database the first time. Should only be run once!"
task setup: :load do
Rake::Task["db:migrate"].invoke
RakeSupport::Migrations.password_migrate(Database.ph_connection)
RakeSupport::Migrations.dump_schema(Database.connection)
puts RakeSupport::Colors.info.call("db:setup executed")
end
desc "Migrates the database up (options [version_number])"
task :migrate, %i[version] => :load do |_, args|
version = args[:version]&.to_i
RakeSupport::Migrations.migrate(Database.connection, target_migration: version)
RakeSupport::Migrations.dump_schema(Database.connection)
puts RakeSupport::Colors.info.call("db:migrate executed")
end
desc "Migrates the database down (options [version_number])"
task :"migrate:down", %i[version] => :load do |_, args|
version = args[:version]&.to_i
RakeSupport::Migrations.migrate_down(Database.connection, target_migration: version)
RakeSupport::Migrations.dump_schema(Database.connection)
puts RakeSupport::Colors.info.call("db:migrate:down executed")
end
desc "Creates a new migration file (parameters: NAME)"
task :create, %i[name] => :load do |_, args|
name = args[:name]
if name.nil? || name.empty?
puts RakeSupport::Colors.error.call("No NAME specified")
puts RakeSupport::Colors.info.call <<~USAGE_STR.chomp
Example usage
`rake db:create[create_table]`
USAGE_STR
exit 1
end
fullpath = RakeSupport::Migrations.create_migration(name)
puts RakeSupport::Colors.info.call("migration file created #{RakeSupport::Colors.warning.call(fullpath)}")
end
end