You are not logged in.
Pages: 1
Hello Ab,
I have followed your instruction how to setup the history features but I don't see anywhere the history table in my database. My code is
Model := TSQLModel.Create([TSQLRecordHistory, TPhoMessartSQLRecord], ROOT_NAME);
VirtualTableExternalRegister(Model, TPhoMessartSQLRecord, FPhoRepository.MDBConnectionProperties, 'messart');
ServerDB := TSQLRestServerDB.Create(Model, ChangeFileExt(ExeVersion.ProgramFileName, '.db3'), False);
ServerDB.TrackChanges([TPhoMessartSQLRecord]);
ServerDB.CreateMissingTables;
ClientDB := TSQLRestClientDB.Create(ServerDB);
Then I add some new data into the table
var
I: Integer;
MA: TPhoMessartSQLRecord;
begin
MA := TPhoMessartSQLRecord.Create;
try
for I := 0 to 10 do
begin
MA.Name := IntToStr(I+1);
ClientDB.Add(MA, True);
end;
finally
MA.Free;
end;
end;
I don't see in the database any history-table. What am I doing wrong?
Offline
You do not have the History table in your main DB?
No, is it created automatically after calling "create missing tables"? What name should it get?
Offline
From your code, it is created in the Sqlite3 local .db3 file, not in the external database.
Ah ok, thx, I will try to read the history from the local file.
But how can I create the history table automatically by the mORMot in the external database? How would the code look like? Or should I create the table manually!?
Offline
You have to call VirtualTableExternalRegister() only for the history table, which is TSQLRecordHistory by default.
Or call VirtualTableExternalRegisterAll which will make all tables externals.
But honestly, the history may gain to be in the local SQlite3, since performance would probably be much higher.
Offline
You have to call VirtualTableExternalRegister() only for the history table, which is TSQLRecordHistory by default.
Or call VirtualTableExternalRegisterAll which will make all tables externals.But honestly, the history may gain to be in the local SQlite3, since performance would probably be much higher.
I can read the history from the local DB without problems!
But I would like to save the history in the external production db where the data is modified by multiple users.
Is there a possibility to turn on/off the "TrackChanges" at runtime?
Is a feature request worth also to save in the history who changed a data record?
Offline
Several features, including automatic history tracking, will only work when used from a single mORMot ORM Server.
You need a single REST server to be able to track all modifications in a safe way.
If the data is modified in an external DB, the history tracking won't work.
The same for the automatic database synchronization feature - e.g. via WebSockets.
You may be able to achieve something similar by using SQL triggers, but it is much more complex and slow than our REST implementation.
This is definitively a feature we would not support now.
ServerDB.TrackChanges([TPhoMessartSQLRecord]) is expected to be enabled, otherwise it would miss some modifications.
There is no track of "who" did make the data record change yet.
Offline
Pages: 1