Skip to content

Alias all ORM migrate tasks to a common db:migrate task #903

Closed
postmodern opened this Issue Aug 8, 2012 · 17 comments

5 participants

@postmodern

There should be one rake task that migrate all Databases up to the highest migrate version, across all ORMs used by the project. This would simplify deploying padrino apps.

I am interested in adding support for Padrino to deployml.

@postmodern

dm-rails also provides a db:migrate task for compatibility with the traditional ActiveRecord db:migrate task.

@DAddYE
Padrino Framework member
DAddYE commented Aug 8, 2012

Ok, let's start with this

@achiu achiu was assigned Jan 5, 2013
@dariocravero
Padrino Framework member

Should we follow this @DAddYE? If we do so, we should reconsider @postmodern's recommendation of putting seed into db:seed in #895. Although I would alias one of them not to break backward's compatibility instead of moving as proposed.

@DAddYE
Padrino Framework member
DAddYE commented Jan 31, 2013

Ok, I can agree with db:seed the problem with dm:migrate can be happen when someone will use two orm adapters (hopefully in two different apps).

So we should add a workaround like:

namespace db do
  desc 'Multimigration whenever you have multiple orms'
  task migrate do
     Task['ar:migrate'].invoke if defined?(ActiveRecord)
     Task['dm:migrate'].invoke if defined?(DataMapper)
     # and so on...
  end

Same for migrate up/down etc...

Makes sense?

I don't see ATM others solution than that without drop support for multiple orm in one project.

@dariocravero
Padrino Framework member

Yeah, looks like it... @padrino/core-members?

@postmodern

@DAddYE we can use rake's task dependencies.

# tasks/data_mapper.rb
namespace :dm do
  task :migrate do
  end
end
task 'db:migrate' => 'dm:migrate'

# tasks/active_record.rb
namespace :ar do
  task :migrate do
  end
end
task 'db:migrate' => 'ar:migrate'
@DAddYE
Padrino Framework member
DAddYE commented Jan 31, 2013

yep but I don't think it will run multiple like:

task 'db:migrate' => ['ar:migrate', 'dm:migrate']
@DAddYE
Padrino Framework member
DAddYE commented Jan 31, 2013

Got it we need to use some like:

namespace :dm do
  task :migrate do
  end
end
Task['db:migrate'].enhance(['dm:migrate'])

# tasks/active_record.rb
namespace :ar do
  task :migrate do
  end
end
Task['db:migrate'].enhance(['ar:migrate'])

So I saw correctly here should make an equivalent of:

task 'db:migrate' => ['ar:migrate', 'dm:migrate']
@postmodern

Rake will merge multiple dependencies together.

task :foo do
  puts 'foo'
end
task :test => :foo

task :bar do
  puts 'bar'
end
task :test => :bar
@DAddYE
Padrino Framework member
DAddYE commented Jan 31, 2013

hahha, I spent my brain 10 minutes to remember about enhance and you tell me that that will do that for me? :dancer:

@postmodern

enhance always confused me, but then I found out Rake lazily connects tasks.

task :does_not_exist_yet => :dependency

task :does_not_exist_yet do
end
task :dependency do
end
@DAddYE
Padrino Framework member
DAddYE commented Jan 31, 2013

So from now I like much more rake! Thanks man!

@dariocravero
Padrino Framework member

:D Amazing! So, who wants to push a PR? :) :dancers:

@postmodern

OK let me try.

@dariocravero
Padrino Framework member

:D Thanks!!

@skade
Padrino Framework member
skade commented Feb 9, 2013

Closed. Thank you very much!

@skade skade closed this Feb 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.