Skip to content

Commit

Permalink
generate new entities using seaORM CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
calebbourg committed Feb 18, 2024
1 parent 4083400 commit 328ca94
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ DATABASE_URL=postgres://refactor:password@localhost:5432/refactor_platform sea-o
```
### Generate a new Entity from Database
Note that to generate a new Entity using the CLI you must ignore all other tables using the `--ignore-tables` option. You must add the option for _each_ table you are ignoring.
```bash
DATABASE_URL=postgres://refactor:password@localhost:5432/refactor_platform sea-orm-cli generate entity -s refactor_platform -o entity/src
DATABASE_URL=postgres://refactor:password@localhost:5432/refactor_platform sea-orm-cli generate entity -s refactor_platform -o entity/src -v --with-serde both --serde-skip-deserializing-primary-key --ignore-tables {table to ignore} --ignore-tables {other table to ignore}
```
## Project Directory Structure
Expand Down
40 changes: 40 additions & 0 deletions entity/src/actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(schema_name = "refactor_platform", table_name = "actions")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(unique)]
pub external_id: Uuid,
pub coaching_session_id: i32,
pub due_by: Option<DateTimeWithTimeZone>,
pub completed: Option<bool>,
pub completed_at: Option<DateTimeWithTimeZone>,
pub created_at: Option<DateTime>,
pub updated_at: Option<DateTime>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::coaching_sessions::Entity",
from = "Column::CoachingSessionId",
to = "super::coaching_sessions::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
CoachingSessions,
}

impl Related<super::coaching_sessions::Entity> for Entity {
fn to() -> RelationDef {
Relation::CoachingSessions.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
53 changes: 53 additions & 0 deletions entity/src/agreements.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(schema_name = "refactor_platform", table_name = "agreements")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(unique)]
pub external_id: Uuid,
pub coaching_session_id: i32,
pub details: Option<String>,
pub user_id: i32,
pub created_at: Option<DateTimeWithTimeZone>,
pub updated_at: Option<DateTimeWithTimeZone>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::coaching_sessions::Entity",
from = "Column::CoachingSessionId",
to = "super::coaching_sessions::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
CoachingSessions,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
Users,
}

impl Related<super::coaching_sessions::Entity> for Entity {
fn to() -> RelationDef {
Relation::CoachingSessions.def()
}
}

impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
71 changes: 71 additions & 0 deletions entity/src/coaching_sessions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(schema_name = "refactor_platform", table_name = "coaching_sessions")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(unique)]
pub external_id: Uuid,
pub coaching_relationship_id: i32,
pub date: Option<DateTime>,
pub timezone: Option<String>,
pub created_at: Option<DateTimeWithTimeZone>,
pub updated_at: Option<DateTimeWithTimeZone>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::actions::Entity")]
Actions,
#[sea_orm(has_many = "super::agreements::Entity")]
Agreements,
#[sea_orm(
belongs_to = "super::coaching_relationships::Entity",
from = "Column::CoachingRelationshipId",
to = "super::coaching_relationships::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
CoachingRelationships,
#[sea_orm(has_many = "super::notes::Entity")]
Notes,
#[sea_orm(has_many = "super::overarching_goals::Entity")]
OverarchingGoals,
}

impl Related<super::actions::Entity> for Entity {
fn to() -> RelationDef {
Relation::Actions.def()
}
}

impl Related<super::agreements::Entity> for Entity {
fn to() -> RelationDef {
Relation::Agreements.def()
}
}

impl Related<super::coaching_relationships::Entity> for Entity {
fn to() -> RelationDef {
Relation::CoachingRelationships.def()
}
}

impl Related<super::notes::Entity> for Entity {
fn to() -> RelationDef {
Relation::Notes.def()
}
}

impl Related<super::overarching_goals::Entity> for Entity {
fn to() -> RelationDef {
Relation::OverarchingGoals.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
9 changes: 6 additions & 3 deletions entity/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

pub mod prelude;

pub mod coaching_relationship;
pub mod organization;
pub mod user;
pub mod actions;
pub mod agreements;
pub mod coaching_sessions;
pub mod notes;
pub mod overarching_goals;
pub mod seaql_migrations;
53 changes: 53 additions & 0 deletions entity/src/notes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(schema_name = "refactor_platform", table_name = "notes")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(unique)]
pub external_id: Uuid,
pub coaching_session_id: i32,
pub body: Option<String>,
pub user_id: i32,
pub created_at: Option<DateTimeWithTimeZone>,
pub updated_at: Option<DateTimeWithTimeZone>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::coaching_sessions::Entity",
from = "Column::CoachingSessionId",
to = "super::coaching_sessions::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
CoachingSessions,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
Users,
}

impl Related<super::coaching_sessions::Entity> for Entity {
fn to() -> RelationDef {
Relation::CoachingSessions.def()
}
}

impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
40 changes: 40 additions & 0 deletions entity/src/overarching_goals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(schema_name = "refactor_platform", table_name = "overarching_goals")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
#[sea_orm(unique)]
pub external_id: Uuid,
pub coaching_session_id: Option<i32>,
pub title: Option<String>,
pub details: Option<String>,
pub completed_at: Option<DateTimeWithTimeZone>,
pub created_at: Option<DateTimeWithTimeZone>,
pub updated_at: Option<DateTimeWithTimeZone>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::coaching_sessions::Entity",
from = "Column::CoachingSessionId",
to = "super::coaching_sessions::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
CoachingSessions,
}

impl Related<super::coaching_sessions::Entity> for Entity {
fn to() -> RelationDef {
Relation::CoachingSessions.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
9 changes: 6 additions & 3 deletions entity/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

pub use super::coaching_relationships::Entity as CoachingRelationships;
pub use super::organizations::Entity as Organizations;
pub use super::users::Entity as Users;
pub use super::actions::Entity as Actions;
pub use super::agreements::Entity as Agreements;
pub use super::coaching_sessions::Entity as CoachingSessions;
pub use super::notes::Entity as Notes;
pub use super::overarching_goals::Entity as OverarchingGoals;
pub use super::seaql_migrations::Entity as SeaqlMigrations;
18 changes: 18 additions & 0 deletions entity/src/seaql_migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(schema_name = "refactor_platform", table_name = "seaql_migrations")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
#[serde(skip_deserializing)]
pub version: String,
pub applied_at: i64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

0 comments on commit 328ca94

Please sign in to comment.