Skip to content

Commit

Permalink
Merge pull request #64 from Jim-Hodapp-Coaching/remove_agreement_status
Browse files Browse the repository at this point in the history
Remove status and status_changed_at fields for Agreements entity model
  • Loading branch information
jhodapp authored Sep 25, 2024
2 parents c6534a6 + a464f44 commit 7b8530d
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 20 deletions.
2 changes: 0 additions & 2 deletions docs/db/refactor_platform_rs.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ Table refactor_platform.agreements {
coaching_session_id uuid [not null]
body varchar [note: 'Either a short or long description of an agreement reached between coach and coachee in a coaching session']
user_id uuid [not null, note: 'User that created (owns) the agreement']
status status [not null]
status_changed_at timestamptz
created_at timestamptz [not null, default: `now()`]
updated_at timestamptz [not null, default: `now()`, note: 'The last date and time an overarching agreement\'s fields were changed']
}
Expand Down
Binary file added docs/db/refactor_platform_rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion entity/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Entity Schema Diagram - Definitions and Relationships

![Untitled (1)](https://github.com/user-attachments/assets/1eea6ba9-b689-4bcb-8b7b-1d9cf725c16c)
![Refactor Platform DB Data Model](../docs/db/refactor_platform_rs.png)


## Example Data - A User as a Coach and Coachee in Two Different Organizations
Expand Down
6 changes: 1 addition & 5 deletions entity/src/agreements.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use crate::{status, Id};
use crate::Id;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
Expand All @@ -18,10 +18,6 @@ pub struct Model {
#[serde(skip_deserializing)]
pub user_id: Id,
#[serde(skip_deserializing)]
pub status: status::Status,
#[serde(skip_deserializing)]
pub status_changed_at: Option<DateTimeWithTimeZone>,
#[serde(skip_deserializing)]
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
pub updated_at: DateTimeWithTimeZone,
Expand Down
11 changes: 2 additions & 9 deletions entity_api/src/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub async fn create(
user_id: Set(user_id),
created_at: Set(now.into()),
updated_at: Set(now.into()),
status_changed_at: Set(None),
..Default::default()
};

Expand All @@ -45,8 +44,6 @@ pub async fn update(db: &DatabaseConnection, id: Id, model: Model) -> Result<Mod
coaching_session_id: Unchanged(agreement.coaching_session_id),
body: Set(model.body),
user_id: Unchanged(agreement.user_id),
status: Unchanged(agreement.status),
status_changed_at: Unchanged(agreement.status_changed_at),
updated_at: Set(chrono::Utc::now().into()),
created_at: Unchanged(agreement.created_at),
};
Expand Down Expand Up @@ -134,8 +131,6 @@ mod tests {
user_id: Id::new_v4(),
coaching_session_id: Id::new_v4(),
body: Some("This is a agreement".to_owned()),
status_changed_at: None,
status: Default::default(),
created_at: now.into(),
updated_at: now.into(),
};
Expand All @@ -160,8 +155,6 @@ mod tests {
coaching_session_id: Id::new_v4(),
body: Some("This is a agreement".to_owned()),
user_id: Id::new_v4(),
status_changed_at: None,
status: Default::default(),
created_at: now.into(),
updated_at: now.into(),
};
Expand Down Expand Up @@ -191,7 +184,7 @@ mod tests {
db.into_transaction_log(),
[Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"SELECT "agreements"."id", "agreements"."coaching_session_id", "agreements"."body", "agreements"."user_id", CAST("agreements"."status" AS text), "agreements"."status_changed_at", "agreements"."created_at", "agreements"."updated_at" FROM "refactor_platform"."agreements" WHERE "agreements"."id" = $1 LIMIT $2"#,
r#"SELECT "agreements"."id", "agreements"."coaching_session_id", "agreements"."body", "agreements"."user_id", "agreements"."created_at", "agreements"."updated_at" FROM "refactor_platform"."agreements" WHERE "agreements"."id" = $1 LIMIT $2"#,
[agreement_id.into(), sea_orm::Value::BigUnsigned(Some(1))]
)]
);
Expand All @@ -217,7 +210,7 @@ mod tests {
db.into_transaction_log(),
[Transaction::from_sql_and_values(
DatabaseBackend::Postgres,
r#"SELECT "agreements"."id", "agreements"."coaching_session_id", "agreements"."body", "agreements"."user_id", CAST("agreements"."status" AS text), "agreements"."status_changed_at", "agreements"."created_at", "agreements"."updated_at" FROM "refactor_platform"."agreements" WHERE "agreements"."coaching_session_id" = $1"#,
r#"SELECT "agreements"."id", "agreements"."coaching_session_id", "agreements"."body", "agreements"."user_id", "agreements"."created_at", "agreements"."updated_at" FROM "refactor_platform"."agreements" WHERE "agreements"."coaching_session_id" = $1"#,
[coaching_session_id.into()]
)]
);
Expand Down
5 changes: 2 additions & 3 deletions migration/src/refactor_platform_rs.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
-- SQL dump generated using DBML (dbml-lang.org)
-- Database: PostgreSQL
-- Generated at: 2024-08-09T18:10:25.658Z
-- Generated at: 2024-09-21T03:25:20.880Z


CREATE TYPE "status" AS ENUM (
'not_started',
'in_progress',
'completed',
'wont_do'
Expand Down Expand Up @@ -73,8 +74,6 @@ CREATE TABLE "refactor_platform"."agreements" (
"coaching_session_id" uuid NOT NULL,
"body" varchar,
"user_id" uuid NOT NULL,
"status" status NOT NULL,
"status_changed_at" timestamptz,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"updated_at" timestamptz NOT NULL DEFAULT (now())
);
Expand Down

0 comments on commit 7b8530d

Please sign in to comment.