CREATE TABLE chr
(
    id                     serial                  NOT NULL,
    account                integer                 NOT NULL,
    world                  integer                 NOT NULL,
    name                   varchar(12)             NOT NULL,
    level                  smallint                NOT NULL,
    exp                    integer                 NOT NULL,
    str                    smallint                NOT NULL,
    dex                    smallint                NOT NULL,
    "int"                  smallint                NOT NULL,
    luk                    smallint                NOT NULL,
    hp                     smallint                NOT NULL,
    mp                     smallint                NOT NULL,
    max_hp                 smallint                NOT NULL,
    max_mp                 smallint                NOT NULL,
    ap                     smallint                NOT NULL,
    sp                     smallint                NOT NULL,
    job                    smallint                NOT NULL,
    fame                   smallint                NOT NULL,
    gender                 smallint                NOT NULL,
    skin                   smallint                NOT NULL,
    hair                   integer                 NOT NULL,
    face                   integer                 NOT NULL,
    meso                   integer   DEFAULT 0     NOT NULL,
    map_id                 integer                 NOT NULL,
    spawn_portal           smallint                NOT NULL,
    gacha_exp              integer                 NOT NULL,
    used_hp_mp_ap          integer                 NOT NULL,
    gm_level               smallint                NOT NULL,
    party_id               integer,
    buddy_capacity         smallint                NOT NULL,
    "rank"                 integer,
    rank_move              integer,
    job_rank               integer,
    job_rank_move          integer,
    guild_id               integer,
    guild_rank             smallint,
    alliance_rank          smallint,
    messenger_id           integer,
    messenger_position     smallint,
    mount_level            smallint,
    mount_exp              integer,
    mount_tiredness        smallint,
    omok_wins              integer   DEFAULT 0     NOT NULL,
    omok_losses            integer   DEFAULT 0     NOT NULL,
    omok_ties              integer   DEFAULT 0     NOT NULL,
    matchcard_wins         integer   DEFAULT 0     NOT NULL,
    matchcard_losses       integer   DEFAULT 0     NOT NULL,
    matchcard_ties         integer   DEFAULT 0     NOT NULL,
    merchant_mesos         integer   DEFAULT 0     NOT NULL,
    has_merchant           boolean   DEFAULT false NOT NULL,
    equip_slots            smallint                NOT NULL,
    use_slots              smallint                NOT NULL,
    setup_slots            smallint                NOT NULL,
    etc_slots              smallint                NOT NULL,
    family_id              integer,
    partner_id             integer,
    marriage_item_id       integer,
    monster_book_cover     integer,
    dojo_tutorial_complete boolean   DEFAULT false NOT NULL,
    dojo_points            integer   DEFAULT 0     NOT NULL,
    dojo_last_stage        integer,
    dojo_vanquisher_stage  integer,
    dojo_vanquisher_kills  integer   DEFAULT 0     NOT NULL,
    ariant_points          integer   DEFAULT 0     NOT NULL,
    data_string            text,
    party_search           boolean   DEFAULT false NOT NULL,
    last_logout            timestamp,
    last_exp_gain          timestamp,
    jail_expire            timestamp,
    created_at             timestamp DEFAULT now() NOT NULL,
    updated_at             timestamp DEFAULT now() NOT NULL,
    UNIQUE (name),
    PRIMARY KEY (id),
    FOREIGN KEY (account) REFERENCES account (id) ON DELETE RESTRICT
);
CREATE UNIQUE INDEX lower_character_name_idx ON chr (lower(name) );
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE chr TO ${server-username};
GRANT USAGE ON SEQUENCE chr_id_seq TO ${server-username};
