Compare commits

..

5 Commits

48 changed files with 572 additions and 340 deletions

4
.gitignore vendored
View File

@ -1,4 +1,2 @@
/target /target
package-lock.json /persmgr_derive/target
node_modules/
build/

105
Cargo.lock generated
View File

@ -83,7 +83,7 @@ dependencies = [
"rustc-hash", "rustc-hash",
"serde", "serde",
"serde_derive", "serde_derive",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -122,7 +122,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -209,7 +209,7 @@ checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -416,6 +416,41 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn 1.0.109",
]
[[package]]
name = "darling_macro"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "der" name = "der"
version = "0.7.10" version = "0.7.10"
@ -457,7 +492,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -617,7 +652,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -941,6 +976,12 @@ dependencies = [
"zerovec", "zerovec",
] ]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "1.1.0" version = "1.1.0"
@ -1284,6 +1325,7 @@ dependencies = [
"axum", "axum",
"base64", "base64",
"cfg-if", "cfg-if",
"persmgr_derive",
"pulldown-cmark", "pulldown-cmark",
"rand 0.9.2", "rand 0.9.2",
"serde", "serde",
@ -1301,6 +1343,16 @@ dependencies = [
"tracing-subscriber", "tracing-subscriber",
] ]
[[package]]
name = "persmgr_derive"
version = "0.1.0"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.16" version = "0.2.16"
@ -1542,7 +1594,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -1745,7 +1797,7 @@ dependencies = [
"quote", "quote",
"sqlx-core", "sqlx-core",
"sqlx-macros-core", "sqlx-macros-core",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -1768,7 +1820,7 @@ dependencies = [
"sqlx-mysql", "sqlx-mysql",
"sqlx-postgres", "sqlx-postgres",
"sqlx-sqlite", "sqlx-sqlite",
"syn", "syn 2.0.106",
"tokio", "tokio",
"url", "url",
] ]
@ -1893,12 +1945,29 @@ dependencies = [
"unicode-properties", "unicode-properties",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.6.1" version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.106" version = "2.0.106"
@ -1924,7 +1993,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -1944,7 +2013,7 @@ checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -2039,7 +2108,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -2269,7 +2338,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -2442,7 +2511,7 @@ dependencies = [
"log", "log",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2464,7 +2533,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2677,7 +2746,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
"synstructure", "synstructure",
] ]
@ -2698,7 +2767,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]
@ -2718,7 +2787,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
"synstructure", "synstructure",
] ]
@ -2758,7 +2827,7 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.106",
] ]
[[package]] [[package]]

View File

@ -4,6 +4,8 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
persmgr_derive.path="./persmgr_derive"
anyhow = "1.0.99" anyhow = "1.0.99"
argon2 = { version = "0.5.3", features = ["simple", "std"] } argon2 = { version = "0.5.3", features = ["simple", "std"] }
askama = "0.14.0" askama = "0.14.0"

View File

@ -1,3 +0,0 @@
-- Add down migration script here
DROP TABLE IF EXISTS users;

View File

@ -1,13 +0,0 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS users (
id BIGSERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
verified_email BOOLEAN NOT NULL,
username TEXT NOT NULL UNIQUE,
pw_hash TEXT NOT NULL,
pw_salt TEXT NOT NULL,
pfp_id BIGINT NOT NULL,
rank_id BIGINT NOT NULL
);

View File

@ -1,3 +0,0 @@
-- Add down migration script here
DROP TABLE IF EXISTS sessions;

View File

