-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRakefile
executable file
·48 lines (39 loc) · 1.35 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
#!/usr/bin/env rake
# frozen_string_literal: true
require 'rake/notes/rake_task'
require 'routes'
require 'bundler/setup'
$LOAD_PATH.unshift 'lib'
require 'travis/migrations'
require 'rails/generators/active_record/migration/migration_generator'
ActiveRecord.schema_format = :sql
Rails.application.config.paths['db'] = 'db/main'
Rails.application.config.paths['db/migrate'] = 'db/main/migrate'
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError # rubocop:disable Lint/SuppressedException
end
task default: [:spec]
namespace :db do
namespace :structure do
task :dump do
version = ActiveRecord::Base.connection.execute("SELECT current_setting('server_version')")[0]['current_setting']
if version.split('.').first.to_i > 9
puts <<~MESSAGE
\033[0;31mYou're running PostgreSQL #{version}. We're running PostgreSQL 9.x
on production and PostgreSQL dumps from higher versions are incompatible,
please don't commit the structure.sql file\033[0m
MESSAGE
end
end
end
end
task :gen_migration, [:name] do |_t, args|
name = args.fetch(:name)
ActiveRecord::Generators::MigrationGenerator.new([name]).create_migration_file
end
if Rails.env.production?
puts 'Running in production environment, disabling db:structure:dump task'
Rake::Task['db:structure:dump'].clear
end