pascal-za/migrant

Auto-ignore models without structure block

Closed this issue · 4 comments

I have acts-as-taggable-on plugin installed. When I run rake generate migrations it's prompting me to delete the context and created_at columns. It's also generating all sorts of migrations to affect indexes, which I don't want.

The reason I believe is because they have a belongs_to call, which is initializing the schema. The thing is though, the taggable model doesn't initialize any other schema via the structure block. So either you only acts on models in app/models (which will mean gems won't be able to utilize migrant), or the better solution:

Ignore models unless structure block was specifically called.

def structure(type=nil, &block)
  @initialized ||= true
  ...
end

def generate_migrations
  models.select(&:initialized?).each { ... }
end

Your assumption about the belongs_to was correct, in fact Migrant should not affect models that don't define a structure block in any way. I've added a commit that should address this.

I'm not certain whether this fixes your taggable problem however, but please feel free to try the master branch and let me know what you find.

If this resolves the problem I'll push a patch ASAP, after I've done a few sanity checks.

That has indeed fixed it :-) Thank you.

Any progress with #9 ?

Great!

With regards to #9 I was throwing some ideas around for other stuff like full text search indexing, then the issue kind of dropped off my radar. I should implement a basic version for now though, it's actually pretty straightforward to add. Watch this space, etc. :)