@ -1,8 +0,0 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS sessions (
user_id BIGINT NOT NULL,
session_key TEXT NOT NULL UNIQUE,
expires BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
)

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS ranks;

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS ranks (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS awards;

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS awards (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS trainings;

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS trainings (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS missions;

View File

@ -1,9 +0,0 @@
CREATE TABLE IF NOT EXISTS missions (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
starting_at BIGINT NOT NULL,
estimated_length BIGINT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS qualifications;

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS qualifications (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS record_ranks;

View File

@ -1,11 +0,0 @@
CREATE TABLE IF NOT EXISTS records_ranks (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
rank_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_rank FOREIGN KEY (rank_id) REFERENCES ranks(id) ON DELETE CASCADE
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS record_awards;

View File

@ -1,11 +0,0 @@
CREATE TABLE IF NOT EXISTS records_awards (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
award_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_award FOREIGN KEY (award_id) REFERENCES awards(id) ON DELETE CASCADE
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS record_training;

View File

@ -1,11 +0,0 @@
CREATE TABLE IF NOT EXISTS records_trainings (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
training_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_training FOREIGN KEY (training_id) REFERENCES trainings(id) ON DELETE CASCADE
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS record_qualifications;

View File

@ -1,11 +0,0 @@
CREATE TABLE IF NOT EXISTS records_qualifications (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
qualification_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_qualification FOREIGN KEY (qualification_id) REFERENCES qualifications(id) ON DELETE CASCADE
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS records_missions;

View File

@ -1,11 +0,0 @@
CREATE TABLE IF NOT EXISTS records_missions (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
mission_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_mission FOREIGN KEY (mission_id) REFERENCES missions(id) ON DELETE CASCADE
);

View File

@ -1 +0,0 @@
DROP TABLE IF EXISTS attendance;

View File

@ -1,10 +0,0 @@
CREATE TABLE IF NOT EXISTS attendance (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
mission_id BIGINT NOT NULL,
confirmed_at BIGINT NOT NULL,
attending BOOL NOT NULL,
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_mission FOREIGN KEY (mission_id) REFERENCES missions(id) ON DELETE CASCADE
);

View File

@ -0,0 +1,14 @@
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS sessions;
DROP TABLE IF EXISTS ranks;
DROP TABLE IF EXISTS awards;
DROP TABLE IF EXISTS trainings;
DROP TABLE IF EXISTS missions;
DROP TABLE IF EXISTS qualifications;
DROP TABLE IF EXISTS record_ranks;
DROP TABLE IF EXISTS record_awards;
DROP TABLE IF EXISTS record_training;
DROP TABLE IF EXISTS record_qualifications;
DROP TABLE IF EXISTS records_missions;
DROP TABLE IF EXISTS attendance;
DROP TABLE IF EXISTS roster_groups;

View File

@ -0,0 +1,148 @@
CREATE TABLE IF NOT EXISTS users (
id BIGSERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
verified_email BOOLEAN NOT NULL,
username TEXT NOT NULL UNIQUE,
pw_hash TEXT NOT NULL,
pw_salt TEXT NOT NULL,
pfp_id BIGINT NOT NULL,
rank_id BIGINT NOT NULL,
group_id BIGINT NOT NULL
-- NOTE: Constraint added later to deal with circular dependency
-- CONSTRAINT fk_group FOREIGN KEY (group_id) REFERENCES roster_group(id)
-- CONSTRAINT fk_rank FOREIGN KEY (rank_id) REFERENCES ranks(id)
);
CREATE TABLE IF NOT EXISTS sessions (
id BIGSERIAL NOT NULL PRIMARY KEY,
user_id BIGINT NOT NULL,
session_key TEXT NOT NULL UNIQUE,
expires BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS ranks (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS awards (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS trainings (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS missions (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
starting_at BIGINT NOT NULL,
estimated_length BIGINT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS qualifications (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS attendance (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
mission_id BIGINT NOT NULL,
confirmed_at BIGINT NOT NULL,
attending BOOL NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_mission FOREIGN KEY(mission_id) REFERENCES missions(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS roster_groups (
id BIGSERIAL NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
sort_order BIGINT NOT NULL,
manager_id BIGINT NOT NULL,
CONSTRAINT fk_manager FOREIGN KEY(manager_id) REFERENCES users(id) ON DELETE SET NULL
);
-- NOTE: For table 'users'
ALTER TABLE users ADD FOREIGN KEY (group_id) REFERENCES roster_groups(id) ON DELETE SET NULL;
ALTER TABLE users ADD FOREIGN KEY (rank_id) REFERENCES ranks(id) ON DELETE SET NULL;
--------------------
-- NOTE: Records
--------------------
CREATE TABLE IF NOT EXISTS records_ranks (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
rank_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_rank FOREIGN KEY (rank_id) REFERENCES ranks(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS records_awards (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
award_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_award FOREIGN KEY (award_id) REFERENCES awards(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS records_trainings (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
training_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_training FOREIGN KEY (training_id) REFERENCES trainings(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS records_qualifications (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
qualification_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_qualification FOREIGN KEY (qualification_id) REFERENCES qualifications(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS records_missions (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
mission_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_mission FOREIGN KEY (mission_id) REFERENCES missions(id) ON DELETE CASCADE
);

101
persmgr_derive/Cargo.lock generated Normal file
View File

@ -0,0 +1,101 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "persmgr_derive"
version = "0.1.0"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"

13
persmgr_derive/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "persmgr_derive"
version = "0.1.0"
edition = "2024"
[lib]
proc-macro = true
[dependencies]
quote = "1"
proc-macro2 = "1"
syn = { version = "1", features = ["full"] }
darling = "0.13"

109
persmgr_derive/src/lib.rs Normal file
View File

@ -0,0 +1,109 @@
use darling::FromDeriveInput;
use proc_macro::{self, TokenStream};
use quote::quote;
use syn::{Data, DeriveInput, Expr, Fields, Type, parse_macro_input};
#[derive(FromDeriveInput, Default)]
#[darling(default, attributes(meta))]
struct Opts {
table: String,
key_t: Option<Expr>,
}
#[proc_macro_derive(TableMeta, attributes(meta))]
pub fn derive_table_meta(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input);
let opts = Opts::from_derive_input(&input)
.expect("Expected attribute #[meta(table=\"users\", key_t=i32)]");
let mut struct_items = Vec::new();
if let Data::Struct(data) = &input.data {
if let Fields::Named(fields) = &data.fields {
for field in &fields.named {
let ident = field.ident.as_ref().unwrap();
let s = ident.to_string();
if s.as_str() == "id" || s.as_str() == "created_at" {
continue;
}
let mut should_deref = false;
if let Type::Path(tp) = &field.ty {
if tp.path.segments.first().unwrap().ident == "ForeignKey" {
should_deref = true;
}
}
struct_items.push((ident, should_deref));
}
}
}
let ident = input.ident;
let table_name = opts.table;
let key_t = opts
.key_t
.unwrap_or_else(|| syn::parse_str::<Expr>("i64").unwrap());
// dbg!(&table_name);
//dbg!(&key_t);
let mut query = format!("UPDATE {table_name} SET ");
let mut query_args = quote!(self.id);
let mut i = 2;
let mut modified_update = false;
for (item, should_deref) in &struct_items {
let s = item.to_string();
//dbg!(&s);
if s.as_str() == "modified_at" {
modified_update = true;
}
if i != 2 {
query.push_str(", ");
}
query.push_str(s.as_str());
query.push_str(&format!(" = ${i} "));
i += 1;
let deref = if *should_deref { quote!(*) } else { quote!() };
query_args = quote! {
#query_args, #deref self.#item
};
}
query.push_str("WHERE id = $1 RETURNING *");
let mut modified_at = quote! {};
if modified_update {
modified_at = quote! {
self.modified_at = time::OffsetDateTime::now_utc().unix_timestamp();
}
}
let output = quote! {
impl TableMeta for #ident {
type PrimaryKey = #key_t;
const TABLE: &'static str = #table_name;
}
impl #ident {
pub async fn update(&mut self, pool: &crate::db::CurrPool) -> anyhow::Result<Self> {
#modified_at
let session = sqlx::query_as!(
#ident,
#query,
#query_args
)
.fetch_one(pool)
.await?;
Ok(session)
}
}
};
eprintln!("{}", output.to_string());
output.into()
}

View File

@ -1,9 +1,11 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{CurrPool, tables::TableMeta}; use crate::db::{CurrPool, tables::TableMeta};
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "awards")]
pub struct Award { pub struct Award {
pub id: i64, pub id: i64,
pub name: String, pub name: String,
@ -12,11 +14,6 @@ pub struct Award {
pub modified_at: i64, pub modified_at: i64,
} }
impl TableMeta for Award {
type PrimaryKey = i64;
const TABLE: &'static str = "awards";
}
impl Award { impl Award {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(
@ -42,25 +39,4 @@ impl Award {
.await?; .await?;
Ok(session) Ok(session)
} }
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
let session = sqlx::query_as!(
Award,
r#"
UPDATE awards SET
name = $2,
description = $3,
modified_at = $4
WHERE id = $1
RETURNING *
"#,
self.id,
self.name,
self.description,
curr_time
)
.fetch_one(pool)
.await?;
Ok(session)
}
} }

View File

@ -1,9 +1,11 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{CurrPool, tables::TableMeta}; use crate::db::{CurrPool, tables::TableMeta};
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "missions")]
pub struct Mission { pub struct Mission {
pub id: i64, pub id: i64,
pub name: String, pub name: String,
@ -14,11 +16,6 @@ pub struct Mission {
pub modified_at: i64, pub modified_at: i64,
} }
impl TableMeta for Mission {
type PrimaryKey = i64;
const TABLE: &'static str = "missions";
}
impl Mission { impl Mission {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(
@ -44,25 +41,4 @@ impl Mission {
.await?; .await?;
Ok(session) Ok(session)
} }
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
let session = sqlx::query_as!(
Mission,
r#"
UPDATE missions SET
name = $2,
description = $3,
modified_at = $4
WHERE id = $1
RETURNING *
"#,
self.id,
self.name,
self.description,
curr_time
)
.fetch_one(pool)
.await?;
Ok(session)
}
} }

View File

@ -1,9 +1,11 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{CurrPool, tables::TableMeta}; use crate::db::{CurrPool, tables::TableMeta};
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "qualifications")]
pub struct Qualification { pub struct Qualification {
pub id: i64, pub id: i64,
pub name: String, pub name: String,
@ -12,11 +14,6 @@ pub struct Qualification {
pub modified_at: i64, pub modified_at: i64,
} }
impl TableMeta for Qualification {
type PrimaryKey = i64;
const TABLE: &'static str = "qualifications";
}
impl Qualification { impl Qualification {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(
@ -46,25 +43,4 @@ impl Qualification {
.await?; .await?;
Ok(session) Ok(session)
} }
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
let session = sqlx::query_as!(
Qualification,
r#"
UPDATE qualifications SET
name = $2,
description = $3,
modified_at = $4
WHERE id = $1
RETURNING *
"#,
self.id,
self.name,
self.description,
curr_time
)
.fetch_one(pool)
.await?;
Ok(session)
}
} }

View File

@ -1,9 +1,11 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{CurrPool, tables::TableMeta}; use crate::db::{CurrPool, tables::TableMeta};
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "ranks")]
pub struct Rank { pub struct Rank {
pub id: i64, pub id: i64,
pub name: String, pub name: String,
@ -12,11 +14,6 @@ pub struct Rank {
pub modified_at: i64, pub modified_at: i64,
} }
impl TableMeta for Rank {
type PrimaryKey = i64;
const TABLE: &'static str = "ranks";
}
impl Rank { impl Rank {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(
@ -42,25 +39,4 @@ impl Rank {
.await?; .await?;
Ok(session) Ok(session)
} }
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
let session = sqlx::query_as!(
Rank,
r#"
UPDATE ranks SET
name = $2,
description = $3,
modified_at = $4
WHERE id = $1
RETURNING *
"#,
self.id,
self.name,
self.description,
curr_time
)
.fetch_one(pool)
.await?;
Ok(session)
}
} }

View File

@ -1,9 +1,11 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{CurrPool, tables::TableMeta}; use crate::db::{CurrPool, tables::TableMeta};
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "trainings")]
pub struct Training { pub struct Training {
pub id: i64, pub id: i64,
pub name: String, pub name: String,
@ -12,11 +14,6 @@ pub struct Training {
pub modified_at: i64, pub modified_at: i64,
} }
impl TableMeta for Training {
type PrimaryKey = i64;
const TABLE: &'static str = "trainings";
}
impl Training { impl Training {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(
@ -42,25 +39,4 @@ impl Training {
.await?; .await?;
Ok(session) Ok(session)
} }
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
let session = sqlx::query_as!(
Training,
r#"
UPDATE trainings SET
name = $2,
description = $3,
modified_at = $4
WHERE id = $1
RETURNING *
"#,
self.id,
self.name,
self.description,
curr_time
)
.fetch_one(pool)
.await?;
Ok(session)
}
} }

53
src/db/tables/groups.rs Normal file
View File

@ -0,0 +1,53 @@
use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow;
use crate::db::{
CurrPool,
tables::{ForeignKey, TableMeta, assignables::missions::Mission, user::User},
};
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "roster_groups")]
pub struct Groups {
pub id: i64,
pub name: String,
pub manager_id: ForeignKey<User>,
pub sort_order: i64,
}
impl Groups {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!(
Groups,
r#"
INSERT INTO roster_groups (name, manager_id, sort_order)
VALUES ($1, $2, $3)
RETURNING *
"#,
self.name,
*self.manager_id,
self.sort_order,
)
.fetch_one(pool)
.await?;
Ok(session)
}
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
let session = sqlx::query_as!(Groups, "SELECT * FROM roster_groups WHERE id = $1", id)
.fetch_one(pool)
.await?;
Ok(session)
}
pub async fn get_by_manager_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
let session = sqlx::query_as!(
Groups,
"SELECT * FROM roster_groups WHERE manager_id = $1",
id
)
.fetch_all(pool)
.await?;
Ok(session)
}
}

View File

@ -8,6 +8,7 @@ use sqlx::{Decode, Encode, QueryBuilder, Type, postgres::PgRow};
pub mod assignables; pub mod assignables;
pub mod attendance; pub mod attendance;
pub mod groups;
pub mod records; pub mod records;
pub mod sessions; pub mod sessions;
pub mod user; pub mod user;

View File

@ -1,4 +1,5 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{ use crate::db::{
@ -6,7 +7,8 @@ use crate::db::{
tables::{ForeignKey, TableMeta, assignables::awards::Award, user::User}, tables::{ForeignKey, TableMeta, assignables::awards::Award, user::User},
}; };
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "records_awards")]
pub struct AwardRecord { pub struct AwardRecord {
pub id: i64, pub id: i64,
pub user_id: ForeignKey<User>, pub user_id: ForeignKey<User>,
@ -15,11 +17,6 @@ pub struct AwardRecord {
pub created_at: i64, pub created_at: i64,
} }
impl TableMeta for AwardRecord {
type PrimaryKey = i64;
const TABLE: &'static str = "records_awards";
}
impl AwardRecord { impl AwardRecord {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(

View File

@ -1,4 +1,5 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{ use crate::db::{
@ -6,7 +7,8 @@ use crate::db::{
tables::{ForeignKey, TableMeta, assignables::missions::Mission, user::User}, tables::{ForeignKey, TableMeta, assignables::missions::Mission, user::User},
}; };
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "records_missions")]
pub struct MissionRecord { pub struct MissionRecord {
pub id: i64, pub id: i64,
pub user_id: ForeignKey<User>, pub user_id: ForeignKey<User>,
@ -15,11 +17,6 @@ pub struct MissionRecord {
pub created_at: i64, pub created_at: i64,
} }
impl TableMeta for MissionRecord {
type PrimaryKey = i64;
const TABLE: &'static str = "records_missions";
}
impl MissionRecord { impl MissionRecord {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(

View File

@ -1,4 +1,5 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{ use crate::db::{
@ -6,7 +7,8 @@ use crate::db::{
tables::{ForeignKey, TableMeta, assignables::qualifications::Qualification, user::User}, tables::{ForeignKey, TableMeta, assignables::qualifications::Qualification, user::User},
}; };
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "records_qualifications")]
pub struct QualificationRecord { pub struct QualificationRecord {
pub id: i64, pub id: i64,
pub user_id: ForeignKey<User>, pub user_id: ForeignKey<User>,
@ -15,11 +17,6 @@ pub struct QualificationRecord {
pub created_at: i64, pub created_at: i64,
} }
impl TableMeta for QualificationRecord {
type PrimaryKey = i64;
const TABLE: &'static str = "records_qualifications";
}
impl QualificationRecord { impl QualificationRecord {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(

View File

@ -1,4 +1,5 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{ use crate::db::{
@ -6,7 +7,8 @@ use crate::db::{
tables::{ForeignKey, TableMeta, assignables::ranks::Rank, user::User}, tables::{ForeignKey, TableMeta, assignables::ranks::Rank, user::User},
}; };
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "records_ranks")]
pub struct RankRecord { pub struct RankRecord {
pub id: i64, pub id: i64,
pub user_id: ForeignKey<User>, pub user_id: ForeignKey<User>,
@ -15,11 +17,6 @@ pub struct RankRecord {
pub created_at: i64, pub created_at: i64,
} }
impl TableMeta for RankRecord {
type PrimaryKey = i64;
const TABLE: &'static str = "records_ranks";
}
impl RankRecord { impl RankRecord {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(

View File

@ -1,4 +1,5 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{ use crate::db::{
@ -6,7 +7,8 @@ use crate::db::{
tables::{ForeignKey, TableMeta, assignables::trainings::Training, user::User}, tables::{ForeignKey, TableMeta, assignables::trainings::Training, user::User},
}; };
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "records_trainings")]
pub struct TrainingRecord { pub struct TrainingRecord {
pub id: i64, pub id: i64,
pub user_id: ForeignKey<User>, pub user_id: ForeignKey<User>,
@ -15,11 +17,6 @@ pub struct TrainingRecord {
pub created_at: i64, pub created_at: i64,
} }
impl TableMeta for TrainingRecord {
type PrimaryKey = i64;
const TABLE: &'static str = "records_trainings";
}
impl TrainingRecord { impl TrainingRecord {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(

View File

@ -1,20 +1,18 @@
use anyhow::Result; use anyhow::Result;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{CurrPool, tables::TableMeta}; use crate::db::{CurrPool, tables::TableMeta};
#[derive(Debug, Default, Clone, FromRow)] #[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "sessions")]
pub struct Session { pub struct Session {
pub id: i64,
pub user_id: i64, pub user_id: i64,
pub session_key: String, pub session_key: String,
pub expires: i64, pub expires: i64,
} }
impl TableMeta for Session {
type PrimaryKey = i64;
const TABLE: &'static str = "sessions";
}
impl Session { impl Session {
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> { pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
let session = sqlx::query_as!( let session = sqlx::query_as!(

View File

@ -1,8 +1,13 @@
use anyhow::bail; use anyhow::bail;
use persmgr_derive::TableMeta;
use sqlx::prelude::FromRow; use sqlx::prelude::FromRow;
use crate::db::{CurrPool, tables::TableMeta}; use crate::db::{
#[derive(Debug, Default, Clone, FromRow)] CurrPool,
tables::{ForeignKey, TableMeta, assignables::ranks::Rank, groups::Groups},
};
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
#[meta(table = "users")]
pub struct User { pub struct User {
pub id: i64, pub id: i64,
pub email: String, pub email: String,
@ -11,12 +16,8 @@ pub struct User {
pub pw_hash: String, pub pw_hash: String,
pub pw_salt: String, pub pw_salt: String,
pub pfp_id: i64, pub pfp_id: i64,
pub rank_id: i64, pub rank_id: ForeignKey<Rank>,
} pub group_id: ForeignKey<Groups>,
impl TableMeta for User {
type PrimaryKey = i64;
const TABLE: &'static str = "users";
} }
impl User { impl User {