Hi all
I have to execute some code always after the up methods of my
migrations. I wondered if there is a before_up/after_up hook that I can
override? Or how could I achieve that?
Thanks a lot
Josh
Hi all
I have to execute some code always after the up methods of my
migrations. I wondered if there is a before_up/after_up hook that I can
override? Or how could I achieve that?
Thanks a lot
Josh
Joshua M. wrote:
Hi all
I have to execute some code always after the up methods of my
migrations. I wondered if there is a before_up/after_up hook that I can
override? Or how could I achieve that?Thanks a lot
Josh
Use method call in the end of up method?
Jamal S. wrote:
Joshua M. wrote:
Hi all
I have to execute some code always after the up methods of my
migrations. I wondered if there is a before_up/after_up hook that I can
override? Or how could I achieve that?Thanks a lot
JoshUse method call in the end of up method?
No, I want it to execute automatically, because it’s always the same
action and I don’t want it in every migration…
Joshua M. wrote:
Jamal S. wrote:
Joshua M. wrote:
Hi all
I have to execute some code always after the up methods of my
migrations. I wondered if there is a before_up/after_up hook that I can
override? Or how could I achieve that?Thanks a lot
JoshUse method call in the end of up method?
No, I want it to execute automatically, because it’s always the same
action and I don’t want it in every migration…
What do you exactly need to do before or after every migration?
create_table, maybe have something before and after ?
Joshua M. wrote:
What do you exactly need to do before or after every migration?
create_table, maybe have something before and after ?
I’m working on a plugin that automatically loads some fixtures according
to every migration, something likedb/migrate/fixtures/001/countries.yml
db/migrate/fixtures/002/users.yml
db/migrate/fixtures/003/bla.yml
db/migrate/fixtures/003/users.ymlSo I just want the up method of a migration to check if there’s a
directory with the corresponding migration number and any fixtures in
it, and if so, to load them.
This might give you a idea how to do it
class A # ActiveRecord::Migration
def self.create_table
puts “create users”
end
end
class Invoke < A # Your own class which inherent
ActiveRecord::Migration
def self.create_table
puts “-> Before”
super
self.after_table
end
def self.after_table
puts “-> After”
end
end
class CreateUsers < Invoke # This is your new class you would use to
create migration, which will inherent Invoke
def self.up
create_table #create your stuff normal
end
end
CreateUsers.up
What do you exactly need to do before or after every migration?
create_table, maybe have something before and after ?
I’m working on a plugin that automatically loads some fixtures according
to every migration, something like
db/migrate/fixtures/001/countries.yml
db/migrate/fixtures/002/users.yml
db/migrate/fixtures/003/bla.yml
db/migrate/fixtures/003/users.yml
So I just want the up method of a migration to check if there’s a
directory with the corresponding migration number and any fixtures in
it, and if so, to load them.
output:
-> Before
create users
-> After
Thank you for your answer!
I remarked that your code only works when calling create_table in the
self.up method. But I need it to work in any case, not depending on what
I call in the self.up method.
As soon as self.up is called, it should execute before_up…
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs