Generate database schema from models … instead of the opposite.
That would make sense !
——
I disagree. The whole thing about Rails is to only have information where it has to be. It has to be in the database, but the models can get it from there. Plus if you generated the schema from the models, everytime you changed the model, you would have to regenerate the database schema, also meaning you would remove all data from the database.
— MattMoriarity
——
1) ALTER TABLE does not remove the data ..!
*not all dbs supported by Rails have ALTER TABLE *
2) data is stored in db… right.. but DB is just a STORAGE. The schema actually duplicates some info of the model, which is plain wrong.
…not if there are DBAs, other apps, etc., which use the same database but through different tools/interfaces, which will not get any of the Rails-based application domain logic. The DB is WAY more than just structured storage.
— Dom
——
One of the major advantages of rails is that you do not need to specify the names of columns in your tables. I can’t imagine that this will be changed, so there’s no obvious way you might be able to generate schemas from ActiveRecord models.
——
Yeah, you don’t specify the names of the columns in the model, but you do in the schema. We should forget about the schema and have it generated automatically with some kind of abstraction from the model.
——
obviously, you’ve never had to clean up some hot$hit programmer’s application database using “primitive” tools like isql, sqlplus, etc. , because, after all, the database is just stupid storage…
———
Have a look at something like Fabrique. (If they ever finish developing it). There is a really funky data design layer which allows you to create Entities, the relationships between them and FQL business queries which are held with the entities. The database is auto-generated and updated when there are changes. At the moment RoR has sortof broken the design process in the middle, as if the data model is not part of the original design. There are a huge number of good things about it…. but in the long term it would need to be developed to be in the same league as the next generation of development environments.
——-
Probably even better is Delphi 2005’s MDA stuff (aka ECO2), Together, Bold for Delphi, etc. Of course, it trashes your database schema when it comes time to update it from the model, but dealing with ActiveRecord seems to be just a whole lot easier than OCL to me.
Plus, there will be people who want to use Rails with existing database schemas, and leaving them out in the wind will really end up being a “cut off your nose to spite your face” situation. Often times, for these people, modifying the database schema will not be allowed (i.e., interfacing a Rails app on top of a Documentum database schema).