Add UUID to store table.
This commit is contained in:
parent
fb6a54c6ef
commit
bf141afa5f
@ -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.
|
||||
|
||||
|
||||
@ -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,
|
||||
)],
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user