forked from alemi/upub
feat!: restructured db, remade all migrations
sorry! your db is now useless (: you weren't using upub in production, were you?? brb gonna migrate 50k posts from test db...
This commit is contained in:
parent
af994da294
commit
58c20b7ba5
22 changed files with 1193 additions and 1227 deletions
|
@ -1,169 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Users::Table)
|
||||
.col(
|
||||
ColumnDef::new(Users::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Users::ActorType).string().not_null())
|
||||
.col(ColumnDef::new(Users::Domain).string().not_null())
|
||||
.col(ColumnDef::new(Users::Name).string().null())
|
||||
.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())
|
||||
.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())
|
||||
.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()
|
||||
)
|
||||
.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())
|
||||
.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()
|
||||
)
|
||||
.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))
|
||||
.col(ColumnDef::new(Objects::Context).string().null())
|
||||
.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())
|
||||
.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,
|
||||
Domain,
|
||||
ActorType,
|
||||
Name,
|
||||
Summary,
|
||||
Image,
|
||||
Icon,
|
||||
PreferredUsername,
|
||||
Inbox,
|
||||
SharedInbox,
|
||||
Outbox,
|
||||
Following,
|
||||
FollowingCount,
|
||||
Followers,
|
||||
FollowersCount,
|
||||
// StatusesCount,
|
||||
PublicKey,
|
||||
PrivateKey,
|
||||
Created,
|
||||
Updated,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Activities {
|
||||
Table,
|
||||
Id,
|
||||
ActivityType,
|
||||
Actor,
|
||||
Object,
|
||||
Target,
|
||||
Cc,
|
||||
Bcc,
|
||||
To,
|
||||
Bto,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Objects {
|
||||
Table,
|
||||
Id,
|
||||
ObjectType,
|
||||
AttributedTo,
|
||||
Name,
|
||||
Summary,
|
||||
Content,
|
||||
Likes,
|
||||
Shares,
|
||||
Comments,
|
||||
Context,
|
||||
Cc,
|
||||
Bcc,
|
||||
To,
|
||||
Bto,
|
||||
Published,
|
||||
}
|
|
@ -1,44 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Relations::Table)
|
||||
.col(
|
||||
ColumnDef::new(Relations::Id)
|
||||
.integer()
|
||||
.auto_increment()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Relations::Follower).string().not_null())
|
||||
.col(ColumnDef::new(Relations::Following).string().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Relations::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Relations {
|
||||
Table,
|
||||
Id,
|
||||
Follower,
|
||||
Following,
|
||||
}
|
|
@ -1,80 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Likes::Table)
|
||||
.col(
|
||||
ColumnDef::new(Likes::Id)
|
||||
.integer()
|
||||
.auto_increment()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Likes::Actor).string().not_null())
|
||||
.col(ColumnDef::new(Likes::Likes).string().not_null())
|
||||
.col(ColumnDef::new(Likes::Date).date_time().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Shares::Table)
|
||||
.col(
|
||||
ColumnDef::new(Shares::Id)
|
||||
.integer()
|
||||
.auto_increment()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Shares::Actor).string().not_null())
|
||||
.col(ColumnDef::new(Shares::Shares).string().not_null())
|
||||
.col(ColumnDef::new(Shares::Date).date_time().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Likes::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Shares::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
enum Likes {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Likes,
|
||||
Date,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
enum Shares {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Shares,
|
||||
Date,
|
||||
}
|
|
@ -1,176 +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> {
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("user-domain-index")
|
||||
.table(Users::Table)
|
||||
.col(Users::Domain)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("activities-published-descending-index")
|
||||
.table(Activities::Table)
|
||||
.col((Activities::Published, IndexOrder::Desc))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("activities-actor-index")
|
||||
.table(Activities::Table)
|
||||
.col(Activities::Actor)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("activities-object-index")
|
||||
.table(Activities::Table)
|
||||
.col(Activities::Object)
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("objects-attributed-to-index")
|
||||
.table(Objects::Table)
|
||||
.col(Objects::AttributedTo)
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("shares-actor-index")
|
||||
.table(Shares::Table)
|
||||
.col(Shares::Actor)
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("shares-shares-index")
|
||||
.table(Shares::Table)
|
||||
.col(Shares::Shares)
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("likes-actor-index")
|
||||
.table(Likes::Table)
|
||||
.col(Likes::Actor)
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("likes-likes-index")
|
||||
.table(Likes::Table)
|
||||
.col(Likes::Likes)
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("likes-actor-likes-index")
|
||||
.table(Likes::Table)
|
||||
.col(Likes::Actor)
|
||||
.col(Likes::Likes)
|
||||
.unique()
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_index(Index::drop().name("user-domain-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("activities-published-descending-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("activities-actor-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("activities-object-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("objects-attributed-to-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("shares-actor-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("shares-shares-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("likes-actor-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("likes-likes-index").to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("likes-actor-likes-index").to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
enum Likes {
|
||||
Table,
|
||||
Actor,
|
||||
Likes,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
enum Shares {
|
||||
Table,
|
||||
Actor,
|
||||
Shares,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
Domain,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Activities {
|
||||
Table,
|
||||
Actor,
|
||||
Object,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Objects {
|
||||
Table,
|
||||
AttributedTo,
|
||||
}
|
|
@ -1,49 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Configs::Table)
|
||||
.col(
|
||||
ColumnDef::new(Configs::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Configs::AcceptFollowRequests).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowersCount).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowingCount).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowers).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowing).boolean().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Configs::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Configs {
|
||||
Table,
|
||||
Id,
|
||||
AcceptFollowRequests,
|
||||
ShowFollowersCount,
|
||||
ShowFollowingCount,
|
||||
ShowFollowers,
|
||||
ShowFollowing,
|
||||
}
|
|
@ -1,67 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Credentials::Table)
|
||||
.col(
|
||||
ColumnDef::new(Credentials::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Credentials::Email).string().not_null())
|
||||
.col(ColumnDef::new(Credentials::Password).string().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Sessions::Table)
|
||||
.col(
|
||||
ColumnDef::new(Sessions::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Sessions::Actor).string().not_null())
|
||||
.col(ColumnDef::new(Sessions::Expires).date_time().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Credentials::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Credentials {
|
||||
Table,
|
||||
Id,
|
||||
Email,
|
||||
Password,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Sessions {
|
||||
Table,
|
||||
Id, // TODO here ID is the session "secret" but in Credentials it's the actor ID (String) ??? weird!!
|
||||
Actor,
|
||||
Expires,
|
||||
}
|
|
@ -1,110 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Addressing::Table)
|
||||
.col(
|
||||
ColumnDef::new(Addressing::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Addressing::Actor).string().not_null())
|
||||
.col(ColumnDef::new(Addressing::Server).string().not_null())
|
||||
.col(ColumnDef::new(Addressing::Activity).string().null())
|
||||
.col(ColumnDef::new(Addressing::Object).string().null())
|
||||
.col(ColumnDef::new(Addressing::Published).date_time().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
// TODO these indexes may not be ordered, killing out timeline query performance
|
||||
// it may be necessary to include datetime in the index itself? or maybe specify
|
||||
// some ordering to use another type of indes?
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-actor-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Actor)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-server-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Server)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-activity-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Activity)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-object-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Object)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Addressing::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-actor-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-server-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-activity-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-object-index").to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Addressing {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Server,
|
||||
Activity,
|
||||
Object,
|
||||
Published,
|
||||
}
|
|
@ -1,66 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Deliveries::Table)
|
||||
.col(
|
||||
ColumnDef::new(Deliveries::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Deliveries::Actor).string().not_null())
|
||||
.col(ColumnDef::new(Deliveries::Target).string().not_null())
|
||||
.col(ColumnDef::new(Deliveries::Activity).string().not_null())
|
||||
.col(ColumnDef::new(Deliveries::Created).date_time().not_null())
|
||||
.col(ColumnDef::new(Deliveries::NotBefore).date_time().not_null())
|
||||
.col(ColumnDef::new(Deliveries::Attempt).integer().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("deliveries-notbefore-index")
|
||||
.table(Deliveries::Table)
|
||||
.col((Deliveries::NotBefore, IndexOrder::Asc))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Deliveries::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("deliveries-notbefore-index").to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Deliveries {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Target,
|
||||
Activity,
|
||||
Created,
|
||||
NotBefore,
|
||||
Attempt,
|
||||
}
|
|
@ -1,46 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Application::Table)
|
||||
.col(
|
||||
ColumnDef::new(Application::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Application::PrivateKey).string().not_null())
|
||||
.col(ColumnDef::new(Application::PublicKey).string().not_null())
|
||||
.col(ColumnDef::new(Application::Created).date_time().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Application::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Application {
|
||||
Table,
|
||||
Id,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
Created,
|
||||
}
|
|
@ -1,72 +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> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Users::Table)
|
||||
.add_column(
|
||||
ColumnDef::new(Users::StatusesCount)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.add_column(
|
||||
ColumnDef::new(Objects::InReplyTo)
|
||||
.string()
|
||||
.null()
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Users::Table)
|
||||
.drop_column(Users::StatusesCount)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.drop_column(Objects::InReplyTo)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
StatusesCount,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Objects {
|
||||
Table,
|
||||
InReplyTo,
|
||||
}
|
|
@ -1,66 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Attachments::Table)
|
||||
.col(
|
||||
ColumnDef::new(Attachments::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Attachments::Url).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::Object).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::DocumentType).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::Name).string().null())
|
||||
.col(ColumnDef::new(Attachments::MediaType).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::Created).date_time().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("attachment-object-index")
|
||||
.table(Attachments::Table)
|
||||
.col(Attachments::Object)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Attachments::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("attachment-object-index").to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Attachments {
|
||||
Table,
|
||||
Id,
|
||||
Url,
|
||||
Object,
|
||||
DocumentType,
|
||||
Name,
|
||||
MediaType,
|
||||
Created,
|
||||
}
|
|
@ -1,45 +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> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.add_column(
|
||||
ColumnDef::new(Objects::Sensitive)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.drop_column(Objects::Sensitive)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Objects {
|
||||
Table,
|
||||
Sensitive,
|
||||
}
|
||||
|
|
@ -1,43 +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> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Relays::Table)
|
||||
.col(
|
||||
ColumnDef::new(Relays::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Relays::Accepted).boolean().not_null().default(false))
|
||||
.col(ColumnDef::new(Relays::Forwarding).boolean().not_null().default(false))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Relays::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Relays {
|
||||
Table,
|
||||
Id,
|
||||
Accepted,
|
||||
Forwarding,
|
||||
}
|
|
@ -1,40 +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> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.add_column(ColumnDef::new(Objects::Updated).date_time().null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.drop_column(Objects::Updated)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Objects {
|
||||
Table,
|
||||
Updated,
|
||||
}
|
||||
|
|
@ -1,40 +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> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.add_column(ColumnDef::new(Objects::Url).string().null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Objects::Table)
|
||||
.drop_column(Objects::Url)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Objects {
|
||||
Table,
|
||||
Url,
|
||||
}
|
||||
|
|
@ -1,82 +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> {
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-actor-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-actor-published-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Actor)
|
||||
.col(Addressing::Published)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-server-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-server-published-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Server)
|
||||
.col(Addressing::Published)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-actor-published-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-actor-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Actor)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("addressing-server-published-index").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("addressing-server-index")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Server)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Addressing {
|
||||
Table,
|
||||
Actor,
|
||||
Server,
|
||||
Published,
|
||||
}
|
|
@ -0,0 +1,375 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Actors {
|
||||
Table,
|
||||
Id,
|
||||
ApId,
|
||||
Instance,
|
||||
ActorType,
|
||||
Name,
|
||||
Summary,
|
||||
Image,
|
||||
Icon,
|
||||
PreferredUsername,
|
||||
Inbox,
|
||||
SharedInbox,
|
||||
Outbox,
|
||||
Following,
|
||||
FollowingCount,
|
||||
Followers,
|
||||
FollowersCount,
|
||||
StatusesCount,
|
||||
PublicKey,
|
||||
PrivateKey,
|
||||
Created,
|
||||
Updated,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Activities {
|
||||
Table,
|
||||
Id,
|
||||
ApId,
|
||||
ActivityType,
|
||||
Actor,
|
||||
Object,
|
||||
Target,
|
||||
Cc,
|
||||
Bcc,
|
||||
To,
|
||||
Bto,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Objects {
|
||||
Table,
|
||||
Id,
|
||||
ApId,
|
||||
ObjectType,
|
||||
AttributedTo,
|
||||
Name,
|
||||
Summary,
|
||||
Content,
|
||||
Sensitive,
|
||||
Url,
|
||||
Likes,
|
||||
Announces,
|
||||
Replies,
|
||||
Context,
|
||||
InReplyTo,
|
||||
Cc,
|
||||
Bcc,
|
||||
To,
|
||||
Bto,
|
||||
Published,
|
||||
Updated,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Instances {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
Domain,
|
||||
Software,
|
||||
Version,
|
||||
DownSince,
|
||||
Users,
|
||||
Posts,
|
||||
Published,
|
||||
Updated,
|
||||
}
|
||||
|
||||
|
||||
#[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(Actors::Table)
|
||||
.comment("main actors table, with users and applications")
|
||||
.col(
|
||||
ColumnDef::new(Actors::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Actors::ApId).string().not_null().unique_key())
|
||||
.col(ColumnDef::new(Actors::ActorType).string().not_null())
|
||||
.col(ColumnDef::new(Actors::Instance).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-actors-instances")
|
||||
.from(Actors::Table, Actors::Instance)
|
||||
.to(Instances::Table, Instances::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Actors::Name).string().null())
|
||||
.col(ColumnDef::new(Actors::Summary).string().null())
|
||||
.col(ColumnDef::new(Actors::Image).string().null())
|
||||
.col(ColumnDef::new(Actors::Icon).string().null())
|
||||
.col(ColumnDef::new(Actors::PreferredUsername).string().not_null().unique_key())
|
||||
.col(ColumnDef::new(Actors::Inbox).string().null())
|
||||
.col(ColumnDef::new(Actors::SharedInbox).string().null())
|
||||
.col(ColumnDef::new(Actors::Outbox).string().null())
|
||||
.col(ColumnDef::new(Actors::Following).string().null())
|
||||
.col(ColumnDef::new(Actors::Followers).string().null())
|
||||
.col(ColumnDef::new(Actors::FollowingCount).integer().not_null().default(0))
|
||||
.col(ColumnDef::new(Actors::FollowersCount).integer().not_null().default(0))
|
||||
.col(ColumnDef::new(Actors::StatusesCount).integer().not_null().default(0))
|
||||
.col(ColumnDef::new(Actors::PublicKey).string().not_null())
|
||||
.col(ColumnDef::new(Actors::PrivateKey).string().null())
|
||||
.col(ColumnDef::new(Actors::Created).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.col(ColumnDef::new(Actors::Updated).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().unique().name("index-actors-ap-id").table(Actors::Table).col(Actors::ApId).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().unique().name("index-actors-preferred-username").table(Actors::Table).col(Actors::PreferredUsername).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-actors-instance").table(Actors::Table).col(Actors::Instance).to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Activities::Table)
|
||||
.comment("all activities this instance ever received or generated")
|
||||
.col(
|
||||
ColumnDef::new(Activities::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Activities::ApId).string().not_null().unique_key())
|
||||
.col(ColumnDef::new(Activities::ActivityType).string().not_null())
|
||||
.col(ColumnDef::new(Activities::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-activities-actors")
|
||||
.from(Activities::Table, Activities::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Activities::Object).integer().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-activities-objects")
|
||||
.from(Activities::Table, Activities::Object)
|
||||
.to(Objects::Table, Objects::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Activities::Target).string().null())
|
||||
.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().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().unique().name("index-activities-ap-id").table(Activities::Table).col(Activities::ApId).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-activities-actor").table(Activities::Table).col(Activities::Actor).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("activities-object-index").table(Activities::Table).col(Activities::Object).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-activities-published-descending").table(Activities::Table).col((Activities::Published, IndexOrder::Desc)).to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Objects::Table)
|
||||
.comment("objects are all AP documents which are neither actors nor activities")
|
||||
.col(
|
||||
ColumnDef::new(Objects::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Objects::ApId).string().not_null().unique_key())
|
||||
.col(ColumnDef::new(Objects::ObjectType).string().not_null())
|
||||
.col(ColumnDef::new(Objects::AttributedTo).integer().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-objects-attributed-to")
|
||||
.from(Objects::Table, Objects::AttributedTo)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.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::Sensitive).boolean().not_null().default(false))
|
||||
.col(ColumnDef::new(Objects::InReplyTo).string().null())
|
||||
.col(ColumnDef::new(Objects::Url).string().null())
|
||||
.col(ColumnDef::new(Objects::Likes).integer().not_null().default(0))
|
||||
.col(ColumnDef::new(Objects::Announces).integer().not_null().default(0))
|
||||
.col(ColumnDef::new(Objects::Replies).integer().not_null().default(0))
|
||||
.col(ColumnDef::new(Objects::Context).string().null())
|
||||
.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())
|
||||
.col(ColumnDef::new(Objects::Published).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.col(ColumnDef::new(Objects::Updated).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().unique().name("index-objects-ap-id").table(Objects::Table).col(Objects::ApId).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-objects-attributed-to").table(Objects::Table).col(Objects::AttributedTo).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-objects-in-reply-to").table(Objects::Table).col(Objects::InReplyTo).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-objects-content-text").table(Objects::Table).col(Objects::Content).full_text().to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-objects-context").table(Objects::Table).col(Objects::Context).to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Instances::Table)
|
||||
.comment("known other instances in the fediverse")
|
||||
.col(
|
||||
ColumnDef::new(Instances::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Instances::Name).string().null())
|
||||
.col(ColumnDef::new(Instances::Domain).string().not_null())
|
||||
.col(ColumnDef::new(Instances::Software).string().null())
|
||||
.col(ColumnDef::new(Instances::Version).string().null())
|
||||
.col(ColumnDef::new(Instances::DownSince).date_time().null())
|
||||
.col(ColumnDef::new(Instances::Users).integer().null())
|
||||
.col(ColumnDef::new(Instances::Posts).integer().null())
|
||||
.col(ColumnDef::new(Instances::Published).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.col(ColumnDef::new(Instances::Updated).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-instances-domain").table(Instances::Table).col(Instances::Domain).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Actors::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-actors-ap-id").table(Actors::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-actors-preferred-username").table(Actors::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-actors-instance").table(Actors::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Activities::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-activities-ap-id").table(Activities::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-activities-actor").table(Activities::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("activities-object-index").table(Activities::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-activities-published-descending").table(Activities::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Objects::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-objects-ap-id").table(Objects::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-objects-attributed-to").table(Objects::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-objects-in-reply-to").table(Objects::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-objects-content-text").table(Objects::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-objects-context").table(Objects::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Instances::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-instances-domain").table(Instances::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
239
src/migrations/m20240524_000002_create_relations_likes_shares.rs
Normal file
239
src/migrations/m20240524_000002_create_relations_likes_shares.rs
Normal file
|
@ -0,0 +1,239 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use super::m20240524_000001_create_actor_activity_object_tables::{Activities, Actors, Objects};
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Relations {
|
||||
Table,
|
||||
Id,
|
||||
Follower,
|
||||
Following,
|
||||
Activity,
|
||||
Accept,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum Likes {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Likes,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum Announces {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Announces,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[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(Relations::Table)
|
||||
.comment("follow relations between actors (applications too! for relays)")
|
||||
.col(
|
||||
ColumnDef::new(Relations::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Relations::Follower).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-relations-follower")
|
||||
.from(Relations::Table, Relations::Follower)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Relations::Following).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-relations-following")
|
||||
.from(Relations::Table, Relations::Following)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Relations::Accept).integer().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-relations-accept")
|
||||
.from(Relations::Table, Relations::Accept)
|
||||
.to(Activities::Table, Activities::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Relations::Activity).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-relations-activity")
|
||||
.from(Relations::Table, Relations::Activity)
|
||||
.to(Activities::Table, Activities::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-relations-follower").table(Relations::Table).col(Relations::Follower).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-relations-following").table(Relations::Table).col(Relations::Following).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Likes::Table)
|
||||
.comment("all like events, joining actor to object")
|
||||
.col(
|
||||
ColumnDef::new(Likes::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Likes::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-likes-actor")
|
||||
.from(Likes::Table, Likes::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Likes::Likes).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-likes-likes")
|
||||
.from(Likes::Table, Likes::Likes)
|
||||
.to(Objects::Table, Objects::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Likes::Published).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-likes-actor").table(Likes::Table).col(Likes::Actor).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-likes-likes").table(Likes::Table).col(Likes::Likes).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.unique()
|
||||
.name("index-likes-actor-likes")
|
||||
.table(Likes::Table)
|
||||
.col(Likes::Actor)
|
||||
.col(Likes::Likes)
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Announces::Table)
|
||||
.comment("all share/boost/reblog events, joining actor to object")
|
||||
.col(
|
||||
ColumnDef::new(Announces::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Announces::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-announces-actor")
|
||||
.from(Announces::Table, Announces::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Announces::Announces).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-announces-announces")
|
||||
.from(Announces::Table, Announces::Announces)
|
||||
.to(Objects::Table, Objects::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Announces::Published).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-announces-actor").table(Announces::Table).col(Announces::Actor).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-announces-announces").table(Announces::Table).col(Announces::Announces).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Relations::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-relations-follower").table(Relations::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-relations-following").table(Relations::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Likes::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-likes-actor").table(Likes::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-likes-likes").table(Likes::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-likes-actor-likes").table(Likes::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Announces::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("shares-actor-index").table(Announces::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_index(Index::drop().name("shares-shares-index").table(Announces::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
167
src/migrations/m20240524_000003_create_users_auth_and_config.rs
Normal file
167
src/migrations/m20240524_000003_create_users_auth_and_config.rs
Normal file
|
@ -0,0 +1,167 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use super::m20240524_000001_create_actor_activity_object_tables::Actors;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Configs {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
AcceptFollowRequests,
|
||||
ShowFollowersCount,
|
||||
ShowFollowingCount,
|
||||
ShowFollowers,
|
||||
ShowFollowing,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Credentials {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Login,
|
||||
Password,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Sessions {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Secret,
|
||||
Expires,
|
||||
}
|
||||
|
||||
#[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(Configs::Table)
|
||||
.comment("configuration for each local user")
|
||||
.col(
|
||||
ColumnDef::new(Configs::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Configs::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-config-actor")
|
||||
.from(Configs::Table, Configs::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Configs::AcceptFollowRequests).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowersCount).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowingCount).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowers).boolean().not_null())
|
||||
.col(ColumnDef::new(Configs::ShowFollowing).boolean().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-configs-actor").table(Configs::Table).col(Configs::Actor).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Credentials::Table)
|
||||
.comment("simple login credentials to authenticate local users")
|
||||
.col(
|
||||
ColumnDef::new(Credentials::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Credentials::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-credentials-actor")
|
||||
.from(Credentials::Table, Credentials::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Credentials::Login).string().not_null())
|
||||
.col(ColumnDef::new(Credentials::Password).string().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-credentials-login").table(Credentials::Table).col(Credentials::Login).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Sessions::Table)
|
||||
.comment("authenticated sessions from local users")
|
||||
.col(
|
||||
ColumnDef::new(Sessions::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Sessions::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-sessions-actor")
|
||||
.from(Sessions::Table, Sessions::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Sessions::Secret).string().not_null())
|
||||
.col(ColumnDef::new(Sessions::Expires).date_time().not_null())
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-sessions-secret").table(Sessions::Table).col(Sessions::Secret).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Configs::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-configs-actor").table(Configs::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Credentials::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-credentials-login").table(Credentials::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Sessions::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-sessions-secret").table(Sessions::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
195
src/migrations/m20240524_000004_create_addressing_deliveries.rs
Normal file
195
src/migrations/m20240524_000004_create_addressing_deliveries.rs
Normal file
|
@ -0,0 +1,195 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use super::m20240524_000001_create_actor_activity_object_tables::{Activities, Actors, Instances, Objects};
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Addressing {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Instance,
|
||||
Activity,
|
||||
Object,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Deliveries {
|
||||
Table,
|
||||
Id,
|
||||
Actor,
|
||||
Target,
|
||||
Activity,
|
||||
Created,
|
||||
NotBefore,
|
||||
Attempt,
|
||||
}
|
||||
|
||||
#[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(Addressing::Table)
|
||||
.comment("this join table contains all addressing relations, serving effectively as permissions truth table")
|
||||
.col(
|
||||
ColumnDef::new(Addressing::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Addressing::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-addressing-actor")
|
||||
.from(Addressing::Table, Addressing::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Addressing::Instance).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-addressing-instance")
|
||||
.from(Addressing::Table, Addressing::Instance)
|
||||
.to(Instances::Table, Instances::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Addressing::Activity).integer().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-addressing-activity")
|
||||
.from(Addressing::Table, Addressing::Activity)
|
||||
.to(Activities::Table, Activities::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Addressing::Object).string().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-addressing-object")
|
||||
.from(Addressing::Table, Addressing::Object)
|
||||
.to(Objects::Table, Objects::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Addressing::Published).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("index-addressing-actor-published")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Actor)
|
||||
.col(Addressing::Published)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("index-addressing-instance-published")
|
||||
.table(Addressing::Table)
|
||||
.col(Addressing::Instance)
|
||||
.col(Addressing::Published)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-addressing-activity").table(Addressing::Table).col(Addressing::Activity).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-addressing-object").table(Addressing::Table).col(Addressing::Object).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Deliveries::Table)
|
||||
.comment("this table contains all enqueued outgoing delivery jobs")
|
||||
.col(
|
||||
ColumnDef::new(Deliveries::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
)
|
||||
.col(ColumnDef::new(Deliveries::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-deliveries-actor")
|
||||
.from(Deliveries::Table, Deliveries::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Deliveries::Target).string().not_null())
|
||||
.col(ColumnDef::new(Deliveries::Activity).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-deliveries-activity")
|
||||
.from(Deliveries::Table, Deliveries::Activity)
|
||||
.to(Activities::Table, Activities::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Deliveries::Created).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.col(ColumnDef::new(Deliveries::NotBefore).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.col(ColumnDef::new(Deliveries::Attempt).integer().not_null().default(0))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("index-deliveries-not-before")
|
||||
.table(Deliveries::Table)
|
||||
.col((Deliveries::NotBefore, IndexOrder::Asc))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Addressing::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-addressing-actor").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-addressing-server").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-addressing-activity").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-addressing-object").to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Deliveries::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-deliveries-not-before").to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use super::m20240524_000001_create_actor_activity_object_tables::{Actors, Objects};
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Attachments {
|
||||
Table,
|
||||
Id,
|
||||
DocumentType,
|
||||
Url,
|
||||
Object,
|
||||
Name,
|
||||
MediaType,
|
||||
Created,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Mentions {
|
||||
Table,
|
||||
Id,
|
||||
Object,
|
||||
Actor,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Hashtags {
|
||||
Table,
|
||||
Id,
|
||||
Object,
|
||||
Name,
|
||||
Published,
|
||||
}
|
||||
|
||||
#[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(Attachments::Table)
|
||||
.comment("media attachments related to objects")
|
||||
.col(
|
||||
ColumnDef::new(Attachments::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Attachments::Url).string().not_null().unique_key())
|
||||
.col(ColumnDef::new(Attachments::Object).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-attachments-object")
|
||||
.from(Attachments::Table, Attachments::Object)
|
||||
.to(Objects::Table, Objects::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Attachments::DocumentType).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::Name).string().null())
|
||||
.col(ColumnDef::new(Attachments::MediaType).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::Created).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-attachment-object").table(Attachments::Table).col(Attachments::Object).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Mentions::Table)
|
||||
.comment("join table relating posts to mentioned users")
|
||||
.col(
|
||||
ColumnDef::new(Mentions::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Mentions::Object).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-mentions-object")
|
||||
.from(Mentions::Table, Mentions::Object)
|
||||
.to(Objects::Table, Objects::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Mentions::Actor).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-mentions-actor")
|
||||
.from(Mentions::Table, Mentions::Actor)
|
||||
.to(Actors::Table, Actors::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Mentions::Published).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-mentions-object").table(Mentions::Table).col(Mentions::Object).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("index-mentions-actor-published")
|
||||
.table(Mentions::Table)
|
||||
.col(Mentions::Actor)
|
||||
.col((Mentions::Published, IndexOrder::Desc))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Hashtags::Table)
|
||||
.comment("join table relating posts to hashtags")
|
||||
.col(
|
||||
ColumnDef::new(Hashtags::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
.auto_increment()
|
||||
)
|
||||
.col(ColumnDef::new(Hashtags::Object).integer().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fkey-hashtags-object")
|
||||
.from(Hashtags::Table, Hashtags::Object)
|
||||
.to(Objects::Table, Objects::Id)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
)
|
||||
.col(ColumnDef::new(Hashtags::Name).string().not_null())
|
||||
.col(ColumnDef::new(Hashtags::Published).date_time().not_null().default(Expr::current_timestamp()))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(Index::create().name("index-hashtags-object").table(Hashtags::Table).col(Hashtags::Object).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("index-hashtags-name-published")
|
||||
.table(Hashtags::Table)
|
||||
.col(Hashtags::Name)
|
||||
.col((Hashtags::Published, IndexOrder::Desc))
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Attachments::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-attachment-object").to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Mentions::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-mentions-object").table(Mentions::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-mentions-actor-published").table(Mentions::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Hashtags::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-hashtags-object").table(Hashtags::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(Index::drop().name("index-hashtags-name-published").table(Hashtags::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,21 +1,10 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20240316_000001_create_table;
|
||||
mod m20240322_000001_create_relations;
|
||||
mod m20240322_000002_add_likes_shares;
|
||||
mod m20240322_000003_add_indexes;
|
||||
mod m20240323_000001_add_user_configs;
|
||||
mod m20240323_000002_add_simple_credentials;
|
||||
mod m20240324_000001_add_addressing;
|
||||
mod m20240325_000001_add_deliveries;
|
||||
mod m20240325_000002_add_system_key;
|
||||
mod m20240418_000001_add_statuses_and_reply_to;
|
||||
mod m20240421_000001_add_attachments;
|
||||
mod m20240424_000001_add_sensitive_field;
|
||||
mod m20240429_000001_add_relays_table;
|
||||
mod m20240502_000001_add_object_updated;
|
||||
mod m20240512_000001_add_url_to_objects;
|
||||
mod m20240520_000001_add_published_to_addressing_actor_index;
|
||||
mod m20240524_000001_create_actor_activity_object_tables;
|
||||
mod m20240524_000002_create_relations_likes_shares;
|
||||
mod m20240524_000003_create_users_auth_and_config;
|
||||
mod m20240524_000004_create_addressing_deliveries;
|
||||
mod m20240524_000005_create_attachments_tags_mentions;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
@ -23,22 +12,11 @@ pub struct Migrator;
|
|||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20240316_000001_create_table::Migration),
|
||||
Box::new(m20240322_000001_create_relations::Migration),
|
||||
Box::new(m20240322_000002_add_likes_shares::Migration),
|
||||
Box::new(m20240322_000003_add_indexes::Migration),
|
||||
Box::new(m20240323_000001_add_user_configs::Migration),
|
||||
Box::new(m20240323_000002_add_simple_credentials::Migration),
|
||||
Box::new(m20240324_000001_add_addressing::Migration),
|
||||
Box::new(m20240325_000001_add_deliveries::Migration),
|
||||
Box::new(m20240325_000002_add_system_key::Migration),
|
||||
Box::new(m20240418_000001_add_statuses_and_reply_to::Migration),
|
||||
Box::new(m20240421_000001_add_attachments::Migration),
|
||||
Box::new(m20240424_000001_add_sensitive_field::Migration),
|
||||
Box::new(m20240429_000001_add_relays_table::Migration),
|
||||
Box::new(m20240502_000001_add_object_updated::Migration),
|
||||
Box::new(m20240512_000001_add_url_to_objects::Migration),
|
||||
Box::new(m20240520_000001_add_published_to_addressing_actor_index::Migration),
|
||||
Box::new(m20240524_000001_create_actor_activity_object_tables::Migration),
|
||||
Box::new(m20240524_000002_create_relations_likes_shares::Migration),
|
||||
Box::new(m20240524_000003_create_users_auth_and_config::Migration),
|
||||
Box::new(m20240524_000004_create_addressing_deliveries::Migration),
|
||||
Box::new(m20240524_000005_create_attachments_tags_mentions::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue