We are currently developing a user based web application in java.
A user can have many properties like firstname, lastname, Region (eg. Asia, Europe, US, UK), country, Division, Branch, Product etc.
There are normal CRUD screens for this user with all the above fields.
The add/edit screen for user will also have a date field called effective date. The way this add/edit user is different from normal add/edit in regular CRUD is that the update made to the user will not reflect until the effective date.
Lets say today is 6 April and I add a new user with Region say Asia and effective date 10 April. And now I go and change same user and change his region from Asia to US but effective date say 15 May.
So till 15th may the system should show his region as Asia only and on 15th may his region should change to US automatically.
You can think of it as the user who is working in Asia as on April but from 15th may he is moving to work in US i.e. Region changed from Asia to US effective date 15th may. So till 15th may he should be shown as a user in Asia only.
So I can not just update his region from Asia to us in database as a simple update operation.
And this applies to lot of other fields like division , branch and product as well.
I can not have multiple records for the same user.
EDIT 1:
We should also be able to see the user history or the future updates.
Like on the 6 april, I should see that users region will change from 15 May and his division will change from A to B starting 10 may.
I should also be able to delete updates say I come to know later that the proposed transfer of user from Asia to Us effective date 15 may is not going to happen now so I should be able to delete that update.
EDIT 2:-
Given the above situations, How do I make changes in my original user table and the user change log table?
Say for a user with region asia in the system which is going to change from asia to Us in next few weeks. user will have same update for user. He changes region from asia to user and choose effecftive date as some future date.
Now How do I check if region is changed from asia to us (there can be namy mre fields like region). Shall I do it at the code level or is it possible to do it at the datbase level using triggers etc?
Please help me out with designing the system and database for this.
I will suggest you can implement this system maintaining a CHANGELOG table and a scheduler which will run at a specific time everyday.
CHANGELOG table
Attributes :
Now, whenever a update is made on required fields, insert a corresponding entry in changelog table.
Example,
Now, a scheduler will run every day say(at 12:00 AM) and will check for scheduled changes made to be done that day from CHANGELOG table and make those changes in respective target tables.
Note : This approach has 2 advantages :
You dont have to maintain two entries for same record.
You can target multiple fields(region,division,branch) and multiple tables as well.