From 0f77a16a8cb7b5df9b3f5b16a61f899751f73538 Mon Sep 17 00:00:00 2001 From: Artus Date: Fri, 21 Jun 2019 13:57:36 +0200 Subject: [PATCH] updates table schema --- lootalot_db/db.sqlite3 | Bin 28672 -> 28672 bytes .../2019-06-10-123922_create_items/down.sql | 1 + .../2019-06-10-123922_create_items/up.sql | 10 +++++++ .../2019-06-10-123940_create_players/up.sql | 2 ++ .../2019-06-10-124013_create_looted/down.sql | 1 - .../2019-06-10-124013_create_looted/up.sql | 8 ------ .../2019-06-21-113950_claims/down.sql | 1 + .../2019-06-21-113950_claims/up.sql | 8 ++++++ lootalot_db/src/lib.rs | 18 +++++------- lootalot_db/src/schema.rs | 27 ++++++++++++++---- 10 files changed, 50 insertions(+), 26 deletions(-) delete mode 100644 lootalot_db/migrations/2019-06-10-124013_create_looted/down.sql delete mode 100644 lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql create mode 100644 lootalot_db/migrations/2019-06-21-113950_claims/down.sql create mode 100644 lootalot_db/migrations/2019-06-21-113950_claims/up.sql diff --git a/lootalot_db/db.sqlite3 b/lootalot_db/db.sqlite3 index 62ac4b2a289949daa28bda72bf3fd98390edd99c..41341aa13774383cb49ea2ec9ccaac0c1f78fb19 100644 GIT binary patch delta 507 zcmZp8z}WDBae}lUHviWR#9z z0Xwvr8>|GP8$z;9mgljaoXsmac@LlTknEP7HSiO{PcJ>+VR(u3sKgP)N&pU#>X%XQ3%m`M0-9eA4z$oq-?=TH>Ip|8_}ON=vR-F($7!?L z-+ijL9a!u=@hD#Zg#lKYHPJho6*}#%7j}!+vr^B?aA*hcBALKBINVe$Zj`ibX5c zVc!)Jdf(Nt=$5mL+wG1k92nhj+^V25*!v~`dq{<@3|;8MNB9Xl;_YpCI)ey`5D81t z9oOkJ8Ty^Tqnk4!g&>^}Oh}2>omPw0G)z#K5F$zWVSj^buW=0E8w!apK3(uDB#rF^ zMG8)XJ9cs;iosI=fjq7YTastC%Uci*h@uSpNL=YF><=_!50*o+io7@`pFFB%gd`Oa Z9FryrV8M7}6Jat0O^LHALJ@X9;13V$oq7NO diff --git a/lootalot_db/migrations/2019-06-10-123922_create_items/down.sql b/lootalot_db/migrations/2019-06-10-123922_create_items/down.sql index dfed2b1..d962a59 100644 --- a/lootalot_db/migrations/2019-06-10-123922_create_items/down.sql +++ b/lootalot_db/migrations/2019-06-10-123922_create_items/down.sql @@ -1,2 +1,3 @@ DROP TABLE items; +DROP TABLE looted; diff --git a/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql b/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql index f39d73b..4893561 100644 --- a/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql +++ b/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql @@ -1,5 +1,15 @@ +-- The global inventory of items CREATE TABLE items ( id INTEGER PRIMARY KEY NOT NULL, name VARCHAR NOT NULL, base_price INTEGER NOT NULL ); + +-- The items that have been looted +CREATE TABLE looted ( + id INTEGER PRIMARY KEY NOT NULL, + name VARCHAR NOT NULL, + base_price INTEGER NOT NULL, + owner_id INTEGER NOT NULL, + FOREIGN KEY (owner_id) REFERENCES players(id) +); diff --git a/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql b/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql index 669ddf9..1ee1f3d 100644 --- a/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql +++ b/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql @@ -7,3 +7,5 @@ CREATE TABLE players ( gp INTEGER DEFAULT 0 NOT NULL, pp INTEGER DEFAULT 0 NOT NULL ); + +INSERT INTO players (id, name) VALUES (0, 'Groupe'); diff --git a/lootalot_db/migrations/2019-06-10-124013_create_looted/down.sql b/lootalot_db/migrations/2019-06-10-124013_create_looted/down.sql deleted file mode 100644 index f01e49c..0000000 --- a/lootalot_db/migrations/2019-06-10-124013_create_looted/down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE looted; diff --git a/lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql b/lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql deleted file mode 100644 index 46f2053..0000000 --- a/lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE looted ( - id INTEGER PRIMARY KEY NOT NULL, - player_id INTEGER NOT NULL, - item_id INTEGER NOT NULL, - acquired_date DATE NOT NULL, - FOREIGN KEY (player_id) REFERENCES players(id), - FOREIGN KEY (item_id) REFERENCES items(id) -); diff --git a/lootalot_db/migrations/2019-06-21-113950_claims/down.sql b/lootalot_db/migrations/2019-06-21-113950_claims/down.sql new file mode 100644 index 0000000..67e69d8 --- /dev/null +++ b/lootalot_db/migrations/2019-06-21-113950_claims/down.sql @@ -0,0 +1 @@ +DROP TABLE claims; diff --git a/lootalot_db/migrations/2019-06-21-113950_claims/up.sql b/lootalot_db/migrations/2019-06-21-113950_claims/up.sql new file mode 100644 index 0000000..8ae547c --- /dev/null +++ b/lootalot_db/migrations/2019-06-21-113950_claims/up.sql @@ -0,0 +1,8 @@ +CREATE TABLE claims ( + id INTEGER PRIMARY KEY NOT NULL, + player_id INTEGER NOT NULL, + loot_id INTEGER NOT NULL, + resolve INTEGER NOT NULL DEFAULT 0, + FOREIGN KEY (player_id) REFERENCES players(id), + FOREIGN KEY (loot_id) REFERENCES looted(id) +); diff --git a/lootalot_db/src/lib.rs b/lootalot_db/src/lib.rs index 75c65cb..f243542 100644 --- a/lootalot_db/src/lib.rs +++ b/lootalot_db/src/lib.rs @@ -23,18 +23,14 @@ impl Player { Ok(players.load::(conn)?) } - pub fn fetch_chest(player: i32, conn: &SqliteConnection) -> QueryResult> { - let owned = { - use schema::looted::dsl::*; - looted.filter(player_id.eq(player)).select(item_id).load::(conn)? - }; + pub fn fetch_chest(player_id: i32, conn: &SqliteConnection) -> QueryResult> { + use schema::looted::dsl::*; + let owned = looted + .filter(owner_id.eq(player_id)) + .select((id, name, base_price)) + .load::(conn)?; dbg!(&owned); - let chest = { - use schema::items::dsl::*; - items.filter(id.eq_any(owned)).load::(conn)? - }; - dbg!(&chest); - Ok(chest) + Ok(owned) } } diff --git a/lootalot_db/src/schema.rs b/lootalot_db/src/schema.rs index b7c9058..5e7b23e 100644 --- a/lootalot_db/src/schema.rs +++ b/lootalot_db/src/schema.rs @@ -1,3 +1,12 @@ +table! { + claims (id) { + id -> Integer, + player_id -> Integer, + loot_id -> Integer, + resolve -> Integer, + } +} + table! { items (id) { id -> Integer, @@ -9,9 +18,9 @@ table! { table! { looted (id) { id -> Integer, - player_id -> Integer, - item_id -> Integer, - acquired_date -> Date, + name -> Text, + base_price -> Integer, + owner_id -> Integer, } } @@ -27,7 +36,13 @@ table! { } } -joinable!(looted -> items (item_id)); -joinable!(looted -> players (player_id)); +joinable!(claims -> looted (loot_id)); +joinable!(claims -> players (player_id)); +joinable!(looted -> players (owner_id)); -allow_tables_to_appear_in_same_query!(items, looted, players,); +allow_tables_to_appear_in_same_query!( + claims, + items, + looted, + players, +);