Add new tables, add automatic data cleanup with configurable duration, move company business logic into seperate folder
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use diesel::MysqlConnection as DbConnection;
|
||||
pub use diesel::MysqlConnection as DbConnection;
|
||||
pub use diesel::mysql::Mysql as DbBackend;
|
||||
use diesel::prelude::*;
|
||||
use diesel_migrations::{EmbeddedMigrations, MigrationHarness, embed_migrations};
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#![allow(dead_code)]
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Debug, Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::antennas)]
|
||||
#[diesel(check_for_backend(diesel::mysql::Mysql))]
|
||||
pub struct Antenna {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub ip: String,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::antennas)]
|
||||
pub struct NewAntenna {
|
||||
pub name: String,
|
||||
pub ip: String,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::client_readings)]
|
||||
#[diesel(check_for_backend(diesel::mysql::Mysql))]
|
||||
pub struct ClientReading {
|
||||
pub id: i64,
|
||||
pub ip: String,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub read_at: NaiveDateTime,
|
||||
pub tx_ccq: i32,
|
||||
pub rx_ccq: i32,
|
||||
pub radio_name: String,
|
||||
pub tx_rate: String,
|
||||
pub rx_rate: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::client_readings)]
|
||||
pub struct NewClientReading {
|
||||
pub ip: String,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub tx_ccq: i32,
|
||||
pub rx_ccq: i32,
|
||||
pub radio_name: String,
|
||||
pub tx_rate: String,
|
||||
pub rx_rate: String,
|
||||
}
|
||||
20
src/db/models/antenna.rs
Normal file
20
src/db/models/antenna.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
#![allow(dead_code)]
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Debug, Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::antennas)]
|
||||
#[diesel(check_for_backend(crate::db::DbBackend))]
|
||||
pub struct Antenna {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub ip: String,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::antennas)]
|
||||
pub struct NewAntenna {
|
||||
pub name: String,
|
||||
pub ip: String,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
83
src/db/models/client_readings.rs
Normal file
83
src/db/models/client_readings.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
#![allow(dead_code)]
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::prelude::*;
|
||||
|
||||
use crate::db::models::NewClientStatisticWithTime;
|
||||
|
||||
#[derive(Debug, Clone, Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::client_readings)]
|
||||
#[diesel(check_for_backend(crate::db::DbBackend))]
|
||||
pub struct ClientReading {
|
||||
pub id: i64,
|
||||
pub ip: Option<String>,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub read_at: NaiveDateTime,
|
||||
pub tx_ccq: Option<i32>,
|
||||
pub rx_ccq: Option<i32>,
|
||||
pub radio_name: Option<String>,
|
||||
pub tx_rate: Option<String>,
|
||||
pub rx_rate: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::client_readings)]
|
||||
pub struct NewClientReading {
|
||||
pub ip: Option<String>,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub tx_ccq: Option<i32>,
|
||||
pub rx_ccq: Option<i32>,
|
||||
pub radio_name: Option<String>,
|
||||
pub tx_rate: Option<String>,
|
||||
pub rx_rate: Option<String>,
|
||||
}
|
||||
#[derive(Debug, Clone, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::client_readings)]
|
||||
pub struct NewClientReadingTimed {
|
||||
pub ip: Option<String>,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub read_at: NaiveDateTime,
|
||||
pub tx_ccq: Option<i32>,
|
||||
pub rx_ccq: Option<i32>,
|
||||
pub radio_name: Option<String>,
|
||||
pub tx_rate: Option<String>,
|
||||
pub rx_rate: Option<String>,
|
||||
}
|
||||
|
||||
impl Into<NewClientReading> for NewClientReadingTimed {
|
||||
fn into(self) -> NewClientReading {
|
||||
NewClientReading {
|
||||
ip: self.ip,
|
||||
mac: self.mac,
|
||||
antenna_ip: self.antenna_ip,
|
||||
db_reading: self.db_reading,
|
||||
tx_ccq: self.tx_ccq,
|
||||
rx_ccq: self.rx_ccq,
|
||||
radio_name: self.radio_name,
|
||||
tx_rate: self.tx_rate,
|
||||
rx_rate: self.rx_rate,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<NewClientStatisticWithTime> for NewClientReadingTimed {
|
||||
fn into(self) -> NewClientStatisticWithTime {
|
||||
NewClientStatisticWithTime {
|
||||
ip: self.ip,
|
||||
mac: self.mac,
|
||||
antenna_ip: self.antenna_ip,
|
||||
db_reading: self.db_reading,
|
||||
read_at: self.read_at,
|
||||
tx_ccq: self.tx_ccq,
|
||||
rx_ccq: self.rx_ccq,
|
||||
radio_name: self.radio_name,
|
||||
tx_rate: self.tx_rate,
|
||||
rx_rate: self.rx_rate,
|
||||
}
|
||||
}
|
||||
}
|
||||
49
src/db/models/client_statistics.rs
Normal file
49
src/db/models/client_statistics.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
#![allow(dead_code)]
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::client_statistics)]
|
||||
#[diesel(check_for_backend(crate::db::DbBackend))]
|
||||
pub struct ClientStatistics {
|
||||
pub id: i64,
|
||||
pub ip: Option<String>,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub read_at: NaiveDateTime,
|
||||
pub tx_ccq: Option<i32>,
|
||||
pub rx_ccq: Option<i32>,
|
||||
pub radio_name: Option<String>,
|
||||
pub tx_rate: Option<String>,
|
||||
pub rx_rate: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::client_statistics)]
|
||||
pub struct NewClientStatistic {
|
||||
pub ip: Option<String>,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub tx_ccq: Option<i32>,
|
||||
pub rx_ccq: Option<i32>,
|
||||
pub radio_name: Option<String>,
|
||||
pub tx_rate: Option<String>,
|
||||
pub rx_rate: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::client_statistics)]
|
||||
pub struct NewClientStatisticWithTime {
|
||||
pub ip: Option<String>,
|
||||
pub mac: String,
|
||||
pub antenna_ip: String,
|
||||
pub db_reading: i32,
|
||||
pub read_at: NaiveDateTime,
|
||||
pub tx_ccq: Option<i32>,
|
||||
pub rx_ccq: Option<i32>,
|
||||
pub radio_name: Option<String>,
|
||||
pub tx_rate: Option<String>,
|
||||
pub rx_rate: Option<String>,
|
||||
}
|
||||
9
src/db/models/mod.rs
Normal file
9
src/db/models/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
mod antenna;
|
||||
mod client_readings;
|
||||
mod client_statistics;
|
||||
mod wara;
|
||||
|
||||
pub use antenna::*;
|
||||
pub use client_readings::*;
|
||||
pub use client_statistics::*;
|
||||
pub use wara::*;
|
||||
18
src/db/models/wara.rs
Normal file
18
src/db/models/wara.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
#![allow(dead_code)]
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Debug, Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::wara)]
|
||||
#[diesel(check_for_backend(crate::db::DbBackend))]
|
||||
pub struct Wara {
|
||||
pub id: i64,
|
||||
|
||||
pub last_client_reading_cleanup: Option<NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Insertable)]
|
||||
#[diesel(table_name = crate::db::schema::wara)]
|
||||
pub struct NewWara {
|
||||
pub last_client_reading_cleanup: Option<NaiveDateTime>,
|
||||
}
|
||||
@@ -1,28 +1,65 @@
|
||||
// Written manually because diesel cant fucking read the db properly for some reason
|
||||
// @generated automatically by Diesel CLI.
|
||||
|
||||
diesel::table! {
|
||||
antennas (id) {
|
||||
id -> Int8,
|
||||
id -> Bigint,
|
||||
name -> Text,
|
||||
ip -> Text,
|
||||
#[max_length = 15]
|
||||
ip -> Varchar,
|
||||
error -> Nullable<Text>,
|
||||
last_error_t -> Nullable<Timestamp>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
client_readings (id) {
|
||||
id -> Int8,
|
||||
ip -> Text,
|
||||
mac -> Text,
|
||||
antenna_ip -> Text,
|
||||
db_reading -> Int4,
|
||||
id -> Bigint,
|
||||
#[max_length = 15]
|
||||
ip -> Nullable<Varchar>,
|
||||
#[max_length = 17]
|
||||
mac -> Varchar,
|
||||
#[max_length = 15]
|
||||
antenna_ip -> Varchar,
|
||||
read_at -> Timestamp,
|
||||
tx_ccq -> Int4,
|
||||
rx_ccq -> Int4,
|
||||
radio_name -> Varchar,
|
||||
tx_rate -> Varchar,
|
||||
rx_rate -> Varchar,
|
||||
db_reading -> Integer,
|
||||
tx_ccq -> Nullable<Integer>,
|
||||
rx_ccq -> Nullable<Integer>,
|
||||
#[max_length = 255]
|
||||
radio_name -> Nullable<Varchar>,
|
||||
#[max_length = 50]
|
||||
tx_rate -> Nullable<Varchar>,
|
||||
#[max_length = 50]
|
||||
rx_rate -> Nullable<Varchar>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::allow_tables_to_appear_in_same_query!(antennas, client_readings,);
|
||||
diesel::table! {
|
||||
client_statistics (id) {
|
||||
id -> Bigint,
|
||||
#[max_length = 15]
|
||||
ip -> Nullable<Varchar>,
|
||||
#[max_length = 17]
|
||||
mac -> Varchar,
|
||||
#[max_length = 15]
|
||||
antenna_ip -> Varchar,
|
||||
read_at -> Timestamp,
|
||||
db_reading -> Integer,
|
||||
tx_ccq -> Nullable<Integer>,
|
||||
rx_ccq -> Nullable<Integer>,
|
||||
#[max_length = 255]
|
||||
radio_name -> Nullable<Varchar>,
|
||||
#[max_length = 50]
|
||||
tx_rate -> Nullable<Varchar>,
|
||||
#[max_length = 50]
|
||||
rx_rate -> Nullable<Varchar>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
wara (id) {
|
||||
id -> Bigint,
|
||||
last_client_reading_cleanup -> Nullable<Timestamp>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::allow_tables_to_appear_in_same_query!(antennas, client_readings, client_statistics, wara,);
|
||||
|
||||
Reference in New Issue
Block a user