Created
October 29, 2011 03:04
-
-
Save libryder/1324029 to your computer and use it in GitHub Desktop.
Typo (6.0.9) fix that allows for new migration version naming scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/admin/base_controller.rb | |
def look_for_needed_db_updates | |
if Migrator.offer_migration_when_available | |
redirect_to :controller => '/admin/settings', :action => 'update_database' if Migrator.migrations_available | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/migrator.rb | |
def self.migrations_available | |
path = File.expand_path("db/migrate") | |
migrator = ActiveRecord::Migrator.new(:up, path) | |
if migrator.pending_migrations.size > 0 | |
true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/admin/settings_controller.rb | |
def update_database | |
@current_version = Migrator.current_schema_version | |
path = File.expand_path("db/migrate") | |
migrator = ActiveRecord::Migrator.new(:up, path) | |
if migrator.pending_migrations.size > 0 | |
@pending = migrator.pending_migrations.count | |
@needed_migrations = migrator.pending_migrations | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @page_heading = _('Database migration') %> | |
<% subtabs_for(:settings) %> | |
<div class='widget-container'> | |
<h3 class='light'><span class='ui-icon ui-icon-gear'></span> <%= _("Information")%></h3> | |
<div class='widget-content'> | |
<p> | |
<strong><%= _("Current database version")%>:</strong> | |
<%= @current_version %> | |
</p> | |
<% unless @needed_migrations.blank? %> | |
<p> | |
<strong><%= _("Migrations")%>:</strong> | |
There are <%= @pending %> migration(s) pending. | |
</p> | |
<h3><%= _("Needed migrations")%></h3> | |
<ul> | |
<% for migration in @needed_migrations %> | |
<li><%= migration.name %></li> | |
<% end %> | |
</ul> | |
<% end %> | |
<%= form_tag :action => 'migrate' do %> | |
<% if @pending.nil? %> | |
<div class='info'> | |
<p><span class='ui-icon ui-icon-info' style='float: left; margin-right: 0.3em;'></span><strong><%= _("You are up to date!")%></strong></p> | |
</div> | |
<% else %> | |
<%= save(_("Update database now")) %> <small><%= _("may take a moment")%></small> | |
<% end %> | |
<% end %> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment