This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
74 lines (62 loc) · 2.12 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
70
71
72
73
74
task :environment do
require_relative 'config/boot'
Ralph.boot
end
namespace :db do
task configure_active_record_tasks: :environment do
include ActiveRecord::Tasks
DatabaseTasks.database_configuration = Ralph.database_configs
DatabaseTasks.db_dir = Ralph.root.join('db')
DatabaseTasks.env = Ralph.env
DatabaseTasks.migrations_paths = [Ralph.root.join('db/migrate')]
end
desc 'Create database'
task create: :configure_active_record_tasks do
DatabaseTasks.create_current
end
desc 'Drop database'
task drop: :configure_active_record_tasks do
DatabaseTasks.drop_current
end
desc 'Run database migrations'
task migrate: :configure_active_record_tasks do |task|
ActiveRecord::Base.logger = Ralph.logger
ActiveRecord::Migration.verbose = false
ActiveRecord::MigrationContext.new(Ralph.root.join('db/migrate'),
ActiveRecord::SchemaMigration).migrate
ActiveRecord::Base.clear_cache!
Rake::Task['db:schema:dump'].invoke
end
desc 'Roll back the last database migration'
task rollback: :configure_active_record_tasks do |task|
ActiveRecord::Base.logger = Ralph.logger
ActiveRecord::Migration.verbose = false
ActiveRecord::MigrationContext.new(Ralph.root.join('db/migrate'),
ActiveRecord::SchemaMigration).rollback
ActiveRecord::Base.clear_cache!
Rake::Task['db:schema:dump'].invoke
end
namespace :migrate do
desc 'Show database migration status'
task status: :configure_active_record_tasks do
DatabaseTasks.migrate_status
end
end
namespace :schema do
desc 'Dump database schema to db/schema.rb'
task dump: :configure_active_record_tasks do
DatabaseTasks.dump_schema(Ralph.current_database_config)
end
desc 'Load database schema from db/schema.rb'
task load: :configure_active_record_tasks do
DatabaseTasks.load_schema(Ralph.current_database_config)
end
end
end
namespace :generate do
desc 'Generate a new database migration'
task :migration, [:name] => :environment do |_task, args|
require_relative 'lib/tasks/generate_migration_task'
GenerateMigrationTask.new(args.name).run
end
end