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