core (memory/sqlite): new database schema (v9):

this new schema brings the new `public_id` column, which will be used to serve files via
HTTP, splits `mime_type` in 2 (`media_type` and `media_subtype`) to make indexing/media
filtering easier, and fixes indexes for `files` table.
This commit is contained in:
Goffi 2020-05-29 21:50:49 +02:00
commit d1521dde4b

View file

@ -22,6 +22,7 @@ import copy
import shortuuid
import mimetypes
import time
from pathlib import Path
from uuid import uuid4
from collections import namedtuple
from twisted.python import failure
@ -1293,8 +1294,8 @@ class Memory(object):
def getFiles(
self, client, peer_jid, file_id=None, version=None, parent=None, path=None,
type_=None, file_hash=None, hash_algo=None, name=None, namespace=None,
mime_type=None, owner=None, access=None, projection=None, unique=False,
perms_to_check=(C.ACCESS_PERM_READ,)):
mime_type=None, public_id=None, owner=None, access=None, projection=None,
unique=False, perms_to_check=(C.ACCESS_PERM_READ,)):
"""Retrieve files with with given filters
@param peer_jid(jid.JID, None): jid trying to access the file
@ -1315,6 +1316,7 @@ class Memory(object):
@param name(unicode, None): name of the file to retrieve
@param namespace(unicode, None): namespace of the files to retrieve
@param mime_type(unicode, None): filter on this mime type
@param public_id(unicode, None): filter on this public id
@param owner(jid.JID, None): if not None, only get files from this owner
@param access(dict, None): get file with given access (see [setFile])
@param projection(list[unicode], None): name of columns to retrieve
@ -1369,6 +1371,7 @@ class Memory(object):
name=name,
namespace=namespace,
mime_type=mime_type,
public_id=public_id,
owner=owner,
access=access,
projection=projection,
@ -1389,11 +1392,12 @@ class Memory(object):
@defer.inlineCallbacks
def setFile(
self, client, name, file_id=None, version="", parent=None, path=None,
type_=C.FILE_TYPE_FILE, file_hash=None, hash_algo=None, size=None,
namespace=None, mime_type=None, created=None, modified=None, owner=None,
access=None, extra=None, peer_jid=None, perms_to_check=(C.ACCESS_PERM_WRITE,)
):
self, client, name, file_id=None, version="", parent=None, path=None,
type_=C.FILE_TYPE_FILE, file_hash=None, hash_algo=None, size=None,
namespace=None, mime_type=None, public_id=None, created=None, modified=None,
owner=None, access=None, extra=None, peer_jid=None,
perms_to_check=(C.ACCESS_PERM_WRITE,)
):
"""Set a file metadata
@param name(unicode): basename of the file
@ -1411,6 +1415,7 @@ class Memory(object):
files
For instance, namespace could be used to group files in a specific photo album
@param mime_type(unicode): MIME type of the file, or None if not known/guessed
@param public_id(unicode): id used to share publicly the file via HTTP
@param created(int): UNIX time of creation
@param modified(int,None): UNIX time of last modification, or None to use
created date
@ -1448,7 +1453,11 @@ class Memory(object):
):
raise ValueError("file_hash and hash_algo must be set at the same time")
if mime_type is None:
mime_type, file_encoding = mimetypes.guess_type(name)
mime_type, __ = mimetypes.guess_type(name)
else:
mime_type = mime_type.lower()
if public_id is not None:
assert len(public_id)>0
if created is None:
created = time.time()
if namespace is not None:
@ -1477,6 +1486,7 @@ class Memory(object):
parent=parent,
type_=C.FILE_TYPE_DIRECTORY,
namespace=namespace,
public_id=public_id,
created=time.time(),
owner=owner,
access=access,
@ -1498,6 +1508,7 @@ class Memory(object):
size=size,
namespace=namespace,
mime_type=mime_type,
public_id=public_id,
created=created,
modified=modified,
owner=owner,
@ -1518,7 +1529,14 @@ class Memory(object):
return self.storage.fileUpdate(file_id, column, update_cb)
@defer.inlineCallbacks
def _deleteFile(self, client, peer_jid, recursive, files_path, file_data):
def _deleteFile(
self,
client,
peer_jid: jid.JID,
recursive: bool,
files_path: Path,
file_data: dict
):
"""Internal method to delete files/directories recursively
@param peer_jid(jid.JID): entity requesting the deletion (must be owner of files