moon-miner/tables.sql

105 lines
3.0 KiB
SQL

CREATE TABLE users (
id integer primary key autoincrement,
name varchar(32) not null
);
CREATE TABLE resource(
id integer primary key autoincrement,
name varchar(32) not null unique
);
CREATE TABLE staking_source(
id integer primary key autoincrement,
user_id int not null,
address varchar(128) not null,
created_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_user FOREIGN KEY(user_id)
REFERENCES users(id)
);
CREATE TABLE resource_well(
id integer primary key autoincrement,
source_id int not null,
resource_id int not null,
init_supply int not null,
CONSTRAINT fk_rid FOREIGN KEY(resource_id)
REFERENCES resource(id),
CONSTRAINT fk_sid FOREIGN KEY(source_id)
REFERENCES staking_source(id)
ON DELETE CASCADE
);
CREATE TABLE staking_event(
id integer primary key autoincrement,
well_id int not null,
source_id int not null,
inventory_item_id int not null,
created_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_sid FOREIGN KEY(source_id)
REFERENCES staking_source(id)
CONSTRAINT fk_wid FOREIGN KEY(well_id)
REFERENCES resource_well(id)
CONSTRAINT fk_iiid FOREIGN KEY(inventory_item_id)
REFERENCES inventory_item(id)
);
CREATE TABLE upgrade_event(
id integer primary key autoincrement,
staking_event_id int not null,
created_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_mevent FOREIGN KEY(staking_event_id)
REFERENCES staking_event(id)
);
CREATE TABLE claim_event(
id integer primary key autoincrement,
resource_id int not null,
claim_type text CHECK ( claim_type IN ('BASE','BONUS') ),
claim_amount int not null,
created_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_ures FOREIGN KEY(staking_source_id)
REFERENCES staking_source(id)
);
CREATE TABLE game_config(
id integer primary key autoincrement,
key text not null,
value text not null,
);
"Another Drill Price": 250 Sollux
CREATE TABLE store_item(
id integer primary key autoincrement,
name varchar(128) not null,
currency int not null,
target_resource int not null,
CONSTRAINT fk_rid FOREIGN KEY(currency)
REFERENCES resource(id)
CONSTRAINT fk_targetid FOREIGN KEY(target_resource)
REFERENCES resource(id)
);
CREATE TABLE inventory_item(
id integer primary key autoincrement,
user_id int not null,
store_id int not null,
name varchar(128) not null,
created_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_user FOREIGN KEY(user_id)
REFERENCES users(id)
CONSTRAINT fk_storeid FOREIGN KEY(store_id)
REFERENCES store_item(id)
);
CREATE TABLE bank_account(
id integer primary key autoincrement,
user_id int not null,
resource_id int not null,
balance int not null default 0 CHECK (balance >= 0),
CONSTRAINT fk_user FOREIGN KEY(user_id)
REFERENCES users(id),
CONSTRAINT fk_resource FOREIGN KEY(resource_id)
REFERENCES resource(id)
);