Rails Schema Generator 0.9.0
Posted by Scott Laird Sat, 10 Dec 2005 18:14:12 GMT
I just released a new version of my Rails Schema Generator on Rubyforge. The schema generator takes a collection of Rails database migration scripts and assembles a complete set of SQL schema files using only the information from the migrations. This release supports MySQL, PostgreSQL, and SQLite; it can generate schemas for all three DB types even if the databases aren’t installed on the system.
We’ve found that the schema generator drastically lowers the work needed to keep Typo working correctly with multiple database types.
This release fixes a number of bugs and should finally work correctly with all common migration operations, including field renaming. This has only been tested with Rails 0.14.4, and at least one API has changed recently, so this may not work with earlier 0.14.x releases.
To use the schema generator, run gem install schema_generator, and then (from your Rails project directory) ./script/generate schema. This will create several schema files in the db/ directory, prompting you before overwriting existing files.

Scott,
Great stuff…just what I was looking for. Coming from Hibernate-based Java projects, the ability to independently define a schema and then actually generate that schema for the target database was something I sorely missed. My Rails project needs to run on SQLite for development but then move to PostgreSQL for production, and your tool will help tremendously. A big thanks!
John
Scott,
I just left the first(!) email on the rubyforge mailing list for this tool; I hope you can help! :)
And I’ve left the second mailing list post. 8-)
I’d contacted Scott earlier about similar problems to Paul’s: no output from the schema generator. Turns out that the missing mysql gem identified by Paul was the problem. I also didn’t install mysql support, since I’m using Postgres.
I’ve also done some checking w.r.t. Rails 0.14.4 vs. Rails 1.0 – I was able to replicate Paul’s problems with Rails 1.0. A temporary workaround is to downgrade to Rails 0.14.4.
Finally, the Rails 1.0 migration generator not only produces a different file name format (e.g. “001initialschema.rb”), rake migrate now recognizes only the new format – it won’t work with the old style numbering, such as Typo has used.
I get the followng exception: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require__’: No such file to load – mysql (MissingSourceFile) from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require’ from ./script/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:213:in `require’ from c:/ruby/lib/ruby/gems/1.8/gems/schema_generator-0.9.0/schema_generator.rb:2 from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require__’ from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require’ from ./script/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:213:in `require’ from ./script/../config/../vendor/rails/railties/lib/rails_generator/spec.rb:17:in `klass’ from ./script/../config/../vendor/rails/railties/lib/rails_generator/lookup.rb:126:in `instance’ from ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../scripts.rb:31:in `run’ from ./script/../config/../vendor/rails/railties/lib/commands/generate.rb:6 from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require__’ from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require’ from script/generate:3