Skip to content

Commit

Permalink
Denormalize database schema for easier usage of enums
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Apr 2, 2024
1 parent 909348f commit ad25fc7
Show file tree
Hide file tree
Showing 40 changed files with 218 additions and 1,033 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pace_error = { workspace = true }
pace_time = { workspace = true }
parking_lot = { workspace = true, features = ["deadlock_detection"] }
rayon = { workspace = true }
sea-orm = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
Expand Down
21 changes: 14 additions & 7 deletions crates/core/src/domain/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pace_time::{
date_time::PaceDateTime,
duration::{calculate_duration, duration_to_str, PaceDuration},
};
use strum::EnumIter;
use sea_orm::DeriveActiveEnum;

use serde_derive::{Deserialize, Serialize};
use std::fmt::Display;
Expand Down Expand Up @@ -84,28 +84,35 @@ impl From<(ActivityGuid, Activity)> for ActivityItem {
PartialOrd,
Ord,
EnumString,
EnumIter,
sea_orm::EnumIter,
strum::Display,
DeriveActiveEnum,
)]
#[serde(rename_all = "kebab-case")]
#[strum(serialize_all = "kebab-case")]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
// #[serde(untagged)]
pub enum ActivityKind {
/// A generic activity
#[default]
#[sea_orm(num_value = 0)]
Activity,

/// A task
Task,

/// A break
#[sea_orm(num_value = 1)]
Intermission,

/// A pomodoro break
#[sea_orm(num_value = 2)]
PomodoroIntermission,

/// A pomodoro work session
#[sea_orm(num_value = 3)]
PomodoroWork,

/// A pomodoro break
PomodoroIntermission,
/// A task
#[sea_orm(num_value = 4)]
Task,
}

#[allow(clippy::trivially_copy_pass_by_ref)]
Expand Down
17 changes: 14 additions & 3 deletions crates/core/src/domain/status.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use sea_orm::DeriveActiveEnum;
use serde_derive::{Deserialize, Serialize};
use strum::{EnumIter, EnumString};
use strum::EnumString;

#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -29,37 +30,47 @@ pub enum TaskStatus {
PartialOrd,
Ord,
EnumString,
EnumIter,
sea_orm::EnumIter,
strum::Display,
DeriveActiveEnum,
)]
#[serde(rename_all = "kebab-case")]
#[strum(serialize_all = "kebab-case")]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
pub enum ActivityStatusKind {
/// The initial state of an activity once it's created in the system but not yet started.
#[default]
#[sea_orm(num_value = 0)]
Created,

/// The activity is scheduled to start at a specific time.
/// It remains in this state until the activity begins.
#[sea_orm(num_value = 1)]
Scheduled,

/// The active state of an activity. It transitions to this state from "Scheduled" when
/// the activity begins or from "Paused" when it's resumed. The start time is recorded
/// upon entering this state for the first time, and the resume time is noted for
/// subsequent entries.
#[sea_orm(num_value = 2)]
InProgress,

/// Represents an activity that has been temporarily halted.
/// This could apply to tasks being paused for a break or intermission.
/// The activity can move back to "InProgress" when work on it resumes.
#[sea_orm(num_value = 3)]
Paused,

/// The final state of an activity, indicating it has been finished.
/// The end time of the activity is recorded, marking its completion.
#[sea_orm(num_value = 4)]
Completed,

#[sea_orm(num_value = 98)]
Unarchived,

#[sea_orm(num_value = 99)]
Archived,
Unarchived, // TODO: Do we need this or can be unarchiving done without it?
}

#[allow(clippy::trivially_copy_pass_by_ref)]
Expand Down
172 changes: 0 additions & 172 deletions crates/storage/src/entities.rs

This file was deleted.

61 changes: 0 additions & 61 deletions crates/storage/src/entities/activities.rs

This file was deleted.

Loading

0 comments on commit ad25fc7

Please sign in to comment.