This commit is contained in:
parent
cfef57d8a1
commit
e1dd679c47
19 changed files with 1807 additions and 73 deletions
|
|
@ -11,13 +11,13 @@ impl MigrationTrait for Migration {
|
|||
Table::create()
|
||||
.table(Users::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(Users::Id).uuid().not_null().primary_key())
|
||||
.col(
|
||||
ColumnDef::new(Users::Id)
|
||||
.uuid()
|
||||
ColumnDef::new(Users::OidcSub)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Users::OidcSub).string().not_null().unique_key())
|
||||
.col(ColumnDef::new(Users::Email).string())
|
||||
.col(ColumnDef::new(Users::DisplayName).string().not_null())
|
||||
.col(ColumnDef::new(Users::AvatarUrl).string())
|
||||
|
|
@ -42,12 +42,7 @@ impl MigrationTrait for Migration {
|
|||
Table::create()
|
||||
.table(Guilds::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Guilds::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Guilds::Id).uuid().not_null().primary_key())
|
||||
.col(ColumnDef::new(Guilds::Name).string().not_null())
|
||||
.col(ColumnDef::new(Guilds::OwnerUserId).uuid().not_null())
|
||||
.col(
|
||||
|
|
@ -108,12 +103,7 @@ impl MigrationTrait for Migration {
|
|||
Table::create()
|
||||
.table(Channels::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Channels::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Channels::Id).uuid().not_null().primary_key())
|
||||
.col(ColumnDef::new(Channels::GuildId).uuid().not_null())
|
||||
.col(ColumnDef::new(Channels::Name).string().not_null())
|
||||
.col(
|
||||
|
|
@ -138,12 +128,7 @@ impl MigrationTrait for Migration {
|
|||
Table::create()
|
||||
.table(Messages::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Messages::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Messages::Id).uuid().not_null().primary_key())
|
||||
.col(ColumnDef::new(Messages::ChannelId).uuid().not_null())
|
||||
.col(ColumnDef::new(Messages::AuthorUserId).uuid().not_null())
|
||||
.col(ColumnDef::new(Messages::Body).text().not_null())
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@ impl MigrationTrait for Migration {
|
|||
Table::create()
|
||||
.table(Invites::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(Invites::Code).string().not_null().primary_key())
|
||||
.col(
|
||||
ColumnDef::new(Invites::Code)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Invites::GuildId).uuid().not_null())
|
||||
.col(ColumnDef::new(Invites::CreatedByUserId).uuid().not_null())
|
||||
.col(
|
||||
|
|
|
|||
|
|
@ -17,8 +17,16 @@ impl MigrationTrait for Migration {
|
|||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(DirectMessages::SenderUserId).uuid().not_null())
|
||||
.col(ColumnDef::new(DirectMessages::RecipientUserId).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(DirectMessages::SenderUserId)
|
||||
.uuid()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(DirectMessages::RecipientUserId)
|
||||
.uuid()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(DirectMessages::Body).text().not_null())
|
||||
.col(
|
||||
ColumnDef::new(DirectMessages::CreatedAt)
|
||||
|
|
|
|||
122
src/migration/m20260227_000006_attachments.rs
Normal file
122
src/migration/m20260227_000006_attachments.rs
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
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)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Attachments::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Attachments::ChannelMessageId).uuid().null())
|
||||
.col(ColumnDef::new(Attachments::DirectMessageId).uuid().null())
|
||||
.col(ColumnDef::new(Attachments::UploaderUserId).uuid().not_null())
|
||||
.col(ColumnDef::new(Attachments::ObjectKey).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::MediaUrl).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::MimeType).string().not_null())
|
||||
.col(ColumnDef::new(Attachments::SizeBytes).big_integer().not_null())
|
||||
.col(ColumnDef::new(Attachments::OriginalFilename).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(Attachments::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_attachments_channel_message")
|
||||
.from(Attachments::Table, Attachments::ChannelMessageId)
|
||||
.to(Messages::Table, Messages::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_attachments_direct_message")
|
||||
.from(Attachments::Table, Attachments::DirectMessageId)
|
||||
.to(DirectMessages::Table, DirectMessages::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_attachments_uploader")
|
||||
.from(Attachments::Table, Attachments::UploaderUserId)
|
||||
.to(Users::Table, Users::Id),
|
||||
)
|
||||
.check(
|
||||
Expr::cust(
|
||||
"(channel_message_id IS NOT NULL AND direct_message_id IS NULL) OR (channel_message_id IS NULL AND direct_message_id IS NOT NULL)",
|
||||
),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_attachments_channel_message")
|
||||
.table(Attachments::Table)
|
||||
.col(Attachments::ChannelMessageId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_attachments_direct_message")
|
||||
.table(Attachments::Table)
|
||||
.col(Attachments::DirectMessageId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Attachments::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Attachments {
|
||||
Table,
|
||||
Id,
|
||||
ChannelMessageId,
|
||||
DirectMessageId,
|
||||
UploaderUserId,
|
||||
ObjectKey,
|
||||
MediaUrl,
|
||||
MimeType,
|
||||
SizeBytes,
|
||||
OriginalFilename,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Messages {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum DirectMessages {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ mod m20260213_000002_invites;
|
|||
mod m20260213_000003_channel_kind;
|
||||
mod m20260213_000004_direct_messages;
|
||||
mod m20260224_000005_soundboard;
|
||||
mod m20260227_000006_attachments;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
|
@ -17,6 +18,7 @@ impl MigratorTrait for Migrator {
|
|||
Box::new(m20260213_000003_channel_kind::Migration),
|
||||
Box::new(m20260213_000004_direct_messages::Migration),
|
||||
Box::new(m20260224_000005_soundboard::Migration),
|
||||
Box::new(m20260227_000006_attachments::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue