Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/schema.py
Show First 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | |||||
);""", | );""", | ||||
""" | """ | ||||
CREATE TABLE IF NOT EXISTS extid_by_target ( | CREATE TABLE IF NOT EXISTS extid_by_target ( | ||||
target_type ascii, | target_type ascii, | ||||
target blob, | target blob, | ||||
target_token bigint, -- value of token(pk) on the "primary" table | target_token bigint, -- value of token(pk) on the "primary" table | ||||
PRIMARY KEY ((target_type, target), target_token) | PRIMARY KEY ((target_type, target), target_token) | ||||
);""", | );""", | ||||
""" | |||||
CREATE TABLE IF NOT EXISTS extid_by_target_type_version ( | |||||
target_type ascii, | |||||
target blob, | |||||
extid_type ascii, | |||||
extid_version smallint, | |||||
target_token bigint, -- value of token(pk) on the "primary" table | |||||
PRIMARY KEY ((target_type, target, extid_type, extid_version), target_token) | |||||
);""", | |||||
] | ] | ||||
CONTENT_INDEX_TEMPLATE = """ | CONTENT_INDEX_TEMPLATE = """ | ||||
-- Secondary table, used for looking up "content" from a single hash | -- Secondary table, used for looking up "content" from a single hash | ||||
CREATE TABLE IF NOT EXISTS content_by_{main_algo} ( | CREATE TABLE IF NOT EXISTS content_by_{main_algo} ( | ||||
{main_algo} blob, | {main_algo} blob, | ||||
target_token bigint, -- value of token(pk) on the "primary" table | target_token bigint, -- value of token(pk) on the "primary" table | ||||
PRIMARY KEY (({main_algo}), target_token) | PRIMARY KEY (({main_algo}), target_token) | ||||
Show All 19 Lines | TABLES = [ | ||||
"origin_visit", | "origin_visit", | ||||
"origin", | "origin", | ||||
"raw_extrinsic_metadata", | "raw_extrinsic_metadata", | ||||
"origin_visit_status", | "origin_visit_status", | ||||
"metadata_authority", | "metadata_authority", | ||||
"metadata_fetcher", | "metadata_fetcher", | ||||
"extid", | "extid", | ||||
"extid_by_target", | "extid_by_target", | ||||
"extid_by_target_type_version", | |||||
] | ] | ||||
HASH_ALGORITHMS = ["sha1", "sha1_git", "sha256", "blake2s256"] | HASH_ALGORITHMS = ["sha1", "sha1_git", "sha256", "blake2s256"] | ||||
for main_algo in HASH_ALGORITHMS: | for main_algo in HASH_ALGORITHMS: | ||||
CREATE_TABLES_QUERIES.extend( | CREATE_TABLES_QUERIES.extend( | ||||
CONTENT_INDEX_TEMPLATE.format( | CONTENT_INDEX_TEMPLATE.format( | ||||
main_algo=main_algo, | main_algo=main_algo, | ||||
other_algos=", ".join( | other_algos=", ".join( | ||||
[algo for algo in HASH_ALGORITHMS if algo != main_algo] | [algo for algo in HASH_ALGORITHMS if algo != main_algo] | ||||
), | ), | ||||
).split("\n\n") | ).split("\n\n") | ||||
) | ) | ||||
TABLES.append("content_by_%s" % main_algo) | TABLES.append("content_by_%s" % main_algo) | ||||
TABLES.append("skipped_content_by_%s" % main_algo) | TABLES.append("skipped_content_by_%s" % main_algo) |