CREATE TABLE IF NOT EXISTS limits (
    id varchar PRIMARY KEY NOT NULL,
    current_asset_count integer NOT NULL,
    max_asset_count integer NOT NULL
);

CREATE TABLE IF NOT EXISTS users (
    id varchar PRIMARY KEY NOT NULL,
    created_at timestamp NOT NULL,
    last_connected_at timestamp NOT NULL,
    email varchar NOT NULL,
    password varchar NOT NULL,
    name varchar NOT NULL,
    limits varchar NOT NULL,
    assets varchar NOT NULL,
    FOREIGN KEY (limits) REFERENCES limits (id)
);

CREATE TABLE IF NOT EXISTS session_keys (
    key varchar PRIMARY KEY NOT NULL,
    user_id varchar NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users (id)
);

CREATE TABLE IF NOT EXISTS heirs (
    id varchar PRIMARY KEY NOT NULL,
    user_id varchar NOT NULL,
    created_at timestamp NOT NULL,
    name varchar NOT NULL,
    email varchar,
    FOREIGN KEY (user_id) REFERENCES users (id)
);

CREATE TABLE IF NOT EXISTS entries (
    id varchar PRIMARY KEY NOT NULL,
    user_id varchar NOT NULL,
    created_at timestamp NOT NULL,
    feelings text NOT NULL,
    assets text NOT NULL,
    title text,
    description text,
    kind varchar NOT NULL,
    music_entry varchar,
    location_entry varchar,
    date_entry varchar,
    FOREIGN KEY (user_id) REFERENCES users (id),
    FOREIGN KEY (music_entry) REFERENCES music_entries (id),
    FOREIGN KEY (location_entry) REFERENCES location_entries (id),
    FOREIGN KEY (date_entry) REFERENCES date_entries (id)
);

CREATE TABLE IF NOT EXISTS music_entries (
    id varchar PRIMARY KEY NOT NULL,
    artist varchar NOT NULL,
    title varchar NOT NULL,
    links text NOT NULL,
    universal_ids text NOT NULL
);

CREATE TABLE IF NOT EXISTS location_entries (
    id varchar PRIMARY KEY NOT NULL,
    location_text text,
    location_coordinates varchar
);

CREATE TABLE IF NOT EXISTS date_entries (
    id varchar PRIMARY KEY NOT NULL,
    referenced_date timestamp NOT NULL
);