Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change database schema, not have to update code

 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder. I have just finished writing an app. MVC, works great, except for one thing. If I add a new column to the database, I have to modify several components in each tier.
My question is, how to make my app dynamic, such that when I add a column to the database, the code deals with it. What is the right approach to accomplish this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blue sky and pie. Imagine a scenario where the columns you add are address (street, city, state/province, postal code, country) information to a user record. This address information needs to be displayed whenever the user information is display, collected when user information is collected, and validated prior to being stored. Not to mention any business logic associated with the new information.

Does it really make any sense to try and write code that's so complex that it could handle all of that automatically?

In a layered application, new features usually require modifications at many levels. Good separation of concerns makes those changes easier.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In rails/grails, the new fields are "automatically" displayed. (You still have to change the code in one place.) If all you have is a CRUD wrapper around the database, this is a viable approach. For many apps, you need custom logic. And yes, that does require changing the app.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that means automatic layouts, rather than handcrafted UI and CSS? That wouldn't be sufficient for any of my apps. What about validations? Business rules?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I assume that means automatic layouts, rather than handcrafted UI and CSS? That wouldn't be sufficient for any of my apps. What about validations? Business rules?

Yes, Rails starts out with automated layouts. It can do more, but that's where it shines. It's not sufficient for many of my apps either. But it is in an option.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer depends entirely on what "deals with it" means. If the field need not be updated by the app, but just preserved when the rest of the record is updated, then I think some of the common ORM frameworks can do this.

If it is also to be displayed, and maybe even saved, then the web app needs to know that this can happen in order to accommodate it. As Jeanne mentioned, some web frameworks go to great length to facilitate this. I don't see Bear's point about layout as an important one - apps that I can envision needing this kind of dynamism wouldn't be visible to a broad public audience, so design wouldn't be a big concern.

Having said that, in my experience it would be extremely rare that you wanted to make a schema change without an accompanying release of the apps that handle that schema - because generally there will be validations and rules that need to be added. And while there's no principal difficulty making a lot of that dynamic as well, then we'd be talking about a really big effort, and a lot of added complexity, where it might just be easier to adapt the code of the app and re-release it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I don't see Bear's point about layout as an important one - apps that I can envision needing this kind of dynamism wouldn't be visible to a broad public audience, so design wouldn't be a big concern.

All of my apps fall into he category of needing design (sometimes quite intricate) so I'm taking those into consideration. But yeah, for apps where stuff can just be spit out, it'd probably be a lot easier. In my experience, those are a minority.

So I guess it depends on what kind of apps the OP is thinking about.

because generally there will be validations and rules that need to be added. And while there's no principal difficulty making a lot of that dynamic as well, then we'd be talking about a really big effort, and a lot of added complexity, where it might just be easier to adapt the code of the app and re-release it.

Aside from the design aspect, that was my point as well.
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks all for your contributions. I will noodle on what you have all said. :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic