Enable contraint parent.filetype='DIR' in filedir
This commit is contained in:
parent
8d6395ecd1
commit
9d48d4d227
@ -99,8 +99,8 @@ CREATE TRIGGER insert_filedir BEFORE INSERT ON filedir
|
|||||||
BEGIN
|
BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
CASE
|
CASE
|
||||||
--WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM filedir WHERE id = NEW.parent) != 'DIR'
|
WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM filedir WHERE id = NEW.parent) != 'DIR'
|
||||||
--THEN RAISE (ABORT, 'Parent is not listed as a directory')
|
THEN RAISE (ABORT, 'Parent is not listed as a directory')
|
||||||
WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM filedir WHERE id = NEW.parent)
|
WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM filedir WHERE id = NEW.parent)
|
||||||
THEN RAISE (ABORT, 'Parent directory resides in different store')
|
THEN RAISE (ABORT, 'Parent directory resides in different store')
|
||||||
END;
|
END;
|
||||||
@ -109,8 +109,8 @@ CREATE TRIGGER update_filedir BEFORE UPDATE ON filedir
|
|||||||
BEGIN
|
BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
CASE
|
CASE
|
||||||
--WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM filedir WHERE id = NEW.parent) != 'DIR'
|
WHEN NEW.parent IS NOT NULL AND (SELECT filetype FROM filedir WHERE id = NEW.parent) != 'DIR'
|
||||||
--THEN RAISE (ABORT, 'Parent is not listed as a directory')
|
THEN RAISE (ABORT, 'Parent is not listed as a directory')
|
||||||
WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM filedir WHERE id = NEW.parent)
|
WHEN NEW.parent IS NOT NULL AND NEW.store != (SELECT store FROM filedir WHERE id = NEW.parent)
|
||||||
THEN RAISE (ABORT, 'Parent directory resides in different store')
|
THEN RAISE (ABORT, 'Parent directory resides in different store')
|
||||||
END;
|
END;
|
||||||
|
|||||||
@ -203,7 +203,7 @@ def test_crossstore_directory_insert(insert_directories):
|
|||||||
(
|
(
|
||||||
None, #id INTEGER PRIMARY KEY NOT NULL,
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
2, #store INTEGER NOT NULL,
|
2, #store INTEGER NOT NULL,
|
||||||
'some_filedir.txt', #filename TEXT, -- only a filename, not a path
|
'some_dir', #filename TEXT, -- only a filename, not a path
|
||||||
1, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE,
|
1, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE,
|
||||||
False, #frozen BOOL NOT NULL,
|
False, #frozen BOOL NOT NULL,
|
||||||
'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
||||||
@ -224,26 +224,56 @@ def insert_files(insert_directories):
|
|||||||
cur = insert_directories
|
cur = insert_directories
|
||||||
cur.executemany(
|
cur.executemany(
|
||||||
'INSERT INTO filedir VALUES '
|
'INSERT INTO filedir VALUES '
|
||||||
'(?, ?, ?, ?, ?, ?, ?, ?)',
|
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
[(
|
[(
|
||||||
None,
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
1, #directory INTEGER NOT NULL
|
1, #store INTEGER NOT NULL,
|
||||||
'example.csv', #filename TEXT
|
'example.csv', #filename TEXT, -- only a filename, not a path
|
||||||
1, #frozen BOOL NOT NULL
|
1, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE,
|
||||||
'-rw-rw-r--', #unfrozen_perms TEXT
|
False, #frozen BOOL NOT NULL,
|
||||||
|
'REG', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
||||||
|
'drw-rw-r--', #unfrozen_perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--'
|
||||||
|
None, #symlink_target TEXT, -- if this is a symlink, this is the (read but not fully resolved) target
|
||||||
'9aafde8f9dbec34c694b86333f746f58958c44247c474904e06d1f07f94292b4', #sha256 TEXT NOT NULL,
|
'9aafde8f9dbec34c694b86333f746f58958c44247c474904e06d1f07f94292b4', #sha256 TEXT NOT NULL,
|
||||||
None, #source_program INTEGER,
|
None, #source_program INTEGER, -- Note that this is redundant since datum points to a program...
|
||||||
None, #source_datum INTEGER,
|
None, #source_datum INTEGER,
|
||||||
), (
|
), (
|
||||||
None,
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
2, #directory INTEGER NOT NULL
|
1, #store INTEGER NOT NULL,
|
||||||
'plots.png', #filename TEXT
|
'plots.png', #filename TEXT, -- only a filename, not a path
|
||||||
1, #frozen BOOL NOT NULL
|
2, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE,
|
||||||
'-rw-r--r--', #unfrozen_perms TEXT
|
False, #frozen BOOL NOT NULL,
|
||||||
|
'REG', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
||||||
|
'drw-r--r--', #unfrozen_perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--'
|
||||||
|
None, #symlink_target TEXT, -- if this is a symlink, this is the (read but not fully resolved) target
|
||||||
'9add10cc3a6f0e4618dfed005ddfbeafdf268c58b773ba0021963c856d00235b', #sha256 TEXT NOT NULL,
|
'9add10cc3a6f0e4618dfed005ddfbeafdf268c58b773ba0021963c856d00235b', #sha256 TEXT NOT NULL,
|
||||||
None, #source_program INTEGER,
|
None, #source_program INTEGER, -- Note that this is redundant since datum points to a program...
|
||||||
None, #source_datum INTEGER,
|
None, #source_datum INTEGER,
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
return cur
|
return cur
|
||||||
|
|
||||||
|
def test_nondir_parent_directory_insert(insert_files):
|
||||||
|
cur = insert_files
|
||||||
|
with pytest.raises(sqlite3.IntegrityError):
|
||||||
|
# declaring parent as 5, but 5 is a file (plots.png)
|
||||||
|
cur.execute(
|
||||||
|
'INSERT INTO filedir VALUES '
|
||||||
|
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
|
(
|
||||||
|
None, #id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
2, #store INTEGER NOT NULL,
|
||||||
|
'some_filedir.txt', #filename TEXT, -- only a filename, not a path
|
||||||
|
5, #parent INTEGER REFERENCES filedir ON UPDATE CASCADE,
|
||||||
|
False, #frozen BOOL NOT NULL,
|
||||||
|
'DIR', #filetype TEXT, -- One of 'LNK', 'DIR', 'REG', etc. See store.FSEntry.from_path for details
|
||||||
|
'dr-xr-xr--', #unfrozen_perms TEXT, -- stat.filemode(os.stat(path).st_mode): '-rw-rw-r--'
|
||||||
|
None, #symlink_target TEXT, -- if this is a symlink, this is the (read but not fully resolved) target
|
||||||
|
'15c5e8d80a48803c18e72cd274532d608b8026dcbc192afc490fe1c289ec6ff1', #sha256 TEXT NOT NULL,
|
||||||
|
None, #source_program INTEGER, -- Note that this is redundant since datum points to a program...
|
||||||
|
None, #source_datum INTEGER,
|
||||||
|
))
|
||||||
|
for row in cur.connection.iterdump():
|
||||||
|
print(row)
|
||||||
|
cur.execute('SELECT * FROM filedir')
|
||||||
|
print(cur.fetchall())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user