Check synchronization of local and cloud sqlite databases#
import os
instance_name = f"test-sqlite-sync"
!lamin load {instance_name}
!yes | lamin delete {instance_name}
from lamindb_setup import init, settings
import os
init(
storage=f"s3://lamindb-ci/{instance_name}",
name=instance_name,
)
Get the paths to the cloud and local sqlite databases.
sqlite_file = settings.instance._sqlite_file
sqlite_file
Remote SQLite file does exists upon instance init:
assert settings.instance._sqlite_file.exists()
Now mimic a new user who loads the instance (this runs 4s):
settings.instance._update_local_sqlite_file()
Get the mere filepath of the local file, without any update:
cache_file = settings.instance.storage.cloud_to_local_no_update(sqlite_file)
cache_file
Delete the local sqlite file:
cache_file.unlink()
assert not cache_file.exists()
Update the local version of the sqlite file:
settings.instance._update_local_sqlite_file()
assert cache_file.exists()
If the local sqlite database is older than the cloud one, the cloud database replaces the local sqlite database file.
cloud_mtime = sqlite_file.modified.timestamp()
cloud_mtime
os.utime(cache_file, times=(cloud_mtime - 1, cloud_mtime - 1))
assert cache_file.stat().st_mtime < sqlite_file.modified.timestamp()
settings.instance._update_local_sqlite_file()
assert cache_file.stat().st_mtime == sqlite_file.modified.timestamp()
Show code cell content
!yes | lamin delete {instance_name}