是否有可能,如果可以,我如何有效地将本地数据库与全局数据库同步,以便在对本地版本执行操作时也会在全局数据库上执行操作。简单地使用版本控制来颠覆全局是不可接受的,因为根据对数据库进行更改的人数,可能存在数据库的多个本地副本。换句话说,是否可以只拥有数据库的镜像,以便即使它位于网络上的其他地方也可以在本地访问它。
1 回答
Synchronizing databases if a very complex topic. The simplest approach is to keep a record at the application level (or though a custom sqlite wrapper) of all queries run against each system and then run those again when synchronizing.
This becomes problematic when you have multiple sources or two way synchronization. Queries that ran fine on one database may fail on an other due to different order of operations (assuming referential integrity is enabled).
Another more complex but robust approach is to keep track of a full transaction history for each table. You'll also need to know which records were affected in each transaction, and the order within each transaction. When that's done, you'll probably need a way to detect when problems will occur and automatically work around them.