This commit is contained in:
Bryan Ashby 2020-11-29 16:24:51 -07:00
parent 4d42eeb318
commit e05e8a2e35
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
3 changed files with 18 additions and 3 deletions

View File

@ -421,7 +421,8 @@ const DB_INIT_TABLE = {
hash_tag_id INTEGER NOT NULL, hash_tag_id INTEGER NOT NULL,
file_id INTEGER NOT NULL, file_id INTEGER NOT NULL,
UNIQUE(hash_tag_id, file_id) UNIQUE(hash_tag_id, file_id),
FOREIGN KEY(file_id) REFERENCES file(file_id) ON DELETE CASCADE
);` );`
); );
@ -431,7 +432,10 @@ const DB_INIT_TABLE = {
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
rating INTEGER NOT NULL, rating INTEGER NOT NULL,
UNIQUE(file_id, user_id) UNIQUE(file_id, user_id),
FOREIGN KEY(file_id) REFERENCES file(file_id) ON DELETE CASCADE
-- Note that we cannot CASCADE if user_id is removed from user.db
-- See processing in oputil's removeUser()
);` );`
); );
@ -447,7 +451,8 @@ const DB_INIT_TABLE = {
hash_id VARCHAR NOT NULL, hash_id VARCHAR NOT NULL,
file_id INTEGER NOT NULL, file_id INTEGER NOT NULL,
UNIQUE(hash_id, file_id) UNIQUE(hash_id, file_id),
FOREIGN KEY(file_id) REFERENCES file(file_id) ON DELETE CASCADE
);` );`
); );

View File

@ -243,6 +243,15 @@ module.exports = class FileEntry {
); );
} }
static removeUserRatings(userId, cb) {
return fileDb.run(
`DELETE FROM file_user_rating
WHERE user_id = ?;`,
[ userId ],
cb
);
}
static persistMetaValue(fileId, name, value, transOrDb, cb) { static persistMetaValue(fileId, name, value, transOrDb, cb) {
if(!_.isFunction(cb) && _.isFunction(transOrDb)) { if(!_.isFunction(cb) && _.isFunction(transOrDb)) {
cb = transOrDb; cb = transOrDb;

View File

@ -172,6 +172,7 @@ function removeUser(user) {
message : [ 'user_message_area_last_read' ], message : [ 'user_message_area_last_read' ],
system : [ 'user_event_log', ], system : [ 'user_event_log', ],
user : [ 'user_group_member', 'user' ], user : [ 'user_group_member', 'user' ],
file : [ 'file_user_rating']
}; };
async.eachSeries(Object.keys(DeleteFrom), (dbName, nextDbName) => { async.eachSeries(Object.keys(DeleteFrom), (dbName, nextDbName) => {