tasks/databases.rake in salsify-data_migrate-3.0.1 vs tasks/databases.rake in salsify-data_migrate-3.1.0

- old
+ new

@@ -221,10 +221,25 @@ assure_data_schema_table puts "Current Schema version: #{ActiveRecord::Migrator.current_version}" puts "Current Data version: #{DataMigrate::DataMigrator.current_version}" end end + + namespace :abort_if_pending_migrations do + desc "Raises an error if there are pending data or schema migrations" + task :with_data => :environment do + assure_data_schema_table + migrations = pending_migrations + if migrations.any? + puts "You have #{migrations.size} pending #{'migration'.pluralize(migrations.size)}:" + migrations.each do |migration| + puts ' %4d %6s %s' % [migration[:version], migration[:kind], migration[:name]] + end + abort %{Run `rails db:migrate:with_data` to update your database then try again.} + end + end + end end namespace :data do desc 'Migrate data migrations (options: VERSION=x, VERBOSE=false)' task :migrate => :environment do @@ -315,27 +330,39 @@ desc "Retrieves the current schema version number for data migrations" task :version => :environment do assure_data_schema_table puts "Current data version: #{DataMigrate::DataMigrator.current_version}" end + + desc "Raises an error if there are pending data migrations" + task :abort_if_pending_migrations => :environment do + migrations = pending_data_migrations + if migrations.any? + puts "You have #{migrations.size} pending data #{'migration'.pluralize(migrations.size)}:" + migrations.each do |migration| + puts ' %4d %s' % [migration[:version], migration[:name]] + end + abort %{Run `rails data:migrate` to update your database then try again.} + end + end end def pending_migrations sort_migrations pending_data_migrations, pending_schema_migrations end def pending_data_migrations data_migrations = DataMigrate::DataMigrator.migrations('db/data') sort_migrations DataMigrate::DataMigrator.new(:up, data_migrations ). - pending_migrations.map{|m| { :version => m.version, :kind => :data }} + pending_migrations.map{|m| { :version => m.version, :kind => :data, :name => m.name }} end def pending_schema_migrations all_migrations = ActiveRecord::Migrator.migrations(Rails.application.config.paths["db/migrate"]) sort_migrations( ActiveRecord::Migrator.new(:up, all_migrations). pending_migrations. - map{|m| { :version => m.version, :kind => :schema }}) + map{|m| { :version => m.version, :kind => :schema, :name => m.name }}) end def sort_migrations set_1, set_2=nil migrations = set_1 + (set_2 || []) migrations.sort{|a,b| sort_string(a) <=> sort_string(b)}