db.rake 808 B

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. namespace :db do
  3. namespace :migrate do
  4. desc 'Setup the db or migrate depending on state of db'
  5. task setup: :environment do
  6. if ActiveRecord::Migrator.current_version.zero?
  7. Rake::Task['db:migrate'].invoke
  8. Rake::Task['db:seed'].invoke
  9. end
  10. rescue ActiveRecord::NoDatabaseError
  11. Rake::Task['db:setup'].invoke
  12. else
  13. Rake::Task['db:migrate'].invoke
  14. end
  15. end
  16. task :pre_migration_check do
  17. version = ActiveRecord::Base.connection.select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
  18. abort 'This version of Mastodon requires PostgreSQL 9.5 or newer. Please update PostgreSQL before updating Mastodon' if version < 90_500
  19. end
  20. Rake::Task['db:migrate'].enhance(['db:pre_migration_check'])
  21. end