#1 2016-12-30 11:00:13

juwo
Member
Registered: 2014-09-05
Posts: 21

how to check whether server uses the same model

Hi,
Is it possible to check (from client side - TSQLHttpClient) whether the server uses the same data model?
For example to show message "Please upgrade your server"

Regards

Offline

#2 2016-12-30 13:18:50

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 333

Re: how to check whether server uses the same model

The "root" parameter in TSQLHttpClient and TSQLRestServer always must be the same, you can use it.

Regards.


Esteban

Online

#3 2016-12-30 15:00:07

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: how to check whether server uses the same model

@EMartin, can you be more obvious? I don't understand it. Thanks.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2016-12-30 15:20:54

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 333

Re: how to check whether server uses the same model

@edwinsn, is simple:

when you create a, for i.e, TSQLRestServerDB, you does the following:

1) create a server

  ...
  MyModel := TSQLModel.Create([TSQLRecords ...], "root");
  MyRestServer := TSQLRestServerDB.Create(MyModel, 'MyDB.db3', false);
  ...

2) create a client that talk to 1)

  ...
  MyModel := TSQLModel.Create([TSQLRecords ...], "root");
  MyClient := TSQLHttpClient.Create(serverhost, serverport, MyModel);
  ...

Client can talk only with server with same "root", "root" can be any name of course.

I hope that I was clear.

Best regards.


Esteban

Online

#5 2017-01-04 03:00:32

Bo
Member
From: Melbourne
Registered: 2016-07-04
Posts: 48
Website

Re: how to check whether server uses the same model

@EMartin,

I guess what juwo wanted to know was what happen if a client connect to a server on which was running on a different "Data Model" in which had slightly different TSQLRecords (different fields, different field type etc.). For example, the server and the clients were all on the version 1.0, and then the server was upgraded to 2.0, but not all of the clients were upgraded to 2.0, thus some of them would be using a different version of "Data Model", is there a way to avoid this situation or it has been guarded by the mORMot already?

Offline

#6 2017-01-04 06:36:04

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: how to check whether server uses the same model

Thanks for the explanation @EMartin. I think @Bo's understand of @juwo's question is correct.

I don't think there are "automatic" ways of that

One idea implementing this:
You set up a global "gDbSchemaVersionNoEach" variable, and each time you upgrade the db schema, you increase that value, and you can expose that version number to the clients via a Method-based API. If you want to store the version number in a sqlite db file, consider the official schema_version PRAGMA (https://www.sqlite.org/pragma.html#prag … ma_version)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#7 2017-01-04 10:56:05

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 333

Re: how to check whether server uses the same model

Sorry for my understood. It's weird for me upgrade the server and not the client, but if the client drive the update (assuming Delphi client) then the client should have the latest version number and compare this with the server version number, for example, after the login you can return the actual server version extending TSQLAuthUser.

Best regards.

Esteban


Esteban

Online

#8 2017-01-13 17:03:14

juwo
Member
Registered: 2014-09-05
Posts: 21

Re: how to check whether server uses the same model

Thanks a lot for your answers. I applied @edwinsn sugestion: variable and api on server

procedure TNoteServer.Model(Ctxt: TSQLRestServerURIContext);
begin
    case Ctxt.Method of
    mGET:
      Ctxt.ReturnsJson(_ObjFast(['ver', model_ver]));
    end;
end;

That works perfectly. Thanks!

@Bo you are correct i would like to avoid problems when not all clients was upgraded, or someone upgrade clients without server

Last edited by juwo (2017-01-13 17:08:51)

Offline

Board footer

Powered by FluxBB