mirror of
https://github.com/versia-pub/activitypub.git
synced 2026-03-13 10:59:17 +01:00
[feat]: initial migration
This commit is contained in:
parent
ed912004b8
commit
99304aa53a
12 changed files with 1474 additions and 243 deletions
|
|
@ -1,12 +1,18 @@
|
|||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20220101_000001_create_table;
|
||||
mod m20220101_000001_post_table;
|
||||
mod m20240417_230111_user_table;
|
||||
mod m20240417_233430_post_user_keys;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20220101_000001_create_table::Migration)]
|
||||
vec![
|
||||
Box::new(m20220101_000001_post_table::Migration),
|
||||
Box::new(m20240417_230111_user_table::Migration),
|
||||
Box::new(m20240417_233430_post_user_keys::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
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> {
|
||||
// Replace the sample below with your own migration scripts
|
||||
todo!();
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Post::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Post::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Post::Title).string().not_null())
|
||||
.col(ColumnDef::new(Post::Text).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Replace the sample below with your own migration scripts
|
||||
todo!();
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Post::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Post {
|
||||
Table,
|
||||
Id,
|
||||
Title,
|
||||
Text,
|
||||
}
|
||||
59
migration/src/m20220101_000001_post_table.rs
Normal file
59
migration/src/m20220101_000001_post_table.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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::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())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Post::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Post {
|
||||
Table,
|
||||
Id,
|
||||
Url,
|
||||
Creator,
|
||||
Title,
|
||||
Content,
|
||||
Local,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
ReblogId,
|
||||
ContentType,
|
||||
Visibility,
|
||||
ReplyId,
|
||||
QuotingId,
|
||||
Sensitive,
|
||||
SpoilerText,
|
||||
}
|
||||
61
migration/src/m20240417_230111_user_table.rs
Normal file
61
migration/src/m20240417_230111_user_table.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
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(User::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(User::Id).string().not_null().primary_key())
|
||||
.col(ColumnDef::new(User::Username).string().not_null())
|
||||
.col(ColumnDef::new(User::Name).string().not_null())
|
||||
.col(ColumnDef::new(User::Summary).string())
|
||||
.col(ColumnDef::new(User::Url).string().not_null())
|
||||
.col(ColumnDef::new(User::PublicKey).string().not_null())
|
||||
.col(ColumnDef::new(User::PrivateKey).string())
|
||||
.col(ColumnDef::new(User::LastRefreshedAt).timestamp().not_null())
|
||||
.col(ColumnDef::new(User::Local).boolean().not_null())
|
||||
.col(ColumnDef::new(User::FollowerCount).integer().not_null())
|
||||
.col(ColumnDef::new(User::FollowingCount).integer().not_null())
|
||||
.col(ColumnDef::new(User::CreatedAt).timestamp().not_null())
|
||||
.col(ColumnDef::new(User::UpdatedAt).timestamp())
|
||||
.col(ColumnDef::new(User::Following).string())
|
||||
.col(ColumnDef::new(User::Followers).string())
|
||||
.col(ColumnDef::new(User::Inbox).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(User::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum User {
|
||||
Table,
|
||||
Id,
|
||||
Username,
|
||||
Name,
|
||||
Summary,
|
||||
Url,
|
||||
PublicKey,
|
||||
PrivateKey,
|
||||
LastRefreshedAt,
|
||||
Local,
|
||||
FollowerCount,
|
||||
FollowingCount,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
Following,
|
||||
Followers,
|
||||
Inbox,
|
||||
}
|
||||
62
migration/src/m20240417_233430_post_user_keys.rs
Normal file
62
migration/src/m20240417_233430_post_user_keys.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
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> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Post::Table)
|
||||
.add_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_post_creator_user_id")
|
||||
.from(Post::Table, Post::Creator)
|
||||
.to(User::Table, User::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.get_foreign_key(),
|
||||
)
|
||||
.add_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_post_reblog_id")
|
||||
.from(Post::Table, Post::ReblogId)
|
||||
.to(Post::Table, Post::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.get_foreign_key(),
|
||||
)
|
||||
.add_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_post_reply_id")
|
||||
.from(Post::Table, Post::ReplyId)
|
||||
.to(Post::Table, Post::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.get_foreign_key(),
|
||||
)
|
||||
.add_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_post_quoting_id")
|
||||
.from(Post::Table, Post::QuotingId)
|
||||
.to(Post::Table, Post::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.get_foreign_key(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue