Rename "store" to "dataset" in schema

This commit is contained in:
Jacob Hinkle 2022-11-09 12:48:06 -05:00
parent 12b669d591
commit e5fa7a32f2

View File

@ -1,5 +1,5 @@
-- Simple key/value table describing _this_ store (not imported ones).
-- In particular, the key "local_store" should be the UUID of the store in this
-- Simple key/value table describing _this_ dataset (not imported ones).
-- In particular, the key "local_dataset" should be the UUID of the dataset in this
-- directory.
CREATE TABLE local_metadata(
key TEXT PRIMARY KEY NOT NULL,
@ -54,8 +54,8 @@ CREATE INDEX FK_user_machine ON user (machine);
-- 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
-- A dataset is a directory containing a file called nancy.db (e.g. the dir holding this database)
-- In order to reliably merge dataset 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
@ -67,29 +67,29 @@ CREATE INDEX FK_user_machine ON user (machine);
-- 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 (
CREATE TABLE dataset (
uuid BLOB PRIMARY KEY NOT NULL -- UUID generated by uuid.uuid4()
);
-- The filedir table holds all files and directories that are tracked by the
-- store. This table also holds tracked files and directories that have been
-- imported and live outside the current store.
-- dataset. This table also holds tracked files and directories that have been
-- imported and live outside the current dataset.
-- We do not support renaming files.
CREATE TABLE filedir (
sha256 BLOB PRIMARY KEY NOT NULL,
store BLOB NOT NULL REFERENCES store ON UPDATE CASCADE,
dataset BLOB NOT NULL REFERENCES dataset ON UPDATE CASCADE,
name TEXT, -- only a filename, not a path
parent BLOB REFERENCES filedir ON UPDATE CASCADE,
UNIQUE(store, name, parent)
UNIQUE(dataset, name, parent)
);
CREATE INDEX FK_filedir_store ON filedir (store);
CREATE INDEX FK_filedir_dataset ON filedir (dataset);
CREATE INDEX FK_filedir_parent ON filedir (parent);
-- Detect cross-store references
-- Detect cross-dataset references
CREATE TRIGGER insert_filedir BEFORE INSERT ON filedir
BEGIN SELECT CASE
WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM filedir WHERE sha256 = NEW.parent)
THEN RAISE (ABORT, 'Parent resides in different store')
WHEN NEW.parent IS NOT NULL AND NEW.dataset != (SELECT dataset FROM filedir WHERE sha256 = NEW.parent)
THEN RAISE (ABORT, 'Parent resides in different dataset')
END; END;
CREATE TRIGGER update_filedir BEFORE UPDATE ON filedir
BEGIN
@ -112,12 +112,8 @@ CREATE TABLE filedir_version (
-- Note that changing filetype (e.g. directory becomes file) or deleting a
-- file are simply just new versions of a filedir.
filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc.
deleted BOOL NOT NULL, -- set True when recording a deleted file
-- We record the permissions on each file to enable fixing if needed
perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--'
symlink_target TEXT, -- if this is a symlink, this is the (read but not fully resolved) target. i.e. this is the "content" of the symlink.
-- The following hash can be NULL if the file was deleted. It could also be