Add tables to store job information

Signed-off-by: trivernis <trivernis@protonmail.com>
feature/jobs
trivernis 2 years ago
parent e5cabd4e9b
commit 8b342f6aac
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -0,0 +1,14 @@
CREATE TABLE jobs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
job_type INTEGER NOT NULL,
name VARCHAR(255),
next_run DATETIME,
interval INTEGER
);
CREATE TABLE job_states (
job_id INTEGER FOREIGN KEY REFERENCES jobs (id),
key VARCHAR(128) NOT NULL DEFAULT 'default',
value BLOB,
PRIMARY KEY (job_id, key)
);

@ -0,0 +1,42 @@
use chrono::NaiveDateTime;
use sea_orm::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "namespaces")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub job_type: JobType,
pub name: Option<String>,
pub next_run: Option<NaiveDateTime>,
pub interval: Option<i64>,
}
#[derive(Clone, Debug, PartialEq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "u32", db_type = "Integer")]
pub enum JobType {
#[sea_orm(num_value = 10)]
MigrateCDs,
#[sea_orm(num_value = 20)]
CalculateSizes,
#[sea_orm(num_value = 30)]
GenerateThumbs,
#[sea_orm(num_value = 40)]
CheckIntegrity,
#[sea_orm(num_value = 50)]
Vacuum,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::job_state::Entity")]
JobState,
}
impl Related<super::job_state::Entity> for Entity {
fn to() -> RelationDef {
Relation::JobState.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -0,0 +1,29 @@
use sea_orm::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "namespaces")]
pub struct Model {
#[sea_orm(primary_key)]
pub job_id: i64,
#[sea_orm(primary_key)]
pub key: String,
pub value: Vec<u8>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::job::Entity",
from = "Column::JobId",
to = "super::job::Column::Id"
)]
Job,
}
impl Related<super::job::Entity> for Entity {
fn to() -> RelationDef {
Relation::Job.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

@ -3,6 +3,8 @@ pub mod content_descriptor_source;
pub mod content_descriptor_tag;
pub mod file;
pub mod file_metadata;
pub mod job;
pub mod job_state;
pub mod namespace;
pub mod sort_key;
pub mod sorting_preset;

Loading…
Cancel
Save