feat(gear): add filter paper category and optional brew association
- Add migration to extend gear CHECK constraint with 'filter_paper' and add nullable filter_paper_id column to brews - Add FilterPaper variant to GearCategory enum - Add filter_paper_id to Brew, NewBrew, and BrewWithDetails - Add filter_paper_id to TimelineBrewData
This commit is contained in:
parent
4ed1544d66
commit
0b967cbb14
4 changed files with 31 additions and 0 deletions
22
migrations/0011_add_filter_paper.sql
Normal file
22
migrations/0011_add_filter_paper.sql
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
-- Add 'filter_paper' gear category and optional filter_paper_id on brews.
|
||||||
|
--
|
||||||
|
-- SQLite does not support altering CHECK constraints, so we recreate the gear
|
||||||
|
-- table with the updated constraint.
|
||||||
|
|
||||||
|
CREATE TABLE gear_new (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
category TEXT NOT NULL CHECK (category IN ('grinder', 'brewer', 'filter_paper')),
|
||||||
|
make TEXT NOT NULL,
|
||||||
|
model TEXT NOT NULL,
|
||||||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO gear_new (id, category, make, model, created_at, updated_at)
|
||||||
|
SELECT id, category, make, model, created_at, updated_at FROM gear;
|
||||||
|
|
||||||
|
DROP TABLE gear;
|
||||||
|
ALTER TABLE gear_new RENAME TO gear;
|
||||||
|
CREATE INDEX idx_gear_category ON gear(category);
|
||||||
|
|
||||||
|
ALTER TABLE brews ADD COLUMN filter_paper_id INTEGER REFERENCES gear(id) ON DELETE SET NULL;
|
||||||
|
|
@ -12,6 +12,7 @@ pub struct Brew {
|
||||||
pub grinder_id: GearId,
|
pub grinder_id: GearId,
|
||||||
pub grind_setting: f64,
|
pub grind_setting: f64,
|
||||||
pub brewer_id: GearId,
|
pub brewer_id: GearId,
|
||||||
|
pub filter_paper_id: Option<GearId>,
|
||||||
pub water_volume: i32,
|
pub water_volume: i32,
|
||||||
pub water_temp: f64,
|
pub water_temp: f64,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
|
|
@ -28,6 +29,7 @@ pub struct BrewWithDetails {
|
||||||
pub roaster_slug: String,
|
pub roaster_slug: String,
|
||||||
pub grinder_name: String,
|
pub grinder_name: String,
|
||||||
pub brewer_name: String,
|
pub brewer_name: String,
|
||||||
|
pub filter_paper_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|
@ -37,6 +39,7 @@ pub struct NewBrew {
|
||||||
pub grinder_id: GearId,
|
pub grinder_id: GearId,
|
||||||
pub grind_setting: f64,
|
pub grind_setting: f64,
|
||||||
pub brewer_id: GearId,
|
pub brewer_id: GearId,
|
||||||
|
pub filter_paper_id: Option<GearId>,
|
||||||
pub water_volume: i32,
|
pub water_volume: i32,
|
||||||
pub water_temp: f64,
|
pub water_temp: f64,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ use super::listing::{SortDirection, SortKey};
|
||||||
pub enum GearCategory {
|
pub enum GearCategory {
|
||||||
Grinder,
|
Grinder,
|
||||||
Brewer,
|
Brewer,
|
||||||
|
#[serde(rename = "filter_paper")]
|
||||||
|
FilterPaper,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GearCategory {
|
impl GearCategory {
|
||||||
|
|
@ -18,6 +20,7 @@ impl GearCategory {
|
||||||
match self {
|
match self {
|
||||||
GearCategory::Grinder => "grinder",
|
GearCategory::Grinder => "grinder",
|
||||||
GearCategory::Brewer => "brewer",
|
GearCategory::Brewer => "brewer",
|
||||||
|
GearCategory::FilterPaper => "filter_paper",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,6 +28,7 @@ impl GearCategory {
|
||||||
match self {
|
match self {
|
||||||
GearCategory::Grinder => "Grinder",
|
GearCategory::Grinder => "Grinder",
|
||||||
GearCategory::Brewer => "Brewer",
|
GearCategory::Brewer => "Brewer",
|
||||||
|
GearCategory::FilterPaper => "Filter Paper",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,6 +40,7 @@ impl FromStr for GearCategory {
|
||||||
match s.to_lowercase().as_str() {
|
match s.to_lowercase().as_str() {
|
||||||
"grinder" => Ok(GearCategory::Grinder),
|
"grinder" => Ok(GearCategory::Grinder),
|
||||||
"brewer" => Ok(GearCategory::Brewer),
|
"brewer" => Ok(GearCategory::Brewer),
|
||||||
|
"filter_paper" => Ok(GearCategory::FilterPaper),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ pub struct TimelineBrewData {
|
||||||
pub bag_id: i64,
|
pub bag_id: i64,
|
||||||
pub grinder_id: i64,
|
pub grinder_id: i64,
|
||||||
pub brewer_id: i64,
|
pub brewer_id: i64,
|
||||||
|
pub filter_paper_id: Option<i64>,
|
||||||
pub coffee_weight: f64,
|
pub coffee_weight: f64,
|
||||||
pub grind_setting: f64,
|
pub grind_setting: f64,
|
||||||
pub water_volume: i32,
|
pub water_volume: i32,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue