0

I have some nasty looking sql in a migration. I can make it more readable by first creating some views, populating my new table from cleaner SQL that the views make possible, then drop the views.

I don't think I've seen this done before in a single migration. Is it a bad idea or bad practice?

Mark Bolusmjak
  • 23,606
  • 10
  • 74
  • 129
  • Could you please add examples of the view definition and what you want to populate? – contradictioned Aug 07 '13 at 14:55
  • @contradictioned it's stuff that can't be shared. I don't think the exact details are important. I'm doing a bunch of inner joins on temp tables created by inner joins themselves. It gets very unreadable. – Mark Bolusmjak Aug 07 '13 at 15:13

1 Answers1

1

I don't see any problem with creating views in your migrations if it simplifies what you're doing and makes it easier to both work with now and revisit later. I've often created temporary tables in migrations to make it easier to do what I want to do data-wise. There might be a bit of database overhead but if your migration is complicated enough to warrant a view being created then you're going to be hitting the database fairly hard anyway.

Shadwell
  • 34,314
  • 14
  • 94
  • 99