Skip to content

Commit

Permalink
check migrations in initializer to speed up boot process
Browse files Browse the repository at this point in the history
  • Loading branch information
machisuji committed Aug 17, 2021
1 parent 5cef260 commit c31bf72
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
40 changes: 40 additions & 0 deletions config/initializers/06-pending_migrations_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#-- encoding: UTF-8

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2021 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++

# We want to abort booting when there are missing migrations by default
# since it can lead to runtime schema cache issues.
# Refusing to boot will encourage admins to fix missing migrations.

exceptions = %w(db:create db:drop db:migrate db:structure:load db:schema:load)
is_console = Rails.const_defined? 'Console'

if Rails.env.production? && !is_console && (exceptions & ARGV).empty?
ActiveRecord::Migration.check_pending! # will raise an exception and abort boot
end
4 changes: 0 additions & 4 deletions docker/prod/migration_status

This file was deleted.

2 changes: 0 additions & 2 deletions docker/prod/web
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ fi
if [ "$MIGRATE" = "true" ]; then
echo "Migrating database..."
bundle exec rake db:migrate
else
$APP_PATH/docker/prod/migration_status # abort if there are pending migrations
fi

# see `config/puma.rb` for configuration
Expand Down
2 changes: 0 additions & 2 deletions docker/prod/worker
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ if [ "$1" = "--seed" ]; then
$APP_PATH/docker/prod/seeder "$@"
fi

$APP_PATH/docker/prod/migration_status # abort if there are pending migrations

QUIET=true bundle exec rake jobs:work

0 comments on commit c31bf72

Please sign in to comment.