Added auth

This commit is contained in:
Connor Johnstone
2026-03-19 14:02:09 -04:00
parent c6452609d6
commit a9d414bffa
10 changed files with 271 additions and 24 deletions
@@ -0,0 +1,67 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Users::Table)
.if_not_exists()
.col(
ColumnDef::new(Users::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(Users::Username)
.text()
.not_null()
.unique_key(),
)
.col(ColumnDef::new(Users::PasswordHash).text().not_null())
.col(
ColumnDef::new(Users::Role)
.text()
.not_null()
.default("user"),
)
.col(
ColumnDef::new(Users::CreatedAt)
.date_time()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Users::UpdatedAt)
.date_time()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Users::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
pub(crate) enum Users {
Table,
Id,
Username,
PasswordHash,
Role,
CreatedAt,
UpdatedAt,
}
@@ -0,0 +1,45 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(WantedItems::Table)
.add_column(ColumnDef::new(WantedItems::UserId).integer())
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_wanted_items_user_id")
.table(WantedItems::Table)
.col(WantedItems::UserId)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(WantedItems::Table)
.drop_column(WantedItems::UserId)
.to_owned(),
)
.await
}
}
#[derive(DeriveIden)]
enum WantedItems {
Table,
UserId,
}
+4
View File
@@ -9,6 +9,8 @@ mod m20260317_000006_create_search_cache;
mod m20260317_000007_unique_artist_album;
mod m20260317_000009_add_wanted_name;
mod m20260317_000010_add_wanted_mbid;
mod m20260319_000011_create_users;
mod m20260319_000012_add_user_id_to_wanted_items;
pub struct Migrator;
@@ -25,6 +27,8 @@ impl MigratorTrait for Migrator {
Box::new(m20260317_000007_unique_artist_album::Migration),
Box::new(m20260317_000009_add_wanted_name::Migration),
Box::new(m20260317_000010_add_wanted_mbid::Migration),
Box::new(m20260319_000011_create_users::Migration),
Box::new(m20260319_000012_add_user_id_to_wanted_items::Migration),
]
}
}