Skip to content

Commit

Permalink
rename entity idens
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Mar 29, 2024
1 parent 826fc83 commit d2340a0
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 111 deletions.
10 changes: 3 additions & 7 deletions crates/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,8 @@ pub enum DatabaseStorageErrorKind {
/// This database engine is currently not supported: {0}
UnsupportedDatabaseEngine(String),

/// Activity with id {guid} not found: {source}
ActivityNotFound {
guid: String,
#[source]
source: sea_orm::error::SqlErr,
},
/// Activity with id {guid} not found
ActivityNotFound { guid: String },

/// Failed to create activity: {0}
ActivityCreationFailed(String),
Expand Down Expand Up @@ -284,7 +280,7 @@ pub enum DatabaseStorageErrorKind {
ActivityReadFailed {
guid: String,
#[source]
source: sea_orm::error::SqlErr,
source: sea_orm::error::DbErr,
},

/// There is no item contained with id {0}
Expand Down
7 changes: 4 additions & 3 deletions crates/storage/src/entity/activities.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15
use chrono::{DateTime, FixedOffset};
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
Expand All @@ -8,16 +9,16 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub guid: String,
pub description_guid: String,
pub begin: String,
pub end: Option<String>,
pub begin: DateTime<FixedOffset>,
pub end: Option<DateTime<FixedOffset>>,
pub duration: Option<i32>,
pub kind_guid: String,
pub status_guid: String,
pub parent_guid: Option<String>,
}

#[derive(DeriveIden)]
pub enum Activities {
pub enum ActivitiesEnum {
Table,
Guid,
DescriptionGuid,
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/entity/activities_categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Model {
}

#[derive(DeriveIden)]
pub enum ActivitiesCategories {
pub enum ActivitiesCategoriesEnum {
Table,
Guid,
ActivityGuid,
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/entity/activities_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Model {
}

#[derive(DeriveIden)]
pub enum ActivitiesTags {
pub enum ActivitiesTagsEnum {
Table,
Guid,
TagGuid,
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/entity/activity_kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
}

#[derive(DeriveIden)]
pub enum ActivityKinds {
pub enum ActivityKindsEnum {
Table,
Guid,
Kind,
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/entity/activity_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
}

#[derive(DeriveIden)]
pub enum ActivityStatus {
pub enum ActivityStatusEnum {
Table,
Guid,
Status,
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/entity/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Model {
}

#[derive(DeriveIden)]
pub enum Categories {
pub enum CategoriesEnum {
Table,
Guid,
Category,
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/entity/descriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
}

#[derive(DeriveIden)]
pub enum Descriptions {
pub enum DescriptionsEnum {
Table,
Guid,
Description,
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/entity/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
}

#[derive(DeriveIden)]
pub enum Tags {
pub enum TagsEnum {
Table,
Guid,
Tag,
Expand Down
44 changes: 22 additions & 22 deletions crates/storage/src/migration/m20240325_000001_create_activities.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use sea_orm_migration::prelude::*;

use crate::entity::activities::Activities;
use crate::entity::activity_kinds::ActivityKinds;
use crate::entity::activity_status::ActivityStatus;
use crate::entity::descriptions::Descriptions;
use crate::entity::activities::ActivitiesEnum;
use crate::entity::activity_kinds::ActivityKindsEnum;
use crate::entity::activity_status::ActivityStatusEnum;
use crate::entity::descriptions::DescriptionsEnum;

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -14,56 +14,56 @@ impl MigrationTrait for Migration {
manager
.create_table(
Table::create()
.table(Activities::Table)
.table(ActivitiesEnum::Table)
.if_not_exists()
.col(
ColumnDef::new(Activities::Guid)
ColumnDef::new(ActivitiesEnum::Guid)
.text()
.not_null()
.primary_key(),
)
.col(
ColumnDef::new(Activities::DescriptionGuid)
ColumnDef::new(ActivitiesEnum::DescriptionGuid)
.text()
.not_null(),
)
.col(
ColumnDef::new(Activities::Begin)
ColumnDef::new(ActivitiesEnum::Begin)
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(Activities::End)
ColumnDef::new(ActivitiesEnum::End)
.timestamp_with_time_zone()
.null(),
)
.col(ColumnDef::new(Activities::Duration).integer().null())
.col(ColumnDef::new(Activities::KindGuid).text().not_null())
.col(ColumnDef::new(Activities::StatusGuid).text().not_null())
.col(ColumnDef::new(Activities::ParentGuid).text().null())
.col(ColumnDef::new(ActivitiesEnum::Duration).integer().null())
.col(ColumnDef::new(ActivitiesEnum::KindGuid).text().not_null())
.col(ColumnDef::new(ActivitiesEnum::StatusGuid).text().not_null())
.col(ColumnDef::new(ActivitiesEnum::ParentGuid).text().null())
.foreign_key(
ForeignKey::create()
.name("fk_activities_parent_guid")
.from(Activities::Table, Activities::ParentGuid)
.to(Activities::Table, Activities::Guid),
.from(ActivitiesEnum::Table, ActivitiesEnum::ParentGuid)
.to(ActivitiesEnum::Table, ActivitiesEnum::Guid),
)
.foreign_key(
ForeignKey::create()
.name("fk_activities_kind")
.from(Activities::Table, Activities::KindGuid)
.to(ActivityKinds::Table, ActivityKinds::Guid),
.from(ActivitiesEnum::Table, ActivitiesEnum::KindGuid)
.to(ActivityKindsEnum::Table, ActivityKindsEnum::Guid),
)
.foreign_key(
ForeignKey::create()
.name("fk_activities_status")
.from(Activities::Table, Activities::StatusGuid)
.to(ActivityStatus::Table, ActivityStatus::Guid),
.from(ActivitiesEnum::Table, ActivitiesEnum::StatusGuid)
.to(ActivityStatusEnum::Table, ActivityStatusEnum::Guid),
)
.foreign_key(
ForeignKey::create()
.name("fk_activities_description")
.from(Activities::Table, Activities::DescriptionGuid)
.to(Descriptions::Table, Descriptions::Guid),
.from(ActivitiesEnum::Table, ActivitiesEnum::DescriptionGuid)
.to(DescriptionsEnum::Table, DescriptionsEnum::Guid),
)
.to_owned(),
)
Expand All @@ -74,7 +74,7 @@ impl MigrationTrait for Migration {
manager
.drop_table(
Table::drop()
.table(Activities::Table)
.table(ActivitiesEnum::Table)
.if_exists()
.to_owned(),
)
Expand Down
15 changes: 10 additions & 5 deletions crates/storage/src/migration/m20240326_000001_create_tags.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sea_orm_migration::prelude::*;

use crate::entity::tags::Tags;
use crate::entity::tags::TagsEnum;

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -12,17 +12,22 @@ impl MigrationTrait for Migration {
.create_table(
Table::create()
.if_not_exists()
.table(Tags::Table)
.col(ColumnDef::new(Tags::Guid).text().not_null().primary_key())
.col(ColumnDef::new(Tags::Tag).text().not_null())
.table(TagsEnum::Table)
.col(
ColumnDef::new(TagsEnum::Guid)
.text()
.not_null()
.primary_key(),
)
.col(ColumnDef::new(TagsEnum::Tag).text().not_null())
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Tags::Table).if_exists().to_owned())
.drop_table(Table::drop().table(TagsEnum::Table).if_exists().to_owned())
.await
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sea_orm_migration::prelude::*;

use crate::entity::categories::Categories;
use crate::entity::categories::CategoriesEnum;

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -12,15 +12,15 @@ impl MigrationTrait for Migration {
.create_table(
Table::create()
.if_not_exists()
.table(Categories::Table)
.table(CategoriesEnum::Table)
.col(
ColumnDef::new(Categories::Guid)
ColumnDef::new(CategoriesEnum::Guid)
.text()
.not_null()
.primary_key(),
)
.col(ColumnDef::new(Categories::Category).text().not_null())
.col(ColumnDef::new(Categories::Description).text().null())
.col(ColumnDef::new(CategoriesEnum::Category).text().not_null())
.col(ColumnDef::new(CategoriesEnum::Description).text().null())
.to_owned(),
)
.await
Expand All @@ -30,7 +30,7 @@ impl MigrationTrait for Migration {
manager
.drop_table(
Table::drop()
.table(Categories::Table)
.table(CategoriesEnum::Table)
.if_exists()
.to_owned(),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sea_orm_migration::prelude::*;

use crate::entity::activity_status::ActivityStatus;
use crate::entity::activity_status::ActivityStatusEnum;

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -12,14 +12,14 @@ impl MigrationTrait for Migration {
.create_table(
Table::create()
.if_not_exists()
.table(ActivityStatus::Table)
.table(ActivityStatusEnum::Table)
.col(
ColumnDef::new(ActivityStatus::Guid)
ColumnDef::new(ActivityStatusEnum::Guid)
.text()
.not_null()
.primary_key(),
)
.col(ColumnDef::new(ActivityStatus::Status).text().not_null())
.col(ColumnDef::new(ActivityStatusEnum::Status).text().not_null())
.to_owned(),
)
.await
Expand All @@ -29,7 +29,7 @@ impl MigrationTrait for Migration {
manager
.drop_table(
Table::drop()
.table(ActivityStatus::Table)
.table(ActivityStatusEnum::Table)
.if_exists()
.to_owned(),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sea_orm_migration::prelude::*;

use crate::entity::activity_kinds::ActivityKinds;
use crate::entity::activity_kinds::ActivityKindsEnum;

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -12,14 +12,14 @@ impl MigrationTrait for Migration {
.create_table(
Table::create()
.if_not_exists()
.table(ActivityKinds::Table)
.table(ActivityKindsEnum::Table)
.col(
ColumnDef::new(ActivityKinds::Guid)
ColumnDef::new(ActivityKindsEnum::Guid)
.text()
.not_null()
.primary_key(),
)
.col(ColumnDef::new(ActivityKinds::Kind).text().not_null())
.col(ColumnDef::new(ActivityKindsEnum::Kind).text().not_null())
.to_owned(),
)
.await
Expand All @@ -29,7 +29,7 @@ impl MigrationTrait for Migration {
manager
.drop_table(
Table::drop()
.table(ActivityKinds::Table)
.table(ActivityKindsEnum::Table)
.if_exists()
.to_owned(),
)
Expand Down
Loading

0 comments on commit d2340a0

Please sign in to comment.