parent
a2bf8542d9
commit
c2d775b30e
@ -0,0 +1,10 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "cargo",
|
||||
"name": "Run",
|
||||
"cargoArgs": ["run"]
|
||||
},
|
||||
|
||||
]
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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 {}
|
@ -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 {}
|
@ -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;
|
||||
|
Loading…
Reference in new issue