Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 920fffc

Browse files
committed
fix: sql logic errors
1 parent 8ed6bfd commit 920fffc

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

migrations/0000_actors.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
CREATE TABLE IF NOT EXISTS actors (
22
-- unique actor id
33
uaid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
4-
local_name TEXT UNIQUE NOT NULL
4+
local_name TEXT UNIQUE NOT NULL,
5+
deactivated BOOLEAN NOT NULL DEFAULT false
56
);
67

8+
COMMENT ON TABLE actors IS 'Actors from this home server.';
9+
710
CREATE TABLE IF NOT EXISTS name_history (
811
uaid UUID NOT NULL REFERENCES actors (uaid) ON DELETE CASCADE,
912
time TIMESTAMP NOT NULL DEFAULT now(),

migrations/0001_federated_identity.sql

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ CREATE TABLE IF NOT EXISTS issuers (
3434
COMMENT ON TABLE issuers IS 'Issuers. Deduplicates issuer entries. Especially helpful, if the domain of this home server changes.';
3535

3636
CREATE TABLE IF NOT EXISTS idcsr (
37-
id BIGSERIAL UNIQUE NOT NULL,
38-
uaid UUID PRIMARY KEY REFERENCES actors (uaid) ON DELETE CASCADE,
39-
public_key_id BIGINT UNIQUE NOT NULL REFERENCES public_keys (id) ON DELETE CASCADE,
37+
serial_number UUID PRIMARY KEY DEFAULT gen_random_uuid(),
38+
uaid UUID NOT NULL REFERENCES actors (uaid) ON DELETE CASCADE,
39+
actor_public_key_id BIGINT UNIQUE NOT NULL REFERENCES public_keys (id) ON DELETE CASCADE,
40+
actor_signature TEXT UNIQUE NOT NULL,
4041
session_id VARCHAR(32) NOT NULL,
4142
valid_not_before TIMESTAMP NULL,
4243
valid_not_after TIMESTAMP NULL,
@@ -47,18 +48,27 @@ CREATE TABLE IF NOT EXISTS idcsr (
4748
COMMENT ON TABLE idcsr IS 'ID-CSRs.';
4849

4950
CREATE TABLE IF NOT EXISTS idcert (
50-
uaid UUID NOT NULL REFERENCES actors (uaid) ON DELETE CASCADE,
51-
id_csr_id BIGINT UNIQUE NOT NULL REFERENCES idcsr (id),
51+
serial_number UUID PRIMARY KEY REFERENCES idcsr (serial_number),
5252
issuer_info_id BIGINT NOT NULL REFERENCES issuers (id) ON DELETE CASCADE,
5353
valid_not_before TIMESTAMP NOT NULL,
5454
valid_not_after TIMESTAMP NOT NULL,
55-
actor_signature_algorithm_identifier INT NOT NULL REFERENCES algorithm_identifiers (id) ON DELETE CASCADE,
55+
home_server_public_key_id INT NOT NULL REFERENCES public_keys (id) ON DELETE CASCADE,
5656
home_server_signature TEXT UNIQUE NOT NULL,
5757
pem_encoded TEXT UNIQUE NOT NULL
5858
);
5959

6060
COMMENT ON TABLE idcert IS 'ID-Certs.';
6161

62+
CREATE TABLE IF NOT EXISTS idcert_cached (
63+
serial_number UUID PRIMARY KEY REFERENCES idcert (serial_number),
64+
invalidated_at TIMESTAMP NULL,
65+
cache_not_valid_before TIMESTAMP NOT NULL,
66+
cache_not_valid_after TIMESTAMP NOT NULL,
67+
cache_signature TEXT UNIQUE NOT NULL
68+
);
69+
70+
COMMENT ON TABLE idcert_cached IS 'ID-Certs issued by this home server with additional cache information.';
71+
6272
CREATE TABLE IF NOT EXISTS foreign_cached_idcerts (
6373
federation_id TEXT NOT NULL,
6474
session_id VARCHAR(32) NOT NULL,

migrations/0002_keytrials.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE IF NOT EXISTS keytrials (
22
id BIGSERIAL PRIMARY KEY,
3-
for_id_cert BIGINT NOT NULL REFERENCES idcsr (id) ON DELETE CASCADE,
3+
for_id_cert_serial_number UUID NOT NULL REFERENCES idcsr (serial_number) ON DELETE CASCADE,
44
expires TIMESTAMP NOT NULL,
55
trial VARCHAR(256) NOT NULL
66
);

migrations/0003_rawr.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CREATE TABLE IF NOT EXISTS resources (
55
CONSTRAINT link_or_bytes CHECK ((bytes IS NOT NULL AND link_to IS NULL) OR (bytes IS NULL AND link_to IS NOT NULL))
66
);
77

8+
COMMENT ON TABLE resources IS 'RawR resources. Either has the server act as a cdn by directly storing and distributing the resource, or acts as a proxy, returning the link to the actual file.';
9+
810
CREATE TABLE IF NOT EXISTS resource_access_properties (
911
id BIGINT PRIMARY KEY REFERENCES resources (id) ON DELETE CASCADE,
1012
private BOOLEAN NOT NULL,

0 commit comments

Comments
 (0)