Refactoring Java Code Because Of SQL Dumb December 16th, 2006

Two years ago, I developed Java application that talked to database. It is for store owner. So you have item_data table. In item_data table, you have sale_price and buying_price column. Off course there is transaction table that record item sales and purchasing. You can change the price of item but you need to keep the transaction price at related time. What do you do in that situation? Off course, you put the sale price and buying price data in transaction table. What did I do? I made dumb mistake. Here’s what I did: Every time you change the price, I make new item that clone the other attributes (the name, the size, etc). With this I can track how many item “Haloha” with sale price Rp 2,000 and how many item “Haloha” too but with sale price Rp 2,500. So you have many duplicate data. It’s bloody stupid.

Then my customer need to put expired date in item data. This is easy if I didn’t make that mistake. But whatever has gone, let it be. I learned from mistake. Design schema very very carefully. Reread. Rethink. Because change schema after writing application is expensive.

Leave a Reply