#1 2015-05-20 12:31:49

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

using the history feature

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

#2 2015-05-20 14:06:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: using the history feature

You do not have the History table in your main DB?

Offline

#3 2015-05-20 14:12:23

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

Re: using the history feature

ab wrote:

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

#4 2015-05-20 19:37:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: using the history feature

From your code, it is created in the Sqlite3 local .db3 file, not in the external database.

Offline

#5 2015-05-21 05:47:46

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

Re: using the history feature

ab wrote:

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

#6 2015-05-21 06:43:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: using the history feature

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

#7 2015-05-21 09:12:39

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

Re: using the history feature

ab wrote:

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

#8 2015-05-21 12:25:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: using the history feature

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

Board footer

Powered by FluxBB