Add project fields

This commit is contained in:
Joshua Coles 2024-03-02 16:54:15 +00:00
parent b722b21a75
commit 84b4c747f5
6 changed files with 2536 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target /target
/migration/target
/.idea /.idea
/ignore /ignore

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# Toggl Portal
## Purpose
- Act as an authenticated client for other apps to use to access Toggl data in addition to caching this data for other
data analysis purposes.

2463
migration/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ mod m20231101_172500_create_time_entry_table;
mod m20231106_134950_create_clients; mod m20231106_134950_create_clients;
mod m20231106_195401_create_projects; mod m20231106_195401_create_projects;
mod m20231106_201029_add_time_entry_project_fk; mod m20231106_201029_add_time_entry_project_fk;
mod m20240302_102418_update_project_table;
pub struct Migrator; pub struct Migrator;
@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
Box::new(m20231106_134950_create_clients::Migration), Box::new(m20231106_134950_create_clients::Migration),
Box::new(m20231106_195401_create_projects::Migration), Box::new(m20231106_195401_create_projects::Migration),
Box::new(m20231106_201029_add_time_entry_project_fk::Migration), Box::new(m20231106_201029_add_time_entry_project_fk::Migration),
Box::new(m20240302_102418_update_project_table::Migration),
] ]
} }

View File

@ -0,0 +1,60 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager.alter_table(
TableAlterStatement::new()
.table(Project::Table)
.add_column(ColumnDef::new(Project::Color).text())
.add_column(ColumnDef::new(Project::ServerCreatedAt).timestamp_with_time_zone())
.add_column(ColumnDef::new(Project::ServerUpdatedAt).timestamp_with_time_zone())
.add_column(ColumnDef::new(Project::ServerDeletedAt).timestamp_with_time_zone())
.to_owned()
).await?;
manager.get_connection().execute_unprepared(
r#"
update "project"
set "color" = raw_json ->> 'color',
"server_created_at" = (raw_json ->> 'created_at') :: timestamptz,
"server_updated_at" = (raw_json ->> 'at') :: timestamptz,
"server_deleted_at" = (raw_json ->> 'server_deleted_at') :: timestamptz
"#,
).await?;
manager.alter_table(
TableAlterStatement::new()
.table(Project::Table)
.modify_column(ColumnDef::new(Project::Color).not_null())
.modify_column(ColumnDef::new(Project::ServerCreatedAt).not_null())
.modify_column(ColumnDef::new(Project::ServerUpdatedAt).not_null())
.to_owned()
).await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager.alter_table(
TableAlterStatement::new()
.table(Project::Table)
.drop_column(Project::Color)
.drop_column(Project::ServerCreatedAt)
.drop_column(Project::ServerUpdatedAt)
.drop_column(Project::ServerDeletedAt)
.to_owned()
).await
}
}
#[derive(DeriveIden)]
enum Project {
Table,
Color,
ServerCreatedAt,
ServerUpdatedAt,
ServerDeletedAt,
}

View File

@ -16,6 +16,11 @@ pub struct Model {
pub active: bool, pub active: bool,
#[sea_orm(column_type = "JsonBinary")] #[sea_orm(column_type = "JsonBinary")]
pub raw_json: Json, pub raw_json: Json,
#[sea_orm(column_type = "Text")]
pub color: String,
pub server_created_at: DateTimeWithTimeZone,
pub server_updated_at: DateTimeWithTimeZone,
pub server_deleted_at: Option<DateTimeWithTimeZone>,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]