activitypub/migration/src/m20240417_233430_post_user_keys.rs

81 lines
3.4 KiB
Rust
Raw Normal View History

2024-04-18 01:47:18 +02:00
use sea_orm_migration::prelude::*;
use crate::{m20220101_000001_post_table::Post, m20240417_230111_user_table::User};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
2024-04-18 04:03:52 +02:00
manager
.drop_table(Table::drop().table(Post::Table).to_owned())
.await?;
2024-04-18 01:59:16 +02:00
2024-04-18 01:47:18 +02:00
manager
2024-04-18 01:59:16 +02:00
.create_table(
Table::create()
2024-04-18 01:47:18 +02:00
.table(Post::Table)
2024-04-18 01:59:16 +02:00
.if_not_exists()
.col(ColumnDef::new(Post::Id).string().not_null().primary_key())
.col(ColumnDef::new(Post::Title).string())
.col(ColumnDef::new(Post::Content).string().not_null())
.col(ColumnDef::new(Post::Local).boolean().not_null())
.col(ColumnDef::new(Post::CreatedAt).timestamp().not_null())
.col(ColumnDef::new(Post::UpdatedAt).timestamp())
.col(ColumnDef::new(Post::ReblogId).string())
.col(ColumnDef::new(Post::ContentType).string().not_null())
.col(ColumnDef::new(Post::Visibility).string().not_null())
.col(ColumnDef::new(Post::ReplyId).string())
.col(ColumnDef::new(Post::QuotingId).string())
.col(ColumnDef::new(Post::Sensitive).boolean().not_null())
.col(ColumnDef::new(Post::SpoilerText).string())
.col(ColumnDef::new(Post::Creator).string().not_null())
.col(ColumnDef::new(Post::Url).string().not_null())
.foreign_key(
2024-04-18 01:47:18 +02:00
ForeignKey::create()
.name("fk_post_creator_user_id")
.from(Post::Table, Post::Creator)
.to(User::Table, User::Id)
2024-04-18 01:59:16 +02:00
.on_delete(ForeignKeyAction::Cascade),
2024-04-18 01:47:18 +02:00
)
2024-04-18 01:59:16 +02:00
.foreign_key(
2024-04-18 01:47:18 +02:00
ForeignKey::create()
.name("fk_post_reblog_id")
.from(Post::Table, Post::ReblogId)
.to(Post::Table, Post::Id)
2024-04-18 01:59:16 +02:00
.on_delete(ForeignKeyAction::Cascade),
2024-04-18 01:47:18 +02:00
)
2024-04-18 01:59:16 +02:00
.foreign_key(
2024-04-18 01:47:18 +02:00
ForeignKey::create()
.name("fk_post_reply_id")
.from(Post::Table, Post::ReplyId)
.to(Post::Table, Post::Id)
2024-04-18 01:59:16 +02:00
.on_delete(ForeignKeyAction::Cascade),
2024-04-18 01:47:18 +02:00
)
2024-04-18 01:59:16 +02:00
.foreign_key(
2024-04-18 01:47:18 +02:00
ForeignKey::create()
.name("fk_post_quoting_id")
.from(Post::Table, Post::QuotingId)
.to(Post::Table, Post::Id)
2024-04-18 01:59:16 +02:00
.on_delete(ForeignKeyAction::Cascade),
2024-04-18 01:47:18 +02:00
)
.to_owned(),
)
2024-04-18 01:59:16 +02:00
.await?;
Ok(())
2024-04-18 01:47:18 +02:00
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_foreign_key(
ForeignKey::drop()
.name("fk_post_creator_user_id")
.table(Post::Table)
.to_owned(),
)
.await
}
}