|
| 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 | + |
0 commit comments