mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 07:24:52 +01:00
fix: postgres issues
ids are i64, converted to bigints. color should be stored as signed. This makes migrating from SQLite to postgres kind of painful, but doable.
This commit is contained in:
parent
4466b792fd
commit
adf2812dfc
11 changed files with 38 additions and 33 deletions
|
@ -25,7 +25,7 @@ eframe = { version = "0.19", features = ["persistence"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
sea-orm = { version = "0.10", features = [ "runtime-tokio-rustls", "sqlx-sqlite", "macros" ] }
|
sea-orm = { version = "0.10", features = [ "runtime-tokio-rustls", "sqlx-sqlite", "sqlx-postgres", "macros" ] }
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
|
|
@ -20,4 +20,5 @@ features = [
|
||||||
# e.g.
|
# e.g.
|
||||||
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
||||||
"sqlx-sqlite", # `DATABASE_DRIVER` feature
|
"sqlx-sqlite", # `DATABASE_DRIVER` feature
|
||||||
|
"sqlx-postgres",
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl MigrationTrait for Migration {
|
||||||
.if_not_exists()
|
.if_not_exists()
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(Panels::Id)
|
ColumnDef::new(Panels::Id)
|
||||||
.integer()
|
.big_integer()
|
||||||
.not_null()
|
.not_null()
|
||||||
.auto_increment()
|
.auto_increment()
|
||||||
.primary_key(),
|
.primary_key(),
|
||||||
|
@ -26,6 +26,7 @@ impl MigrationTrait for Migration {
|
||||||
.col(ColumnDef::new(Panels::Position).integer().not_null())
|
.col(ColumnDef::new(Panels::Position).integer().not_null())
|
||||||
.col(ColumnDef::new(Panels::Timeserie).boolean().not_null())
|
.col(ColumnDef::new(Panels::Timeserie).boolean().not_null())
|
||||||
.col(ColumnDef::new(Panels::Height).integer().not_null())
|
.col(ColumnDef::new(Panels::Height).integer().not_null())
|
||||||
|
.col(ColumnDef::new(Panels::Width).integer().not_null())
|
||||||
.col(ColumnDef::new(Panels::ViewScroll).boolean().not_null())
|
.col(ColumnDef::new(Panels::ViewScroll).boolean().not_null())
|
||||||
.col(ColumnDef::new(Panels::LimitView).boolean().not_null())
|
.col(ColumnDef::new(Panels::LimitView).boolean().not_null())
|
||||||
.col(ColumnDef::new(Panels::ViewSize).integer().not_null())
|
.col(ColumnDef::new(Panels::ViewSize).integer().not_null())
|
||||||
|
@ -43,7 +44,7 @@ impl MigrationTrait for Migration {
|
||||||
.if_not_exists()
|
.if_not_exists()
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(Sources::Id)
|
ColumnDef::new(Sources::Id)
|
||||||
.integer()
|
.big_integer()
|
||||||
.not_null()
|
.not_null()
|
||||||
.auto_increment()
|
.auto_increment()
|
||||||
.primary_key(),
|
.primary_key(),
|
||||||
|
@ -62,15 +63,15 @@ impl MigrationTrait for Migration {
|
||||||
.if_not_exists()
|
.if_not_exists()
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(Metrics::Id)
|
ColumnDef::new(Metrics::Id)
|
||||||
.integer()
|
.big_integer()
|
||||||
.not_null()
|
.not_null()
|
||||||
.auto_increment()
|
.auto_increment()
|
||||||
.primary_key(),
|
.primary_key(),
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(Metrics::Name).string().not_null())
|
.col(ColumnDef::new(Metrics::Name).string().not_null())
|
||||||
.col(ColumnDef::new(Metrics::Position).integer().not_null())
|
.col(ColumnDef::new(Metrics::Position).integer().not_null())
|
||||||
.col(ColumnDef::new(Metrics::PanelId).integer().not_null())
|
.col(ColumnDef::new(Metrics::PanelId).big_integer().not_null())
|
||||||
.col(ColumnDef::new(Metrics::SourceId).integer().not_null())
|
.col(ColumnDef::new(Metrics::SourceId).big_integer().not_null())
|
||||||
.col(ColumnDef::new(Metrics::QueryX).string().not_null())
|
.col(ColumnDef::new(Metrics::QueryX).string().not_null())
|
||||||
.col(ColumnDef::new(Metrics::QueryY).string().not_null())
|
.col(ColumnDef::new(Metrics::QueryY).string().not_null())
|
||||||
.col(ColumnDef::new(Metrics::Color).integer().not_null())
|
.col(ColumnDef::new(Metrics::Color).integer().not_null())
|
||||||
|
@ -83,14 +84,14 @@ impl MigrationTrait for Migration {
|
||||||
.if_not_exists()
|
.if_not_exists()
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(Points::Id)
|
ColumnDef::new(Points::Id)
|
||||||
.integer()
|
.big_integer()
|
||||||
.not_null()
|
.not_null()
|
||||||
.auto_increment()
|
.auto_increment()
|
||||||
.primary_key(),
|
.primary_key(),
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(Points::MetricId).integer().not_null())
|
.col(ColumnDef::new(Points::MetricId).big_integer().not_null())
|
||||||
.col(ColumnDef::new(Points::X).float().not_null())
|
.col(ColumnDef::new(Points::X).double().not_null())
|
||||||
.col(ColumnDef::new(Points::Y).float().not_null())
|
.col(ColumnDef::new(Points::Y).double().not_null())
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
).await?;
|
).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -121,6 +122,7 @@ enum Panels {
|
||||||
Position,
|
Position,
|
||||||
Timeserie,
|
Timeserie,
|
||||||
Height,
|
Height,
|
||||||
|
Width,
|
||||||
ViewScroll,
|
ViewScroll,
|
||||||
LimitView,
|
LimitView,
|
||||||
ViewSize,
|
ViewSize,
|
||||||
|
|
|
@ -10,13 +10,13 @@ use crate::data::FetchError;
|
||||||
#[sea_orm(table_name = "metrics")]
|
#[sea_orm(table_name = "metrics")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
pub id: i32,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub source_id: i32,
|
pub source_id: i64,
|
||||||
pub query_x: Option<String>,
|
pub query_x: Option<String>,
|
||||||
pub query_y: String,
|
pub query_y: String,
|
||||||
pub panel_id: i32,
|
pub panel_id: i64,
|
||||||
pub color: u32,
|
pub color: i32,
|
||||||
pub position: i32,
|
pub position: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*;
|
||||||
#[sea_orm(table_name = "panels")]
|
#[sea_orm(table_name = "panels")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key, auto_increment = true)]
|
#[sea_orm(primary_key, auto_increment = true)]
|
||||||
pub id: i32,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub view_scroll: bool,
|
pub view_scroll: bool,
|
||||||
pub view_size: i32,
|
pub view_size: i32,
|
||||||
|
|
|
@ -6,8 +6,8 @@ use eframe::egui::plot::PlotPoint;
|
||||||
#[sea_orm(table_name = "points")]
|
#[sea_orm(table_name = "points")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
pub id: i32,
|
pub id: i64,
|
||||||
pub metric_id: i32,
|
pub metric_id: i64,
|
||||||
pub x: f64,
|
pub x: f64,
|
||||||
pub y: f64,
|
pub y: f64,
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use chrono::Utc;
|
||||||
#[sea_orm(table_name = "sources")]
|
#[sea_orm(table_name = "sources")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
pub id: i32,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::data::entities;
|
||||||
use super::metric::metric_edit_ui;
|
use super::metric::metric_edit_ui;
|
||||||
|
|
||||||
pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
||||||
let mut source_to_put_metric_on : Option<i32> = None;
|
let mut source_to_put_metric_on : Option<i64> = None;
|
||||||
let mut to_swap: Option<usize> = None;
|
let mut to_swap: Option<usize> = None;
|
||||||
let _to_insert: Vec<entities::metrics::Model> = Vec::new();
|
let _to_insert: Vec<entities::metrics::Model> = Vec::new();
|
||||||
// let mut to_delete: Option<usize> = None;
|
// let mut to_delete: Option<usize> = None;
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -49,6 +49,14 @@ struct CliArgs {
|
||||||
log_size: u64,
|
log_size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When compiling for web:
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
fn setup_tracing(_layer: InternalLoggerLayer) {
|
||||||
|
// Make sure panics are logged using `console.error`.
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
// Redirect tracing to console.log and friends:
|
||||||
|
tracing_wasm::set_as_global_default();
|
||||||
|
}
|
||||||
|
|
||||||
// When compiling natively:
|
// When compiling natively:
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
@ -61,15 +69,6 @@ fn setup_tracing(layer: InternalLoggerLayer) {
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// When compiling for web:
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
fn setup_tracing(_layer: InternalLoggerLayer) {
|
|
||||||
// Make sure panics are logged using `console.error`.
|
|
||||||
console_error_panic_hook::set_once();
|
|
||||||
// Redirect tracing to console.log and friends:
|
|
||||||
tracing_wasm::set_as_global_default();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = CliArgs::parse();
|
let args = CliArgs::parse();
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub fn timestamp_to_str(t: i64, date: bool, time: bool) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unpack_color(c: u32) -> Color32 {
|
pub fn unpack_color(c: i32) -> Color32 {
|
||||||
let r: u8 = (c >> 0) as u8;
|
let r: u8 = (c >> 0) as u8;
|
||||||
let g: u8 = (c >> 8) as u8;
|
let g: u8 = (c >> 8) as u8;
|
||||||
let b: u8 = (c >> 16) as u8;
|
let b: u8 = (c >> 16) as u8;
|
||||||
|
@ -92,11 +92,11 @@ pub fn unpack_color(c: u32) -> Color32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn repack_color(c: Color32) -> u32 {
|
pub fn repack_color(c: Color32) -> i32 {
|
||||||
let mut out: u32 = 0;
|
let mut out: i32 = 0;
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
for el in c.to_array() {
|
for el in c.to_array() {
|
||||||
out |= ((el & 0xFF) as u32) << offset;
|
out |= ((el & 0xFF) as i32) << offset;
|
||||||
offset += 8;
|
offset += 8;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use sea_orm::{DatabaseConnection, EntityTrait, Condition, ColumnTrait, QueryFilter, Set};
|
use sea_orm::{DatabaseConnection, EntityTrait, Condition, ColumnTrait, QueryFilter, Set, QueryOrder, Order};
|
||||||
use tokio::sync::{watch, mpsc};
|
use tokio::sync::{watch, mpsc};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
@ -174,6 +174,7 @@ impl AppState {
|
||||||
.add(entities::points::Column::X.gte((now - new_width) as f64))
|
.add(entities::points::Column::X.gte((now - new_width) as f64))
|
||||||
.add(entities::points::Column::X.lte(now as f64))
|
.add(entities::points::Column::X.lte(now as f64))
|
||||||
)
|
)
|
||||||
|
.order_by(entities::points::Column::X, Order::Asc)
|
||||||
.all(&db)
|
.all(&db)
|
||||||
.await.unwrap().into();
|
.await.unwrap().into();
|
||||||
self.tx.points.send(self.points.clone().into()).unwrap();
|
self.tx.points.send(self.points.clone().into()).unwrap();
|
||||||
|
@ -194,6 +195,7 @@ impl AppState {
|
||||||
.add(entities::points::Column::X.gte(now - new_width))
|
.add(entities::points::Column::X.gte(now - new_width))
|
||||||
.add(entities::points::Column::X.lte(now - width))
|
.add(entities::points::Column::X.lte(now - width))
|
||||||
)
|
)
|
||||||
|
.order_by(entities::points::Column::X, Order::Asc)
|
||||||
.all(&db)
|
.all(&db)
|
||||||
.await.unwrap();
|
.await.unwrap();
|
||||||
info!(target: "worker", "Fetched {} previous points", previous_points.len());
|
info!(target: "worker", "Fetched {} previous points", previous_points.len());
|
||||||
|
@ -211,6 +213,7 @@ impl AppState {
|
||||||
.add(entities::points::Column::X.gte(last as f64))
|
.add(entities::points::Column::X.gte(last as f64))
|
||||||
.add(entities::points::Column::X.lte(now as f64))
|
.add(entities::points::Column::X.lte(now as f64))
|
||||||
)
|
)
|
||||||
|
.order_by(entities::points::Column::X, Order::Asc)
|
||||||
.all(&db)
|
.all(&db)
|
||||||
.await.unwrap();
|
.await.unwrap();
|
||||||
info!(target: "worker", "Fetched {} new points", new_points.len());
|
info!(target: "worker", "Fetched {} new points", new_points.len());
|
||||||
|
|
Loading…
Reference in a new issue