From c2d775b30e486da59cb548b5bab39bbceb14336c Mon Sep 17 00:00:00 2001 From: Evie Viau Date: Sat, 4 Feb 2023 01:54:06 -0800 Subject: [PATCH] Add page and post blocks --- .fleet/run.json | 10 ++++ migration/src/lib.rs | 4 ++ .../src/m20230204_001022_create_pages.rs | 4 +- .../src/m20230204_011034_create_posts.rs | 2 +- .../m20230204_014834_create_post_blocks.rs | 52 +++++++++++++++++++ .../m20230204_014838_create_page_blocks.rs | 52 +++++++++++++++++++ src/entities/mod.rs | 2 + src/entities/page.rs | 11 +++- src/entities/page_block.rs | 34 ++++++++++++ src/entities/post.rs | 11 +++- src/entities/post_block.rs | 34 ++++++++++++ src/entities/prelude.rs | 2 + 12 files changed, 213 insertions(+), 5 deletions(-) create mode 100644 .fleet/run.json create mode 100644 migration/src/m20230204_014834_create_post_blocks.rs create mode 100644 migration/src/m20230204_014838_create_page_blocks.rs create mode 100644 src/entities/page_block.rs create mode 100644 src/entities/post_block.rs diff --git a/.fleet/run.json b/.fleet/run.json new file mode 100644 index 0000000..48ad121 --- /dev/null +++ b/.fleet/run.json @@ -0,0 +1,10 @@ +{ + "configurations": [ + { + "type": "cargo", + "name": "Run", + "cargoArgs": ["run"] + }, + + ] +} \ No newline at end of file diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 75049b4..f35d73d 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -2,6 +2,8 @@ pub use sea_orm_migration::prelude::*; mod m20230204_001022_create_pages; mod m20230204_011034_create_posts; +mod m20230204_014834_create_post_blocks; +mod m20230204_014838_create_page_blocks; pub struct Migrator; #[async_trait::async_trait] @@ -10,6 +12,8 @@ impl MigratorTrait for Migrator { vec![ Box::new(m20230204_001022_create_pages::Migration), Box::new(m20230204_011034_create_posts::Migration), + Box::new(m20230204_014834_create_post_blocks::Migration), + Box::new(m20230204_014838_create_page_blocks::Migration), ] } } diff --git a/migration/src/m20230204_001022_create_pages.rs b/migration/src/m20230204_001022_create_pages.rs index 3733e8a..7cfe580 100644 --- a/migration/src/m20230204_001022_create_pages.rs +++ b/migration/src/m20230204_001022_create_pages.rs @@ -12,7 +12,7 @@ impl MigrationTrait for Migration { .table(Page::Table) .if_not_exists() .col( - ColumnDef::new(Page::Id) + ColumnDef::new(Page::Id) .string() .not_null() .primary_key(), @@ -37,7 +37,7 @@ impl MigrationTrait for Migration { /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] -enum Page { +pub enum Page { Table, Id, Draft, diff --git a/migration/src/m20230204_011034_create_posts.rs b/migration/src/m20230204_011034_create_posts.rs index 9a3e419..66a8df1 100644 --- a/migration/src/m20230204_011034_create_posts.rs +++ b/migration/src/m20230204_011034_create_posts.rs @@ -37,7 +37,7 @@ impl MigrationTrait for Migration { /// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] -enum Post { +pub enum Post { Table, Id, Draft, diff --git a/migration/src/m20230204_014834_create_post_blocks.rs b/migration/src/m20230204_014834_create_post_blocks.rs new file mode 100644 index 0000000..b63c539 --- /dev/null +++ b/migration/src/m20230204_014834_create_post_blocks.rs @@ -0,0 +1,52 @@ +use sea_orm_migration::prelude::*; + +use super::m20230204_011034_create_posts::Post; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(PostBlock::Table) + .if_not_exists() + .col( + ColumnDef::new(PostBlock::Id) + .string() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(PostBlock::Owner).string().not_null()) + .col(ColumnDef::new(PostBlock::Order).integer().not_null()) + .col(ColumnDef::new(PostBlock::Type).string().not_null()) + .col(ColumnDef::new(PostBlock::Content).string().not_null()) + .foreign_key(ForeignKey::create() + .name("fk-post_blocks-posts") + .from(PostBlock::Table, PostBlock::Owner) + .to(Post::Table, Post::Id) + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(PostBlock::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +pub enum PostBlock { + Table, + Id, + Owner, + Order, + Type, + Content +} diff --git a/migration/src/m20230204_014838_create_page_blocks.rs b/migration/src/m20230204_014838_create_page_blocks.rs new file mode 100644 index 0000000..a7dcbdb --- /dev/null +++ b/migration/src/m20230204_014838_create_page_blocks.rs @@ -0,0 +1,52 @@ +use sea_orm_migration::prelude::*; + +use crate::m20230204_001022_create_pages::Page; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(PageBlock::Table) + .if_not_exists() + .col( + ColumnDef::new(PageBlock::Id) + .string() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(PageBlock::Owner).string().not_null()) + .col(ColumnDef::new(PageBlock::Order).integer().not_null()) + .col(ColumnDef::new(PageBlock::Type).string().not_null()) + .col(ColumnDef::new(PageBlock::Content).string().not_null()) + .foreign_key(ForeignKey::create() + .name("fk-page_blocks-posts") + .from(PageBlock::Table, PageBlock::Owner) + .to(Page::Table, Page::Id) + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(PageBlock::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +pub enum PageBlock { + Table, + Id, + Owner, + Order, + Type, + Content +} diff --git a/src/entities/mod.rs b/src/entities/mod.rs index 57cfd6f..fa4ca12 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -3,4 +3,6 @@ pub mod prelude; pub mod page; +pub mod page_block; pub mod post; +pub mod post_block; diff --git a/src/entities/page.rs b/src/entities/page.rs index 4264b90..d48767a 100644 --- a/src/entities/page.rs +++ b/src/entities/page.rs @@ -16,6 +16,15 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::page_block::Entity")] + PageBlock, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::PageBlock.def() + } +} impl ActiveModelBehavior for ActiveModel {} diff --git a/src/entities/page_block.rs b/src/entities/page_block.rs new file mode 100644 index 0000000..c92d607 --- /dev/null +++ b/src/entities/page_block.rs @@ -0,0 +1,34 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "page_block")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub owner: String, + pub order: i32, + pub r#type: String, + pub content: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::page::Entity", + from = "Column::Owner", + to = "super::page::Column::Id", + on_update = "Restrict", + on_delete = "Restrict" + )] + Page, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Page.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/entities/post.rs b/src/entities/post.rs index a8d20c8..fbedf4d 100644 --- a/src/entities/post.rs +++ b/src/entities/post.rs @@ -16,6 +16,15 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::post_block::Entity")] + PostBlock, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::PostBlock.def() + } +} impl ActiveModelBehavior for ActiveModel {} diff --git a/src/entities/post_block.rs b/src/entities/post_block.rs new file mode 100644 index 0000000..1f5fe58 --- /dev/null +++ b/src/entities/post_block.rs @@ -0,0 +1,34 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "post_block")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub owner: String, + pub order: i32, + pub r#type: String, + pub content: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::post::Entity", + from = "Column::Owner", + to = "super::post::Column::Id", + on_update = "Restrict", + on_delete = "Restrict" + )] + Post, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Post.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/entities/prelude.rs b/src/entities/prelude.rs index b2296eb..56f78f1 100644 --- a/src/entities/prelude.rs +++ b/src/entities/prelude.rs @@ -1,4 +1,6 @@ //! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7 pub use super::page::Entity as Page; +pub use super::page_block::Entity as PageBlock; pub use super::post::Entity as Post; +pub use super::post_block::Entity as PostBlock;