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(Bookmarks::Table)
.if_not_exists()
.col(ColumnDef::new(Bookmarks::Id).uuid().not_null().primary_key())
.col(ColumnDef::new(Bookmarks::UserId).uuid().not_null())
.col(ColumnDef::new(Bookmarks::PostId).uuid().not_null())
.col(ColumnDef::new(Bookmarks::CreatedAt).timestamp_with_time_zone().not_null().default(Expr::current_timestamp()))
.foreign_key(
ForeignKey::create()
.name("fk_bookmarks_user_id")
.from(Bookmarks::Table, Bookmarks::UserId)
.to(Alias::new("users"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKey::create()
.name("fk_bookmarks_post_id")
.from(Bookmarks::Table, Bookmarks::PostId)
.to(Alias::new("posts"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_bookmarks_user_post")
.table(Bookmarks::Table)
.col(Bookmarks::UserId)
.col(Bookmarks::PostId)
.unique()
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager.drop_table(Table::drop().table(Bookmarks::Table).to_owned()).await
}
}
#[derive(DeriveIden)]
enum Bookmarks {
Table,
Id,
UserId,
PostId,
CreatedAt,
}
neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
2.3 KiB · text
History
263b40b