diff --git a/src/nancy/schema/version0.sql b/src/nancy/schema/version0.sql index 9bfe3d1..c777ab7 100644 --- a/src/nancy/schema/version0.sql +++ b/src/nancy/schema/version0.sql @@ -76,9 +76,22 @@ CREATE TABLE user(id INTEGER PRIMARY KEY NOT NULL, -- Stores and files (and directories) -- These are the primary objects tracked by nancy. -- A store is a directory containing a file called nancy.db (e.g. the dir holding this database) +-- In order to reliably merge store entries (like when we have converging +-- dependencies), we need to deduplicate. The machine and path could match, for +-- example if a database is created in one location then copied elsewhere, +-- followed by regenerating the original database. In these cases, we would want +-- to distinguish the new database from the copied one while still being able to +-- equate two simple copies of a db. +-- For this we use a UUID generated randomly +-- by the client. SQLite does not natively support UUIDs but it is stored here +-- as a string. +-- Client code should generate random UUIDs in the RFC 4122 variant layout. +-- https://datatracker.ietf.org/doc/html/rfc4122.html +-- This is possible in Python by simply calling uuid.uuid4() with no arguments CREATE TABLE store (id INTEGER PRIMARY KEY NOT NULL, machine INTEGER, dbpath TEXT NOT NULL, + uuid TEXT NOT NULL, -- str(uuid.uuid4()) imported BOOL, -- is this the store for the current directory? If not, then it was -- imported in order to describe a dependency. diff --git a/tests/test_db.py b/tests/test_db.py index 589e8e3..7ad04f2 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -123,25 +123,29 @@ def test_invalid_user_machine(insert_user): @pytest.fixture def insert_store(insert_machine): + import uuid cur = insert_machine cur.executemany( 'INSERT INTO store VALUES ' - '(?, ?, ?, ?)', + '(?, ?, ?, ?, ?)', [( None, #id INTEGER PRIMARY KEY NOT NULL, 1, #machine INTEGER, '/path/to/first/store', #dbpath TEXT NOT NULL, + str(uuid.uuid4()), #-- UUID generated by str(uuid.uuid4()) False, #imported BOOL, ), ( None, #id INTEGER PRIMARY KEY NOT NULL, 1, #machine INTEGER, '/path/to/dependency/store', #dbpath TEXT NOT NULL, + str(uuid.uuid4()), #-- UUID generated by str(uuid.uuid4()) True, #imported BOOL, ), ( None, #id INTEGER PRIMARY KEY NOT NULL, 2, #machine INTEGER, # same path but on a separate machine '/path/to/first/store', #dbpath TEXT NOT NULL, + str(uuid.uuid4()), #-- UUID generated by str(uuid.uuid4()) True, #imported BOOL, )], )