Merge branch 'main' of https://git.mixel.cloud/Hackathon2024/ApfelNetzwerk
This commit is contained in:
commit
bbcb70d27e
2
.env
2
.env
|
@ -1,2 +1,2 @@
|
||||||
DATABASE_URL=postgres://apfel:apfel@localhost:5432/apfel
|
DATABASE_URL=postgres://apfel:apfel@localhost:5432/apfel
|
||||||
JWT_SECRET_KEY=9b2cbd156a7a7e0e530acd780fdd16e8f37fa3fd8122c74a9b7e1ce6fc67980ed0e55572be4e382679a0c13d13f0a651d15e9e877bb579e957c899eb762b1bb4
|
TOKEN_SECRET=9b2cbd156a7a7e0e530acd780fdd16e8f37fa3fd8122c74a9b7e1ce6fc67980ed0e55572be4e382679a0c13d13f0a651d15e9e877bb579e957c899eb762b1bb4
|
|
@ -2,4 +2,6 @@
|
||||||
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
||||||
|
pub mod node;
|
||||||
|
pub mod node_group;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
36
crates/entity/src/node.rs
Normal file
36
crates/entity/src/node.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||||
|
#[sea_orm(table_name = "node")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub status: bool,
|
||||||
|
#[sea_orm(column_type = "Double")]
|
||||||
|
pub coord_la: f64,
|
||||||
|
#[sea_orm(column_type = "Double")]
|
||||||
|
pub coord_lo: f64,
|
||||||
|
#[sea_orm(column_type = "Float")]
|
||||||
|
pub temperature: f32,
|
||||||
|
#[sea_orm(column_type = "Double")]
|
||||||
|
pub battery: f64,
|
||||||
|
pub uptime: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(has_many = "super::node_group::Entity")]
|
||||||
|
NodeGroup,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::node_group::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::NodeGroup.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
33
crates/entity/src/node_group.rs
Normal file
33
crates/entity/src/node_group.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||||
|
#[sea_orm(table_name = "node_group")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub node: Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::node::Entity",
|
||||||
|
from = "Column::Node",
|
||||||
|
to = "super::node::Column::Id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
Node,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::node::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Node.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -1,3 +1,5 @@
|
||||||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||||
|
|
||||||
|
pub use super::node::Entity as Node;
|
||||||
|
pub use super::node_group::Entity as NodeGroup;
|
||||||
pub use super::user::Entity as User;
|
pub use super::user::Entity as User;
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
pub use sea_orm_migration::prelude::*;
|
pub use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
mod m20241008_091626_create_table_user;
|
mod m20241008_091626_create_table_user;
|
||||||
|
mod m20241008_095058_create_table_node;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![Box::new(m20241008_091626_create_table_user::Migration)]
|
vec![
|
||||||
|
Box::new(m20241008_091626_create_table_user::Migration),
|
||||||
|
Box::new(m20241008_095058_create_table_node::Migration),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
82
crates/migration/src/m20241008_095058_create_table_node.rs
Normal file
82
crates/migration/src/m20241008_095058_create_table_node.rs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
use sea_orm_migration::{prelude::*, schema::*};
|
||||||
|
|
||||||
|
#[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(Node::Table)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(
|
||||||
|
uuid(Node::Id)
|
||||||
|
.extra("DEFAULT gen_random_uuid()")
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(string(Node::Name))
|
||||||
|
.col(boolean(Node::Status))
|
||||||
|
.col(double(Node::CoordLa))
|
||||||
|
.col(double(Node::CoordLo))
|
||||||
|
.col(float(Node::Temperature))
|
||||||
|
.col(double(Node::Battery))
|
||||||
|
.col(big_unsigned(Node::Uptime))
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
manager
|
||||||
|
.create_table(
|
||||||
|
Table::create()
|
||||||
|
.table(NodeGroup::Table)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(
|
||||||
|
uuid(NodeGroup::Id)
|
||||||
|
.extra("DEFAULT gen_random_uuid()")
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(string(NodeGroup::Name))
|
||||||
|
.col(uuid(NodeGroup::Node))
|
||||||
|
.foreign_key(
|
||||||
|
ForeignKey::create()
|
||||||
|
.name("fk-node_id")
|
||||||
|
.from(NodeGroup::Table, NodeGroup::Node)
|
||||||
|
.to(Node::Table, Node::Id)
|
||||||
|
.on_update(ForeignKeyAction::Cascade)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(Node::Table).to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum Node {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
Name, //Default mac address, kann auch geändert werden über die API
|
||||||
|
Status,
|
||||||
|
CoordLa,
|
||||||
|
CoordLo,
|
||||||
|
Temperature,
|
||||||
|
Battery, //Measured in volts
|
||||||
|
Uptime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum NodeGroup {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
Name,
|
||||||
|
Node,
|
||||||
|
}
|
Loading…
Reference in a new issue