feat: nailing down teh format

This commit is contained in:
silver 2023-09-16 18:02:15 +01:00
parent 974173857c
commit 670a85d2ef
2 changed files with 47 additions and 20 deletions

View file

@ -105,7 +105,8 @@ fn str_to_num<T: FromStr + Default>(x: &str) -> T {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Accounts {
pub server: GuildId,
pub wolves_id: String,
pub id_wolves: String,
pub id_member: String,
pub email: String,
pub expiry: String,
pub discord: Option<String>,
@ -119,7 +120,8 @@ impl<'r> FromRow<'r, SqliteRow> for Accounts {
Ok(Self {
server,
wolves_id: row.try_get("wolves_api")?,
id_wolves: row.try_get("id_wolves")?,
id_member: row.try_get("id_member")?,
email: row.try_get("email")?,
expiry: row.try_get("expiry")?,
discord: row.try_get("discord")?,
@ -178,19 +180,20 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
sqlx::query(
"CREATE TABLE IF NOT EXISTS accounts (
server integer not null,
wolves_id text not null,
id_wolves text DEFAULT '',
id_member text DEFAULT '',
email text not null,
expiry text not null,
discord text,
minecraft text,
CONSTRAINT con_server_wolves PRIMARY KEY(server,wolves_id)
PRIMARY KEY(server,id_wolves,id_member)
)",
)
.execute(&pool)
.await?;
sqlx::query("CREATE INDEX IF NOT EXISTS index_server ON accounts (server)").execute(&pool).await?;
sqlx::query("CREATE INDEX IF NOT EXISTS index_wolves_id ON accounts (wolves_id)")
sqlx::query("CREATE INDEX IF NOT EXISTS index_id_wolves ON accounts (id_wolves)")
.execute(&pool)
.await?;