upub/src/migrations/m20240316_000001_create_table.rs

170 lines
4.4 KiB
Rust
Raw Normal View History

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(Users::Table)
.col(
ColumnDef::new(Users::Id)
.string()
.not_null()
.primary_key()
)
2024-03-19 01:00:44 +01:00
.col(ColumnDef::new(Users::ActorType).string().not_null())
2024-03-21 01:09:33 +01:00
.col(ColumnDef::new(Users::Domain).string().not_null())
.col(ColumnDef::new(Users::Name).string().null())
2024-03-21 01:09:33 +01:00
.col(ColumnDef::new(Users::Summary).string().null())
.col(ColumnDef::new(Users::Image).string().null())
.col(ColumnDef::new(Users::Icon).string().null())
.col(ColumnDef::new(Users::PreferredUsername).string().not_null())
2024-03-21 01:09:33 +01:00
.col(ColumnDef::new(Users::Inbox).string().null())
.col(ColumnDef::new(Users::SharedInbox).string().null())
.col(ColumnDef::new(Users::Outbox).string().null())
.col(ColumnDef::new(Users::Following).string().null())
.col(ColumnDef::new(Users::Followers).string().null())
.col(ColumnDef::new(Users::FollowingCount).integer().not_null().default(0))
.col(ColumnDef::new(Users::FollowersCount).integer().not_null().default(0))
// .col(ColumnDef::new(Users::StatusesCount).integer().not_null().default(0))
.col(ColumnDef::new(Users::PublicKey).string().not_null())
.col(ColumnDef::new(Users::PrivateKey).string().null())
2024-03-21 01:09:33 +01:00
.col(ColumnDef::new(Users::Created).date_time().not_null())
.col(ColumnDef::new(Users::Updated).date_time().not_null())
.to_owned()
)
.await?;
manager
.create_table(
Table::create()
.table(Activities::Table)
.col(
ColumnDef::new(Activities::Id)
.string()
.not_null()
.primary_key()
)
2024-03-19 01:00:44 +01:00
.col(ColumnDef::new(Activities::ActivityType).string().not_null())
.col(ColumnDef::new(Activities::Actor).string().not_null())
.col(ColumnDef::new(Activities::Object).string().null())
.col(ColumnDef::new(Activities::Target).string().null())
2024-03-21 01:09:33 +01:00
.col(ColumnDef::new(Activities::To).json().null())
.col(ColumnDef::new(Activities::Bto).json().null())
.col(ColumnDef::new(Activities::Cc).json().null())
.col(ColumnDef::new(Activities::Bcc).json().null())
.col(ColumnDef::new(Activities::Published).date_time().not_null())
.to_owned()
).await?;
manager
.create_table(
Table::create()
.table(Objects::Table)
.col(
ColumnDef::new(Objects::Id)
.string()
.not_null()
.primary_key()
)
2024-03-19 01:00:44 +01:00
.col(ColumnDef::new(Objects::ObjectType).string().not_null())
.col(ColumnDef::new(Objects::AttributedTo).string().null())
.col(ColumnDef::new(Objects::Name).string().null())
.col(ColumnDef::new(Objects::Summary).string().null())
.col(ColumnDef::new(Objects::Content).string().null())
.col(ColumnDef::new(Objects::Likes).integer().not_null().default(0))
.col(ColumnDef::new(Objects::Shares).integer().not_null().default(0))
.col(ColumnDef::new(Objects::Comments).integer().not_null().default(0))
2024-03-21 19:51:00 +01:00
.col(ColumnDef::new(Objects::Context).string().null())
2024-03-21 20:36:46 +01:00
.col(ColumnDef::new(Objects::To).json().null())
.col(ColumnDef::new(Objects::Bto).json().null())
.col(ColumnDef::new(Objects::Cc).json().null())
.col(ColumnDef::new(Objects::Bcc).json().null())
2024-03-21 01:09:33 +01:00
.col(ColumnDef::new(Objects::Published).string().not_null())
.to_owned()
).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Users::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Activities::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Objects::Table).to_owned())
.await?;
Ok(())
}
}
#[derive(DeriveIden)]
enum Users {
Table,
Id,
2024-03-21 01:09:33 +01:00
Domain,
ActorType,
Name,
2024-03-21 01:09:33 +01:00
Summary,
Image,
Icon,
PreferredUsername,
Inbox,
SharedInbox,
Outbox,
Following,
FollowingCount,
2024-03-21 01:09:33 +01:00
Followers,
FollowersCount,
// StatusesCount,
PublicKey,
PrivateKey,
2024-03-21 01:09:33 +01:00
Created,
Updated,
}
#[derive(DeriveIden)]
enum Activities {
Table,
Id,
ActivityType,
Actor,
Object,
Target,
2024-03-21 01:09:33 +01:00
Cc,
Bcc,
To,
Bto,
Published,
}
#[derive(DeriveIden)]
enum Objects {
Table,
Id,
ObjectType,
2024-03-21 01:09:33 +01:00
AttributedTo,
Name,
Summary,
Content,
Likes,
Shares,
Comments,
2024-03-21 19:51:00 +01:00
Context,
2024-03-21 20:36:46 +01:00
Cc,
Bcc,
To,
Bto,
Published,
}