pique/_experiments/2024-03-02-database-benchmark/migration/src/m20240307_110706_create_tables.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

use std::fmt;
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(Page::Table)
.if_not_exists()
.col(
ColumnDef::new(Page::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Page::ExternalId).big_integer().not_null())
.col(ColumnDef::new(Page::Title).string().not_null())
.col(ColumnDef::new(Page::Text).string().not_null())
//.col(ColumnDef::new(Page::Text).custom(LongText).not_null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Page::Table).to_owned())
.await
}
}
pub struct LongText;
impl Iden for LongText {
fn unquoted(&self, s: &mut dyn fmt::Write) {
s.write_str("LongText").unwrap();
}
}
#[derive(DeriveIden)]
enum Page {
Table,
Id,
ExternalId,
Title,
Text,
}