Skip to content

Commit 74645f8

Browse files
authored
Add NTE roll/pull tracker API and marker screenshot URLs (#83)
* Add NTE tracker API and marker screenshot URLs * Fix tracker test-only atomic imports * Harden marker comment screenshot URL validation * Relax tracker pull enum constraints * Relax tracker pull constraints in original migration
1 parent 4d12ce2 commit 74645f8

9 files changed

Lines changed: 2053 additions & 14 deletions
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
CREATE TABLE ntehelper_tracker_uid_claim (
2+
uid bigint PRIMARY KEY,
3+
owner_user_id bigint NOT NULL,
4+
claim_source text NOT NULL,
5+
claimed_at timestamptz NOT NULL DEFAULT now(),
6+
updated_at timestamptz NOT NULL DEFAULT now(),
7+
CONSTRAINT ntehelper_tracker_uid_claim_owner_user_id_fkey FOREIGN KEY (owner_user_id) REFERENCES users (id) ON DELETE CASCADE,
8+
CONSTRAINT ntehelper_tracker_uid_claim_uid_check CHECK (uid BETWEEN 100000 AND 999999999999),
9+
CONSTRAINT ntehelper_tracker_uid_claim_source_check CHECK (claim_source IN ('self', 'admin'))
10+
);
11+
12+
CREATE UNIQUE INDEX ntehelper_tracker_uid_claim_self_owner_idx
13+
ON ntehelper_tracker_uid_claim (owner_user_id)
14+
WHERE claim_source = 'self';
15+
16+
CREATE INDEX ntehelper_tracker_uid_claim_owner_idx
17+
ON ntehelper_tracker_uid_claim (owner_user_id, claimed_at DESC);
18+
19+
CREATE TABLE ntehelper_tracker_pull (
20+
uid bigint NOT NULL,
21+
record_uid text NOT NULL,
22+
pool_group_id text NOT NULL,
23+
banner_type text NOT NULL,
24+
timestamp_raw text NOT NULL,
25+
timestamp_group_ordinal integer,
26+
roll_result integer,
27+
result_type text,
28+
reward_type text NOT NULL,
29+
reward_id text NOT NULL,
30+
reward_name text NOT NULL,
31+
reward_rank text,
32+
star_rank integer,
33+
quantity integer,
34+
imported_at timestamptz NOT NULL DEFAULT now(),
35+
PRIMARY KEY (uid, record_uid),
36+
CONSTRAINT ntehelper_tracker_pull_uid_fkey FOREIGN KEY (uid) REFERENCES ntehelper_tracker_uid_claim (uid) ON DELETE CASCADE,
37+
CONSTRAINT ntehelper_tracker_pull_record_uid_check CHECK (
38+
char_length(btrim(record_uid)) BETWEEN 1 AND 128
39+
AND btrim(record_uid) !~ '[^A-Za-z0-9_.:-]'
40+
),
41+
CONSTRAINT ntehelper_tracker_pull_timestamp_raw_check CHECK (timestamp_raw ~ '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$'),
42+
CONSTRAINT ntehelper_tracker_pull_timestamp_group_ordinal_check CHECK (timestamp_group_ordinal IS NULL OR timestamp_group_ordinal >= 0),
43+
CONSTRAINT ntehelper_tracker_pull_roll_result_check CHECK (roll_result IS NULL OR roll_result >= 0),
44+
CONSTRAINT ntehelper_tracker_pull_result_type_check CHECK (result_type IS NULL OR char_length(btrim(result_type)) BETWEEN 1 AND 64),
45+
CONSTRAINT ntehelper_tracker_pull_reward_type_check CHECK (char_length(btrim(reward_type)) BETWEEN 1 AND 64),
46+
CONSTRAINT ntehelper_tracker_pull_reward_id_check CHECK (char_length(btrim(reward_id)) BETWEEN 1 AND 128),
47+
CONSTRAINT ntehelper_tracker_pull_reward_name_check CHECK (char_length(btrim(reward_name)) BETWEEN 1 AND 128),
48+
CONSTRAINT ntehelper_tracker_pull_star_rank_check CHECK (star_rank IS NULL OR star_rank IN (3, 4, 5)),
49+
CONSTRAINT ntehelper_tracker_pull_quantity_check CHECK (quantity IS NULL OR quantity >= 0)
50+
);
51+
52+
CREATE INDEX ntehelper_tracker_pull_uid_timestamp_idx
53+
ON ntehelper_tracker_pull (uid, timestamp_raw DESC);
54+
55+
CREATE INDEX ntehelper_tracker_pull_uid_banner_timestamp_idx
56+
ON ntehelper_tracker_pull (uid, banner_type, timestamp_raw DESC);
57+
58+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ALTER TABLE ntehelper_tracker_uid_claim
2+
DROP CONSTRAINT ntehelper_tracker_uid_claim_owner_user_id_fkey;
3+
4+
ALTER TABLE ntehelper_tracker_uid_claim
5+
ALTER COLUMN owner_user_id DROP NOT NULL;
6+
7+
ALTER TABLE ntehelper_tracker_uid_claim
8+
ADD CONSTRAINT ntehelper_tracker_uid_claim_owner_user_id_fkey
9+
FOREIGN KEY (owner_user_id) REFERENCES users (id) ON DELETE SET NULL;
10+
11+
DROP INDEX ntehelper_tracker_uid_claim_self_owner_idx;
12+
13+
CREATE INDEX ntehelper_tracker_uid_claim_self_owner_idx
14+
ON ntehelper_tracker_uid_claim (owner_user_id)
15+
WHERE claim_source = 'self';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE ntehelper_tracker_uid_claim
2+
ADD COLUMN nickname text NOT NULL DEFAULT '';
3+
4+
ALTER TABLE ntehelper_tracker_uid_claim
5+
ADD CONSTRAINT ntehelper_tracker_uid_claim_nickname_check CHECK (
6+
char_length(btrim(nickname)) <= 24
7+
AND btrim(nickname) !~ '[[:cntrl:]]'
8+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE ntehelper_marker_comment
2+
ADD COLUMN screenshot_urls jsonb NOT NULL DEFAULT '[]'::jsonb;
3+
4+
ALTER TABLE ntehelper_marker_comment
5+
ADD CONSTRAINT ntehelper_marker_comment_screenshot_urls_check CHECK (
6+
jsonb_typeof(screenshot_urls) = 'array'
7+
AND jsonb_array_length(screenshot_urls) <= 4
8+
);

0 commit comments

Comments
 (0)