db.rake 846 B

1234567891011121314151617181920212223242526
  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. begin
  7. if ActiveRecord::Migrator.current_version.zero?
  8. Rake::Task['db:migrate'].invoke
  9. Rake::Task['db:seed'].invoke
  10. end
  11. rescue ActiveRecord::NoDatabaseError
  12. Rake::Task['db:setup'].invoke
  13. else
  14. Rake::Task['db:migrate'].invoke
  15. end
  16. end
  17. end
  18. task :pre_migration_check do
  19. version = ActiveRecord::Base.connection.select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
  20. abort 'This version of Mastodon requires PostgreSQL 9.5 or newer. Please update PostgreSQL before updating Mastodon' if version < 90_500
  21. end
  22. Rake::Task['db:migrate'].enhance(['db:pre_migration_check'])
  23. end