feat: got migrations working!!!!

This commit is contained in:
silver 2024-03-03 00:18:46 +00:00
parent 480fc9b1a0
commit a9f55da04d
4 changed files with 45 additions and 52 deletions

View file

@ -269,59 +269,11 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
)
.await?;
sqlx::query(
"CREATE TABLE IF NOT EXISTS wolves (
id_wolves integer PRIMARY KEY,
email text not null,
discord integer,
minecraft text
)",
)
.execute(&pool)
.await?;
sqlx::query("CREATE INDEX IF NOT EXISTS index_discord ON wolves (discord)").execute(&pool).await?;
sqlx::query(
"CREATE TABLE IF NOT EXISTS wolves_verify (
discord integer PRIMARY KEY,
email text not null,
auth_code text not null,
date_expiry text not null
)",
)
.execute(&pool)
.await?;
sqlx::query("CREATE INDEX IF NOT EXISTS index_date_expiry ON wolves_verify (date_expiry)")
.execute(&pool)
// migrations are amazing!
sqlx::migrate!("./db/migrations")
.run(&pool)
.await?;
sqlx::query(
"CREATE TABLE IF NOT EXISTS server_members (
server integer not null,
id_wolves integer not null,
expiry text not null,
PRIMARY KEY(server,id_wolves),
FOREIGN KEY (id_wolves) REFERENCES wolves (id_wolves)
)",
)
.execute(&pool)
.await?;
sqlx::query(
"CREATE TABLE IF NOT EXISTS servers (
server integer PRIMARY KEY,
wolves_api text not null,
role_past integer,
role_current integer,
member_past integer DEFAULT 0,
member_current integer DEFAULT 0
)",
)
.execute(&pool)
.await?;
Ok(pool)
}