0

Is it possible to make Rails generate several model migrations in just 1 command? Something like...

$ rails g model Product1 name:string, Product2 name:string, Product3 name:string [...]

Background:

I have to generate about 4'000 models/db tables.

Running 1 generator command for each one would take probably over 10 hours...

Or do I have to think outside the box for a faster solution to this?

TomDogg
  • 3,803
  • 5
  • 33
  • 60

2 Answers2

0

Why not just do it in a ruby script?

4000.times do |i|
  system("rails g model Product#{i} name:string")
end

I'm sure your models are probably more complicated than a name string for each, but I could easily see you reading them in from a file and parsing the appropriate columns.

Hope it helps.

Geoff
  • 2,208
  • 1
  • 16
  • 17
  • Thanks, but it wouldn't solve the "long total execution time" problem, since the command "rails g model..." would still have to be executed 4k times, meaning that it would still "invoke active_record" once for each time... (the idea was to somehow end up having just 1 such command) – TomDogg Jan 27 '13 at 17:03
  • From my reading of the help file, it doesn't seem like you can do more than one model at once. However, you can always go in and change the script to do whatever you want. I still don't see how running the script 4000 times is worse than running it once with 4000 inputs though. – Geoff Jan 27 '13 at 18:18
0

The solution to the original problem is to use the gem "spring" (it speeds things up a lot):

https://github.com/jonleighton/spring

TomDogg
  • 3,803
  • 5
  • 33
  • 60