From bdf58a624fd9f1051a93ec16bba76bc393dd99fa Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 20 Feb 2023 12:49:24 +0700 Subject: [PATCH] Fix some SQL --- data.sql | 25 +++++++++++++++---------- tables.sql | 7 +++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/data.sql b/data.sql index d979ed9..bb22ca8 100644 --- a/data.sql +++ b/data.sql @@ -1,9 +1,9 @@ INSERT INTO resource(name) VALUES - ('NEBULANCE'), + ('SOLLUX'), ('SHADOWSTONE'), ('AZURIUM'), ('NOVAFOR'), - ('SOLLUX'); + ('NEBULANCE'); INSERT INTO users(name) VALUES ('Joe'), @@ -14,20 +14,25 @@ INSERT INTO users(name) VALUES INSERT INTO bank_account(user_id, resource_id, balance) VALUES - (1, 1, 0), + (1, 1, 200), (1, 2, 175), - (1, 3, 200), + (1, 3, 0), (1, 4, 25), (1, 5, 10); INSERT INTO store_item(name, currency, target_resource, price, claim_amount) VALUES - ('Drill 1A', 1, 1, 100, 500), - ('Drill 1B', 2, 2, 100, 500), - ('Drill 1C', 3, 3, 100, 500), - ('Drill 1D', 4, 4, 100, 500), - ('Drill 1E', 5, 5, 100, 500); - + ('Drill 1A', 1, 1, 25, 500), + ('Drill 1B', 1, 2, 25, 500), + ('Drill 1C', 1, 3, 25, 500), + ('Drill 1D', 1, 4, 25, 500), + ('Drill 1E', 1, 5, 25, 500); +SELECT staking_event.id,well_id,staking_event.source_id, + inventory_item_id,staking_event.created_at,expiration_at +FROM staking_event +INNER JOIN resource_well ON resource_well.id = well_id +INNER JOIN staking_source on staking_event.source_id = staking_source.id +WHERE staking_event.source_id = ? AND staking_source.user_id = ?; SELECT name,init_supply FROM resource_well diff --git a/tables.sql b/tables.sql index 7d0d6ef..10f41fa 100644 --- a/tables.sql +++ b/tables.sql @@ -36,8 +36,8 @@ CREATE TABLE staking_event( well_id int not null, source_id int not null, inventory_item_id int not null, - amount int not null, created_at timestamp DEFAULT (current_timestamp), + expiration_at timestamp DEFAULT (current_timestamp), CONSTRAINT fk_sid FOREIGN KEY(source_id) REFERENCES staking_source(id) CONSTRAINT fk_wid FOREIGN KEY(well_id) @@ -49,11 +49,10 @@ CREATE TABLE staking_event( 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) + CONSTRAINT fk_rid FOREIGN KEY(resource_id) + REFERENCES resource(id) ); CREATE TABLE upgrade_event(