Let's suppose I have the following structure.
XData Echo Server - United States
Client 1 - Argentina (1 user running the system/client)
Client 2 - Brazil (1 user running the system/client)
All sharing the same database.
When using NodeManager.CreateNode and NodeManager.DefineSelfNode on clients 1 and 2, can they both have the same NodeID?
Is it possible/recommended to remove a node on the client (remove the corresponding records in ECHO_SELF_NODE/ECHO_NODE)?
Is it possible/recommended to unregister a client node on the server (remove the corresponding registration in ECHO_NODE)?
No. Those names will be replicated to other nodes and need to be unique so Echo knows where the data goes to.
Why would you want to do that? In theory, no, not recommended.
It's recommended to simply disable a node in server, so data doesn't get replicated to it anymore.
I have a multi-tenant structure.
Access to the client application is protected by username and password. This user's ID is used as the NodeID.
On the server, I filter replications so clients 1 and 2 don't transfer data to each other.
It is possible for customer 1 to log out and log into customer 2's account. In that case, I would need to remove the SelfNode and create it again.
I would recommend you use two different databases for that. Otherwise, you will end up mixing data for both customers. You really want client 1 to change data, then logout, login as client 2 and suddenly all pending client 1 not belongs to client 2? It doesn't look it's desired behavior.
Yes, the idea is that a client 3 (system administrator/support) can do this task.
At the moment, all my tables have a column called "CLIENT_ID".
On the server, the filtering is done like this:
Timer := TSparkleTimer.Create (
procedure ( Echo : TObject )
ACon : IDBConnection;
AStatement : IDBStatement;
TEcho ( Echo ) .BatchLoad ( TMappingExplorer.Get ( 'ECHO_SYNC' ) ) ;
TEcho ( Echo ) .Route (
procedure ( Log : TEchoLog; Node : TEchoNode; var Route : boolean )
ACon := CreateAdaptedFBCon ( ) ;
AStatement := ACon.CreateStatement;
AStatement.SetSQLCommand ( Format ( 'SELECT 1 FROM %s WHERE ID = %s AND CLIENT_ID = %s' , [ Copy ( Log.EntityClass , 12 , Length ( Log.EntityClass ) - 11 ) , QuotedStr ( Log.EntityId ) , QuotedStr ( Node.Id ) ] ) ) ;
Route := AStatement.ExecuteQuery.Next;
Route := False;
Echo , 15000 , TTimerType.Periodic ) ;
But you're right, it's better to use multiple databases (one for each customer).
Considering this scenario, on my server: Can I have just one database (containing the records of all clients) or should I also have a database for each client?
Yes, you can have one single database in the server. Actually each client database is a different node, it doesn't matter if it's in the same computer or a different one.
Suppose I already have a database with records (managed by Aurelius/Echo). If I want to create a new client, is it my responsibility to insert the records that are already in the server's database into the new client? Or is echo able to sync them?
You have to insert existing records manually.