Fix navbar

This commit is contained in:
Adrian Woźniak 2023-08-16 16:54:09 +02:00
parent 9a05b64eaf
commit 7069e58f1d
2 changed files with 197 additions and 0 deletions

View File

@ -0,0 +1,103 @@
use sea_orm_migration::prelude::*;
use crate::m20230726_135630_parking_spaces::ParkingSpace;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(ParkingSpaceLocation::ParkingSpaceLocations)
.if_not_exists()
.col(
ColumnDef::new(ParkingSpaceLocation::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(ParkingSpaceLocation::Name)
.string()
.not_null(),
)
.col(
ColumnDef::new(ParkingSpaceLocation::Number)
.integer()
.not_null(),
)
.col(
ColumnDef::new(ParkingSpaceLocation::Stage)
.string()
.not_null(),
)
.col(
ColumnDef::new(ParkingSpaceLocation::CreatedAt)
.timestamp()
.default(SimpleExpr::Custom("NOW()".to_owned()))
.not_null(),
)
.col(
ColumnDef::new(ParkingSpaceLocation::UpdatedAt)
.timestamp()
.default(SimpleExpr::Custom("NOW()".to_owned()))
.not_null(),
)
.if_not_exists()
.to_owned(),
)
.await?;
m.alter_table(
Table::alter()
.table(ParkingSpace::ParkingSpaces)
.drop_column(ParkingSpace::Location)
.to_owned(),
)
.await?;
m.alter_table(
Table::alter()
.table(ParkingSpace::ParkingSpaces)
.add_column(ColumnDef::new(ParkingSpace::LocationId).integer())
.to_owned(),
)
.await?;
m.create_foreign_key(
ForeignKeyCreateStatement::new()
.from_tbl(ParkingSpace::ParkingSpaces)
.from_col(ParkingSpace::LocationId)
.to_tbl(ParkingSpaceLocation::ParkingSpaceLocations)
.to_col(ParkingSpaceLocation::Id)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
m.drop_table(
Table::drop()
.table(ParkingSpaceLocation::ParkingSpaceLocations)
.to_owned(),
)
.await?;
Ok(())
}
}
#[derive(Iden)]
pub enum ParkingSpaceLocation {
ParkingSpaceLocations,
Id,
Name,
Number,
Stage,
CreatedAt,
UpdatedAt,
}

View File

@ -0,0 +1,94 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2
use sea_orm::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"parking_space_locations"
}
}
#[derive(
Clone,
Debug,
PartialEq,
DeriveModel,
DeriveActiveModel,
Eq,
DeriveActixAdmin,
DeriveActixAdminModel,
DeriveActixAdminViewModel,
serde::Serialize,
)]
pub struct Model {
#[actix_admin(primary_key)]
pub id: i32,
pub name: String,
pub number: i32,
pub stage: String,
pub created_at: DateTime,
pub updated_at: DateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
Name,
Number,
Stage,
CreatedAt,
UpdatedAt,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
ParkingSpaces,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::String(None).def(),
Self::Number => ColumnType::Integer.def(),
Self::Stage => ColumnType::String(None).def(),
Self::CreatedAt => ColumnType::DateTime.def(),
Self::UpdatedAt => ColumnType::DateTime.def(),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::ParkingSpaces => Entity::has_many(super::parking_spaces::Entity).into(),
}
}
}
impl Related<super::parking_spaces::Entity> for Entity {
fn to() -> RelationDef {
Relation::ParkingSpaces.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
use actix_admin::prelude::*;
impl ActixAdminModelValidationTrait<ActiveModel> for Entity {}
impl ActixAdminModelFilterTrait<Entity> for Entity {}