Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/db.py
Show All 22 Lines | def jsonize(d): | ||||
return _jsonize(dict(d) if d is not None else None) | return _jsonize(dict(d) if d is not None else None) | ||||
class Db(BaseDb): | class Db(BaseDb): | ||||
"""Proxy to the SWH DB, with wrappers around stored procedures | """Proxy to the SWH DB, with wrappers around stored procedures | ||||
""" | """ | ||||
current_version = 167 | current_version = 169 | ||||
def mktemp_dir_entry(self, entry_type, cur=None): | def mktemp_dir_entry(self, entry_type, cur=None): | ||||
self._cursor(cur).execute( | self._cursor(cur).execute( | ||||
"SELECT swh_mktemp_dir_entry(%s)", (("directory_entry_%s" % entry_type),) | "SELECT swh_mktemp_dir_entry(%s)", (("directory_entry_%s" % entry_type),) | ||||
) | ) | ||||
@stored_procedure("swh_mktemp_revision") | @stored_procedure("swh_mktemp_revision") | ||||
def mktemp_revision(self, cur=None): | def mktemp_revision(self, cur=None): | ||||
▲ Show 20 Lines • Show All 1,100 Lines • ▼ Show 20 Lines | _raw_extrinsic_metadata_context_cols = [ | ||||
"release", | "release", | ||||
"revision", | "revision", | ||||
"path", | "path", | ||||
"directory", | "directory", | ||||
] | ] | ||||
"""The list of context columns for all artifact types.""" | """The list of context columns for all artifact types.""" | ||||
_raw_extrinsic_metadata_insert_cols = [ | _raw_extrinsic_metadata_insert_cols = [ | ||||
"id", | |||||
"type", | "type", | ||||
"target", | "target", | ||||
"authority_id", | "authority_id", | ||||
"fetcher_id", | "fetcher_id", | ||||
"discovery_date", | "discovery_date", | ||||
"format", | "format", | ||||
"metadata", | "metadata", | ||||
*_raw_extrinsic_metadata_context_cols, | *_raw_extrinsic_metadata_context_cols, | ||||
] | ] | ||||
"""List of columns of the raw_extrinsic_metadata table, used when writing | """List of columns of the raw_extrinsic_metadata table, used when writing | ||||
metadata.""" | metadata.""" | ||||
_raw_extrinsic_metadata_insert_query = f""" | _raw_extrinsic_metadata_insert_query = f""" | ||||
INSERT INTO raw_extrinsic_metadata | INSERT INTO raw_extrinsic_metadata | ||||
({', '.join(_raw_extrinsic_metadata_insert_cols)}) | ({', '.join(_raw_extrinsic_metadata_insert_cols)}) | ||||
VALUES ({', '.join('%s' for _ in _raw_extrinsic_metadata_insert_cols)}) | VALUES ({', '.join('%s' for _ in _raw_extrinsic_metadata_insert_cols)}) | ||||
ON CONFLICT (target, authority_id, discovery_date, fetcher_id) | ON CONFLICT (id) | ||||
DO NOTHING | DO NOTHING | ||||
""" | """ | ||||
raw_extrinsic_metadata_get_cols = [ | raw_extrinsic_metadata_get_cols = [ | ||||
"raw_extrinsic_metadata.target", | "raw_extrinsic_metadata.target", | ||||
"raw_extrinsic_metadata.type", | "raw_extrinsic_metadata.type", | ||||
"discovery_date", | "discovery_date", | ||||
"metadata_authority.type", | "metadata_authority.type", | ||||
Show All 15 Lines | _raw_extrinsic_metadata_select_query = f""" | ||||
INNER JOIN metadata_authority | INNER JOIN metadata_authority | ||||
ON (metadata_authority.id=authority_id) | ON (metadata_authority.id=authority_id) | ||||
INNER JOIN metadata_fetcher ON (metadata_fetcher.id=fetcher_id) | INNER JOIN metadata_fetcher ON (metadata_fetcher.id=fetcher_id) | ||||
WHERE raw_extrinsic_metadata.target=%s AND authority_id=%s | WHERE raw_extrinsic_metadata.target=%s AND authority_id=%s | ||||
""" | """ | ||||
def raw_extrinsic_metadata_add( | def raw_extrinsic_metadata_add( | ||||
self, | self, | ||||
id: bytes, | |||||
type: str, | type: str, | ||||
target: str, | target: str, | ||||
discovery_date: datetime.datetime, | discovery_date: datetime.datetime, | ||||
authority_id: int, | authority_id: int, | ||||
fetcher_id: int, | fetcher_id: int, | ||||
format: str, | format: str, | ||||
metadata: bytes, | metadata: bytes, | ||||
origin: Optional[str], | origin: Optional[str], | ||||
visit: Optional[int], | visit: Optional[int], | ||||
snapshot: Optional[str], | snapshot: Optional[str], | ||||
release: Optional[str], | release: Optional[str], | ||||
revision: Optional[str], | revision: Optional[str], | ||||
path: Optional[bytes], | path: Optional[bytes], | ||||
directory: Optional[str], | directory: Optional[str], | ||||
cur, | cur, | ||||
): | ): | ||||
query = self._raw_extrinsic_metadata_insert_query | query = self._raw_extrinsic_metadata_insert_query | ||||
args: Dict[str, Any] = dict( | args: Dict[str, Any] = dict( | ||||
id=id, | |||||
type=type, | type=type, | ||||
target=target, | target=target, | ||||
authority_id=authority_id, | authority_id=authority_id, | ||||
fetcher_id=fetcher_id, | fetcher_id=fetcher_id, | ||||
discovery_date=discovery_date, | discovery_date=discovery_date, | ||||
format=format, | format=format, | ||||
metadata=metadata, | metadata=metadata, | ||||
origin=origin, | origin=origin, | ||||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |