feat: Add user role entity and integrate with user model, including migration updates and a new Makefile target.

This commit is contained in:
2025-12-18 20:23:03 +05:30
parent 42b567f0ac
commit f9f6871ee5
5 changed files with 62 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ use sea_orm::sea_query::SqliteQueryBuilder;
use crate::config::Config;
use crate::models::bio::{biomarker_entry, biomarker_type};
use crate::models::user::{session, user};
use crate::models::user::{role, session, user};
/// Connect to the SQLite database.
pub async fn connect(config: &Config) -> Result<DatabaseConnection, DbErr> {
@@ -24,9 +24,10 @@ pub async fn connect(config: &Config) -> Result<DatabaseConnection, DbErr> {
pub async fn run_migrations(db: &DatabaseConnection) -> Result<(), DbErr> {
let schema = Schema::new(DbBackend::Sqlite);
// Create table statements
// Create table statements (order matters for foreign keys)
let statements = vec![
schema.create_table_from_entity(user::Entity),
schema.create_table_from_entity(role::Entity), // roles first
schema.create_table_from_entity(user::Entity), // users references roles
schema.create_table_from_entity(session::Entity),
schema.create_table_from_entity(biomarker_type::Entity),
schema.create_table_from_entity(biomarker_entry::Entity),