aspose file tools*
The moose likes JSP and the fly likes Change database schema, not have to update code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Change database schema, not have to update code" Watch "Change database schema, not have to update code" New topic
Author

Change database schema, not have to update code

stephen r davidson
Ranch Hand

Joined: Jun 23, 2013
Posts: 58
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

Joined: Jan 10, 2002
Posts: 61657
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30957
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

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

Joined: May 26, 2003
Posts: 30957
    
158

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
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
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.


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

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

Joined: Jun 23, 2013
Posts: 58
Ok. Thanks all for your contributions. I will noodle on what you have all said. :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change database schema, not have to update code