CREATE TABLE users (
    id serial not null primary key,
    name varchar(32) not null,
);

CREATE TABLE resource(
    id serial not null primary key,
    name varchar(32) not null,
);

INSERT INTO resource(name) VALUES
    ('NEBULANCE'),
    ('SHADOWSTONE'),
    ('AZURIUM'),
    ('NOVAFOR'),
    ('SOLLUX');

CREATE TABLE staking_source(
    id serial not null primary key,
    user_id int not null,
    CONSTRAINT fk_user FOREIGN KEY(user_id)
        REFERENCES users(id),
);

CREATE TABLE resource_well(
    id serial not null primary key,
    staking_source_id int not null,
    resource_id int not null,
    init_supply int not null default 0,
    CONSTRAINT fk_resource FOREIGN KEY(resource_id)
        REFERENCES resource(id),
    CONSTRAINT fk_ssource FOREIGN KEY(staking_source_id)
        REFERENCES staking_source(id),
);

CREATE TABLE staking_event(
    id serial primary key not null,
    staking_source_id int not null,
    created_at timestamp without time zone default (now() at time zone 'utc'),
    CONSTRAINT fk_ures FOREIGN KEY(staking_source_id)
        REFERENCES staking_source(id),
);

CREATE TABLE upgrade_event(
    id serial primary key not null,
    staking_event_id int not null,
    created_at timestamp without time zone default (now() at time zone 'utc'),
    CONSTRAINT fk_mevent FOREIGN KEY(staking_event_id)
        REFERENCES staking_event(id),
);

CREATE TABLE claim_event(
    id serial not null primary key,
    staking_source_id int not null,
    created_at timestamp without time zone default (now() at time zone 'utc'),
    CONSTRAINT fk_ures FOREIGN KEY(staking_source_id)
        REFERENCES staking_source(id),
);
