Commit 3f7a7a8b683cab42f30521d8d3dea26a5e00918f
1 parent
5a911ba4
Exists in
master
and in
22 other branches
Better support for plugins migrations
Showing
1 changed file
with
15 additions
and
20 deletions
Show diff stats
lib/tasks/plugins.rake
1 | +require 'active_record' | ||
2 | +require_dependency 'active_record/migration' | ||
3 | + | ||
4 | +class ActiveRecord::Migrator | ||
5 | + alias_method :orig_initialize, :initialize | ||
6 | + def initialize *args | ||
7 | + orig_initialize *args | ||
8 | + @migrations_path = "{db/migrate,config/plugins/*/db/migrate}" | ||
9 | + end | ||
10 | +end | ||
11 | + | ||
1 | namespace :noosfero do | 12 | namespace :noosfero do |
2 | namespace :plugins do | 13 | namespace :plugins do |
3 | - plugin_migration_dirs = Dir.glob(File.join(Rails.root, 'config', 'plugins', '*', 'db', 'migrate')) | 14 | + plugin_migration_dirs = Dir.glob(File.join(Rails.root, 'config', |
15 | + 'plugins', '*', 'db', 'migrate')) | ||
4 | task :migrate do | 16 | task :migrate do |
5 | plugin_migration_dirs.each do |path| | 17 | plugin_migration_dirs.each do |path| |
6 | - ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) | ||
7 | - end | ||
8 | - end | ||
9 | - task :abort_if_pending_migrations do | ||
10 | - if defined? ActiveRecord | ||
11 | - pending_migrations = plugin_migration_dirs.map do |path| | ||
12 | - ActiveRecord::Migrator.new(:up, path).pending_migrations | ||
13 | - end.flatten | ||
14 | - | ||
15 | - if pending_migrations.any? | ||
16 | - puts "You have #{pending_migrations.size} pending migrations:" | ||
17 | - pending_migrations.each do |pending_migration| | ||
18 | - puts ' %4d %s' % [pending_migration.version, pending_migration.name] | ||
19 | - end | ||
20 | - abort %{Run "rake db:migrate" to update your database then try again.} | ||
21 | - end | 18 | + ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? |
19 | + ENV["VERSION"].to_i : nil) | ||
22 | end | 20 | end |
23 | end | 21 | end |
24 | end | 22 | end |
25 | end | 23 | end |
26 | - | ||
27 | -task 'db:migrate' => 'noosfero:plugins:migrate' | ||
28 | -task 'db:abort_if_pending_migrations' => 'noosfero:plugins:abort_if_pending_migrations' |