CREATE TABLE IF NOT EXISTS "xp"
(
    user_id BIGINT NOT NULL REFERENCES userinfo(user_id) PRIMARY KEY,
    user_current_level INTEGER NOT NULL DEFAULT 0,
    xp_value BIGINT NOT NULL DEFAULT 0,
    last_given_xp BIGINT,
    rank_track INTEGER NOT NULL,
    rank_track_last_changed BIGINT,
    freeze_rank BIGINT,
    freeze_rank_last_changed BIGINT
);

CREATE TABLE IF NOT EXISTS "tracks"
(
    track_id INTEGER NOT NULL PRIMARY KEY,
    track_name VARCHAR(128) NOT NULL
);

CREATE TABLE IF NOT EXISTS "ranks"
(
    role_id BIGINT NOT NULL PRIMARY KEY,
    required_level INTEGER NOT NULL DEFAULT 1,
    rank_track INTEGER NOT NULL DEFAULT 0,
    rank_name VARCHAR(128) NOT NULL
);

INSERT INTO "tracks" (track_id, track_name) VALUES
    (0, 'officer'),
    (1, 'enlisted');

INSERT INTO "ranks" (role_id, required_level, rank_track, rank_name) VALUES
    (1154403063960961063, 0, 0, 'cadet first year'), -- cadet 1
    (1154403107313307729, 5, 0, 'cadet fourth year'), -- cadet 4
    (1152963553620393995, 10, 0, 'ensign'), -- ensign
    (1152963552299188224, 20, 0, 'lieutenant junior grade'), -- ltjg
    (1152963550906695762, 30, 0, 'lieutenant'), -- lt
    (1152963549979758712, 40, 0, 'lieutenant commander'), -- ltcmdr
    (1152963548843094126, 50, 0, 'commander'), -- cmdr
    (1152963541255594054, 75, 0, 'captain'), -- capt
    (1152759044893843656, 100, 0, 'fleet captain'), -- fleetcapt
    (1152965025938550926, 0, 1, 'crewman third class'), -- crewman 3rd
    (1152965024550228099, 5, 1, 'crewman second class'), -- crewman 2nd
    (1152965023098994789, 10, 1, 'crewman first class'), -- crewman 1st
    (1152964462844846162, 20, 1, 'petty officer third class'), -- petty 3rd
    (1152964461817253958, 30, 1, 'petty officer second class'), -- petty 2nd
    (1152964460835778631, 40, 1, 'petty officer first class'), -- petty 1st
    (1152963559010087022, 50, 1, 'chief petty officer'), -- chief petty
    (1152963557537886229, 75, 1, 'senior chief petty officer'), -- sr ch petty
    (1152963556527063110, 100, 1, 'master chief petty officer'); -- master ch petty
