Have stored procedures or view definitions in your application? Wouldn’t it be great if you could keep those with the rest of your code?
DBuddy is a small script that does two things to streamline this process:
- Loads all of the SQL files matching one or more globs
- Watches over those files and reloads them on changes
dbuddy db/views/*.sql db/procedures/*.sql
dbuddy --watch db/views/*.sql db/procedures/*.sql dbuddy -w db/views/*.sql db/procedures/*.sql
From code (e.g. rake task)
DBuddy.run(ActiveRecord::Base.connection, Dir.glob("db/views/*.sql") + Dir.glob("db/procedures/*.sql"))
- Right now it assumes it’s being run in the root of a Rails project and loads config/environment.rb. This could be improved, but right now I don’t have a use case.