Create post schema
This commit is contained in:
parent
06dd8fce67
commit
a2bf8542d9
5 changed files with 77 additions and 1 deletions
|
@ -1,11 +1,15 @@
|
|||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20230204_001022_create_pages;
|
||||
mod m20230204_011034_create_posts;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20230204_001022_create_pages::Migration)]
|
||||
vec![
|
||||
Box::new(m20230204_001022_create_pages::Migration),
|
||||
Box::new(m20230204_011034_create_posts::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
49
migration/src/m20230204_011034_create_posts.rs
Normal file
49
migration/src/m20230204_011034_create_posts.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[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(Post::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Post::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Post::Draft).boolean().not_null())
|
||||
.col(ColumnDef::new(Post::Slug).string().not_null())
|
||||
.col(ColumnDef::new(Post::Title).string().not_null())
|
||||
.col(ColumnDef::new(Post::Summary).string())
|
||||
.col(ColumnDef::new(Post::Published).date_time().not_null())
|
||||
.col(ColumnDef::new(Post::Updated).date_time())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Post::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
enum Post {
|
||||
Table,
|
||||
Id,
|
||||
Draft,
|
||||
Slug,
|
||||
Title,
|
||||
Summary,
|
||||
Published,
|
||||
Updated,
|
||||
}
|
|
@ -3,3 +3,4 @@
|
|||
pub mod prelude;
|
||||
|
||||
pub mod page;
|
||||
pub mod post;
|
||||
|
|
21
src/entities/post.rs
Normal file
21
src/entities/post.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
//! `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")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: String,
|
||||
pub draft: i8,
|
||||
pub slug: String,
|
||||
pub title: String,
|
||||
pub summary: Option<String>,
|
||||
pub published: DateTime,
|
||||
pub updated: Option<DateTime>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -1,3 +1,4 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7
|
||||
|
||||
pub use super::page::Entity as Page;
|
||||
pub use super::post::Entity as Post;
|
||||
|
|
Reference in a new issue