History when fields added to table?

A place for users and developers of the Xataface to discuss and receive support.

Postby Aoirthoir » Mon Oct 02, 2006 11:14 am

Just to check I wanted to see what would happen if the structure a table was changed.

Seems Mr. Steve has thought of most everything. If you add a field, and then update the database, the __history table will have the fields you added included in it. If you drop a field, they will not be displayed in the history area, but the fields themselves are not dropped from the table. Good security measure..

Thanks again Mr. Steve for an excellent job.
Aoirthoir
 
Posts: 420
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Mon Oct 02, 2006 12:57 pm

Thanks for taking the time to test all these things out Joe. It helps me sleep at night to know that the framework has gone through some independent tests..

Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: History when fields added to table?

Postby jvinolas » Wed May 11, 2011 10:07 am

I have a question regarding History. I have an existing application with lots of entries on mysql and now I need to enable history. The history works as expected for new records, but with modifications to existing records there is lack of original entry so it doesn't work as expected: it seems that the modification is the new entry.

Do I have to export it, flush table data and code a new import function so the history gets generated for existing records as they are inserted again? Is there an easier and quicker way of getting that done with data already on mysql?

Thanks.
jvinolas
 
Posts: 51
Joined: Thu Apr 15, 2010 12:31 am

Re: History when fields added to table?

Postby shannah » Wed May 11, 2011 10:15 am

The history feature only starts logging history from the time that history is enabled. You can't get history from before history was turned on. With existing records is works the same way as with new records. Whenever a change is made to the record (through Xataface) it makes a snapshot of the record in the history table.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: History when fields added to table?

Postby jvinolas » Wed May 11, 2011 11:25 am

I think I didn't explain so well.

What I mean is that as I enable history after records have been introduced, modifications to those records create a record in related history table (and the history table itself), but as there is no 'initial' record, when I go to history table, I can't view the modifications that where done from that 'initial' record.

I can't view the green and red field modifications on history table. Those 'green and red' modifications will be seen if I introduce another modification (3rd one) to the same record, as then I will have 2 entries on history table and your code can show modifications between both.

That doesn't happen with new records as they will get the 'initial' insert into history table and I will be able to see the modifications when I modify the record as your code will get differences from both records.

So, in the end, now I'm not able to track first modification from original record as I enabled history after those records where inserted into mysql database.

One solution I'm looking at is to export all data, dump table date, activate history and create a new import function for that data so it will get initial insert into history. Another way will be to look into all registers and call your history insert function to get it done for the first time.

Have you got a better way of inserting all those initial history registers?
jvinolas
 
Posts: 51
Joined: Thu Apr 15, 2010 12:31 am

Re: History when fields added to table?

Postby shannah » Thu May 12, 2011 11:43 am

You're right. History works by simply making a 2nd copy of your record (as you are saving it) in the history table at the time of save. It doesn't take the previous state. This presents the one-time problem that you describe as it won't make a history of the first state of the record.

I suppose we could change it to run before the save rather than after the save, but I'd have to think about this a bit as it's been a long time since I've delved into the History functionality and there may be a reason why it works the way it does.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: History when fields added to table?

Postby jvinolas » Fri May 13, 2011 1:09 am

Hi again,

I have to check yor code that inserts records into history table, but for me it will be perfect if that code evaluates if there is an entry for that record in related history table and, if false, it makes two inserts: one with old data and one with modified data. Otherwise, if true, just works as it does now: insert modified information.

That should be run just in case it is a modification to an existing record, not if new record created.

Maybe the problem will be that DATE an USER information of first record will not be true because we don't know who did the first entry, we are doing all that stuff because actual user is modifying a register. But I don't see the problem leaving those fields empty and showing differences on history (we will see that 'nobody at nodate did first entry'. Another option will be to use actual user and data for that record also.

Thanks!
jvinolas
 
Posts: 51
Joined: Thu Apr 15, 2010 12:31 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 16 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved