overleaf/services/history-v1/storage/scripts/global-blobs-db-cleanup/03-create-global-blobs-table.sql
Alf Eaton ee85d948e2 Avoid duplicating a math-closing dollar sign (#11227)
GitOrigin-RevId: ef2ef77e26df59d1af3df6dc664e284d3c70102d
2023-01-16 08:41:42 +00:00

16 lines
607 B
SQL

CREATE TABLE global_blobs (
hash_bytes bytea NOT NULL,
byte_length integer NOT NULL,
string_length integer,
global boolean,
CONSTRAINT global_blobs_pkey PRIMARY KEY (hash_bytes),
CONSTRAINT global_blobs_byte_length_non_negative
CHECK (byte_length >= 0),
CONSTRAINT global_blobs_string_length_non_negative
CHECK (string_length IS NULL OR string_length >= 0)
);
INSERT INTO global_blobs (hash_bytes, byte_length, string_length, global)
SELECT hash_bytes, byte_length, string_length, true
FROM blobs
WHERE hash_bytes IN (SELECT hash_bytes FROM global_blob_hashes);