Add page and post blocks

This commit is contained in:
Evie Viau-Chow-Stuart 2023-02-04 01:54:06 -08:00
parent a2bf8542d9
commit c2d775b30e
Signed by: evie
GPG key ID: 928652CDFCEC8099
12 changed files with 213 additions and 5 deletions

10
.fleet/run.json Normal file
View file

@ -0,0 +1,10 @@
{
"configurations": [
{
"type": "cargo",
"name": "Run",
"cargoArgs": ["run"]
},
]
}

View file

@ -2,6 +2,8 @@ pub use sea_orm_migration::prelude::*;
mod m20230204_001022_create_pages; mod m20230204_001022_create_pages;
mod m20230204_011034_create_posts; mod m20230204_011034_create_posts;
mod m20230204_014834_create_post_blocks;
mod m20230204_014838_create_page_blocks;
pub struct Migrator; pub struct Migrator;
#[async_trait::async_trait] #[async_trait::async_trait]
@ -10,6 +12,8 @@ impl MigratorTrait for Migrator {
vec![ vec![
Box::new(m20230204_001022_create_pages::Migration), Box::new(m20230204_001022_create_pages::Migration),
Box::new(m20230204_011034_create_posts::Migration), Box::new(m20230204_011034_create_posts::Migration),
Box::new(m20230204_014834_create_post_blocks::Migration),
Box::new(m20230204_014838_create_page_blocks::Migration),
] ]
} }
} }

View file

@ -12,7 +12,7 @@ impl MigrationTrait for Migration {
.table(Page::Table) .table(Page::Table)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(Page::Id) ColumnDef::new(Page::Id)
.string() .string()
.not_null() .not_null()
.primary_key(), .primary_key(),
@ -37,7 +37,7 @@ impl MigrationTrait for Migration {
/// Learn more at https://docs.rs/sea-query#iden /// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)] #[derive(Iden)]
enum Page { pub enum Page {
Table, Table,
Id, Id,
Draft, Draft,

View file

@ -37,7 +37,7 @@ impl MigrationTrait for Migration {
/// Learn more at https://docs.rs/sea-query#iden /// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)] #[derive(Iden)]
enum Post { pub enum Post {
Table, Table,
Id, Id,
Draft, Draft,

View file

@ -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
}

View file

@ -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
}

View file

@ -3,4 +3,6 @@
pub mod prelude; pub mod prelude;
pub mod page; pub mod page;
pub mod page_block;
pub mod post; pub mod post;
pub mod post_block;

View file

@ -16,6 +16,15 @@ pub struct Model {
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {} pub enum Relation {
#[sea_orm(has_many = "super::page_block::Entity")]
PageBlock,
}
impl Related<super::page_block::Entity> for Entity {
fn to() -> RelationDef {
Relation::PageBlock.def()
}
}
impl ActiveModelBehavior for ActiveModel {} impl ActiveModelBehavior for ActiveModel {}

View file

@ -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<super::page::Entity> for Entity {
fn to() -> RelationDef {
Relation::Page.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -16,6 +16,15 @@ pub struct Model {
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {} pub enum Relation {
#[sea_orm(has_many = "super::post_block::Entity")]
PostBlock,
}
impl Related<super::post_block::Entity> for Entity {
fn to() -> RelationDef {
Relation::PostBlock.def()
}
}
impl ActiveModelBehavior for ActiveModel {} impl ActiveModelBehavior for ActiveModel {}

View file

@ -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<super::post::Entity> for Entity {
fn to() -> RelationDef {
Relation::Post.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -1,4 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7 //! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7
pub use super::page::Entity as Page; 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::Entity as Post;
pub use super::post_block::Entity as PostBlock;