Skip to content

Instantly share code, notes, and snippets.

@libryder
Created October 29, 2011 03:04
Show Gist options
  • Save libryder/1324029 to your computer and use it in GitHub Desktop.
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
# 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
# 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
# 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
<% @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