<p>I know that there are a few (automatic) ways to create a data access layer to manipulate an existing database (LINQ to SQL, Hibernate, etc...). But I'm getting kind of tired (and I believe that there should be a better way of doing things) of stuff like:</p>

<ol>
<li>Creating/altering tables in Visio</li>
<li>Using Visio's "Update Database" to create/alter the database</li>
<li>Importing the tables into a "LINQ to SQL classes" object</li>
<li>Changing the code accordingly</li>
<li>Compiling</li>
</ol>

<p>What about a way to generate the database schema from the objects/entities definition? I can't seem to find good references for tools like this (and I would expect some kind of built-in support in at least some frameworks).</p>

<p>It would be perfect if I could just:</p>

<ol>
<li>Change the object definition</li>
<li>Change the code that manipulates the object</li>
<li>Compile (the database changes are done auto-magically)</li>
</ol>

[{'answer_id': 29147, 'author': 'jason saldo', 'author_id': 1293, 'author_profile': 'https://Stackoverflow.com/users/1293', 'pm_score': 1, 'selected': False, 'text': '<p>You may be looking for an <a href="http://en.wikipedia.org/wiki/Object_database" rel="nofollow noreferrer">Object Database</a>.  </p>\n'}, {'answer_id': 29151, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 1, 'selected': False, 'text': '<p>I believe this is the problem that the <a href="http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx" rel="nofollow noreferrer">Microsofy Entity Framework</a> is trying to address. Whilst not specifically designed to "Compile (the database changes are done auto-magically)" it does address the issue of handling changes to the domain model without a huge dependance on the underlying data model.</p>\n'}, {'answer_id': 29165, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 0, 'selected': False, 'text': '<p>Some of the really big dogs, such as <a href="http://ca.com/us/products/product.aspx?id=260" rel="nofollow noreferrer">ERwin Data Modeler</a>, will go object to DB. You need to have the big bucks to afford the product though.</p>\n'}, {'answer_id': 29183, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 1, 'selected': False, 'text': '<p>As Jason suggested, object db might be a good choice. Take a look at <a href="http://www.db4o.com" rel="nofollow noreferrer">db4objects</a>.</p>\n'}, {'answer_id': 30155, 'author': 'Ed.T', 'author_id': 3014, 'author_profile': 'https://Stackoverflow.com/users/3014', 'pm_score': 1, 'selected': False, 'text': '<p>What you described is GORM. It is part of the <a href="http://grails.org/" rel="nofollow noreferrer">Grails</a> framework and is built to work with Hibernate (maybe JPA in the future). When I was first using Grails it seemed backwards. I was more comfortable with a Rails style workflow of making the tables and letting the framework generate scaffolding from the database schema. GORM persists your domain objects for you so you create and change the objects, it manages database create/update. This makes more sense now that I have gotten used to it. Sorry to tease you if you aren\'t looking for a new framework but it is on the <a href="http://grails.org/Roadmap" rel="nofollow noreferrer">roadmap</a> for release 1.1 to make GORM available standalone.</p>\n'}, {'answer_id': 30515, 'author': 'Farinha', 'author_id': 2841, 'author_profile': 'https://Stackoverflow.com/users/2841', 'pm_score': 0, 'selected': False, 'text': '<p>I kept digging around some of the "major" frameworks and it seems that Django does exactly what I was talking about. Or so it seems from this <a href="http://www2.lamptraining.com/screencast/1/" rel="nofollow noreferrer">screencast</a>.</p>\n\n<p>Does anyone have any remark to make about this? Does it work well?</p>\n'}, {'answer_id': 30568, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 1, 'selected': False, 'text': '<p>When we built the first version of our own framework (<a href="http://www.inon.com/page.jsp?page=datamanager" rel="nofollow noreferrer" title="Inon Datamanager">Inon Datamanager</a>) I had it read pre-existing SQL tables and autogenerate Java objects from them.</p>\n\n<p>When my colleagues who came from a Smalltalkish background built the second version, they started from the objects and then autogenerated the tables.</p>\n\n<p>Actually, they forgot about the SQL part altogether until I came back in and added it. But nowadays we just run a trigger on application startup which iterates over the object model, checks if the tables and all the right columns exist, and creates them if not. Very convenient.</p>\n\n<p>This turned out to be a lot easier than you might expect - if your favourite tool doesn\'t support a similar process, you could probably write it in a couple of hours - assuming the relational to object mapping is relatively simple.</p>\n\n<p>But the point is, it seems to depend on whether you\'re culturally an object person or a database person - you can regard either one as the authoritative source.</p>\n'}, {'answer_id': 293179, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Yes, Django works well.</p>\n\n<p>yes, it will generate your SQL tables from your data model definitions (written in python)</p>\n\n<p>It won't always alter existing tables if you update your structure, you might have to run an ALTER table manually</p>\n\n<p>Ruby on Rails has an even more advanced version of these features (Rails migrations), but I don't like the framework as much, I find ruby and rails pretty idiosyncratic</p>\n"}, {'answer_id': 1155551, 'author': 'Alex Yakunin', 'author_id': 106042, 'author_profile': 'https://Stackoverflow.com/users/106042', 'pm_score': 2, 'selected': False, 'text': '<p>Check out <a href="http://wiki.dataobjects.net" rel="nofollow noreferrer">DataObjects.Net</a> - is is designed to support exactly this case. Code only, and nothing else. Its <a href="http://wiki.dataobjects.net/index.php?title=Schema_upgrade" rel="nofollow noreferrer">schema upgrade layer</a> is probably the most featured one you can find, and it really fully abstracts schema upgrade SQL.</p>\n\n<p>Check out <a href="http://wiki.dataobjects.net/index.php?title=Video" rel="nofollow noreferrer">product video</a> - you\'ll notice nothing additional is made to sync the schema. Schema upgrade sample shows the intended usage of this feature.</p>\n'}, {'answer_id': 4281637, 'author': 'Lucero', 'author_id': 88558, 'author_profile': 'https://Stackoverflow.com/users/88558', 'pm_score': 0, 'selected': False, 'text': '<p>Kind of a late answer, but here it goes:</p>\n\n<p>I faced the exact same problem and ended up writing my own solution for it, working with .NET and SQL Server only however. It basicaly does implement the process you describe:</p>\n\n<ul>\n<li>All DB objects are kept as embedded <code>CREATE</code> scripts as part of the source code</li>\n<li>DB Objects are set up automatically (or on request) when using the data access functionality</li>\n<li>All non-table changes are also performed automatically (or on request) at the same time</li>\n<li>Table changes, which may require special attention to migrate data, are performend via (manually created) change scripts also upon upgrading the database</li>\n<li>Even manual changes made to any databse object can be detected, so that schema integrity can be verified and rectified</li>\n<li>An optional lightweight ORM can map stored procedures and objects as well as result sets (even multiple)</li>\n<li>A command-line application helps keeping the SQL source files in sync with a development database</li>\n</ul>\n\n<p>The library including the database are free under a LGPL license.</p>\n\n<p><a href="http://code.google.com/p/bsn-modulestore/" rel="nofollow">http://code.google.com/p/bsn-modulestore/</a></p>\n'}]
['https://Stackoverflow.com/questions/29145', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2841/']