Sha256: 9ef34f4b8cbc75c0a2ad8d19dc25c47d3e9d8c19f905e3b3f6ce2bf1d380d3f0

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

namespace :db do
  namespace :ghost do
    namespace :migrate do
      desc 'Runs the "down" for a given migration VERSION from tmp/schema_ghosts.'
      task down: [:prepare_directory, 'db:load_config'] do
        ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [Rails.root.join('tmp', 'schema_ghosts')]
        ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
        Rake::Task['db:migrate:down'].invoke
      end

      task :prepare_directory do
        FileUtils.mkdir_p(Rails.root.join('tmp', 'schema_ghosts'))
      end
    end

    # desc 'store versions'
    task store_versions_before_migrations: [:store_original_migrations_paths] do
      GhostSchema::MigrationStore.before_migrating_migrations = ActiveRecord::Base.connection.migration_context.get_all_versions
      Rake::Task['db:ghost:restore_original_migrations_paths'].invoke
    end

    # desc 'copy migrations'
    task :copy_migrated_versions do
      GhostSchema::MigrationStore.after_migrating_migrations = ActiveRecord::Base.connection.migration_context.get_all_versions
      GhostSchema::MigrationStore.copy_files
    end

    task :store_original_migrations_paths do
      GhostSchema::MigrationStore.original_migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
    end
    task :restore_original_migrations_paths do
      ActiveRecord::Tasks::DatabaseTasks.migrations_paths = GhostSchema::MigrationStore.original_migrations_paths
      ActiveRecord::Migrator.migrations_paths = GhostSchema::MigrationStore.original_migrations_paths
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ghost_schema-0.1.0 lib/tasks/ghost_schema_tasks.rake