This commit is contained in:
parent
24975c2e0d
commit
3acd082fb0
28 changed files with 3454 additions and 836 deletions
107
src/migration/m20260227_000007_sessions.rs
Normal file
107
src/migration/m20260227_000007_sessions.rs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
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(Sessions::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Sessions::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Sessions::UserId).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(Sessions::ExpiresAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Sessions::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Sessions::LastSeenAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(Sessions::RevokedAt).timestamp_with_time_zone())
|
||||
.col(ColumnDef::new(Sessions::UserAgentHash).string())
|
||||
.col(ColumnDef::new(Sessions::IpHash).string())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_sessions_user")
|
||||
.from(Sessions::Table, Sessions::UserId)
|
||||
.to(Users::Table, Users::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_sessions_user_id")
|
||||
.table(Sessions::Table)
|
||||
.col(Sessions::UserId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_sessions_expires_at")
|
||||
.table(Sessions::Table)
|
||||
.col(Sessions::ExpiresAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_sessions_revoked_at")
|
||||
.table(Sessions::Table)
|
||||
.col(Sessions::RevokedAt)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Sessions::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Sessions {
|
||||
Table,
|
||||
Id,
|
||||
UserId,
|
||||
ExpiresAt,
|
||||
CreatedAt,
|
||||
LastSeenAt,
|
||||
RevokedAt,
|
||||
UserAgentHash,
|
||||
IpHash,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Users {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
72
src/migration/m20260227_000008_soundboard_media.rs
Normal file
72
src/migration/m20260227_000008_soundboard_media.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
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(SoundboardSounds::Table)
|
||||
.add_column(ColumnDef::new(SoundboardSounds::ObjectKey).string().null())
|
||||
.add_column(ColumnDef::new(SoundboardSounds::MediaUrl).string().null())
|
||||
.add_column(ColumnDef::new(SoundboardSounds::MimeType).string().null())
|
||||
.add_column(
|
||||
ColumnDef::new(SoundboardSounds::SizeBytes)
|
||||
.big_integer()
|
||||
.null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
UPDATE soundboard_sounds
|
||||
SET media_url = file_path
|
||||
WHERE media_url IS NULL
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(SoundboardSounds::Table)
|
||||
.modify_column(
|
||||
ColumnDef::new(SoundboardSounds::MediaUrl)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(SoundboardSounds::Table)
|
||||
.drop_column(SoundboardSounds::ObjectKey)
|
||||
.drop_column(SoundboardSounds::MediaUrl)
|
||||
.drop_column(SoundboardSounds::MimeType)
|
||||
.drop_column(SoundboardSounds::SizeBytes)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum SoundboardSounds {
|
||||
Table,
|
||||
ObjectKey,
|
||||
MediaUrl,
|
||||
MimeType,
|
||||
SizeBytes,
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
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(SoundboardSounds::Table)
|
||||
.modify_column(ColumnDef::new(SoundboardSounds::FilePath).string().null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
UPDATE soundboard_sounds
|
||||
SET file_path = media_url
|
||||
WHERE file_path IS NULL
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(SoundboardSounds::Table)
|
||||
.modify_column(
|
||||
ColumnDef::new(SoundboardSounds::FilePath)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum SoundboardSounds {
|
||||
Table,
|
||||
FilePath,
|
||||
}
|
||||
|
|
@ -6,6 +6,9 @@ mod m20260213_000003_channel_kind;
|
|||
mod m20260213_000004_direct_messages;
|
||||
mod m20260224_000005_soundboard;
|
||||
mod m20260227_000006_attachments;
|
||||
mod m20260227_000007_sessions;
|
||||
mod m20260227_000008_soundboard_media;
|
||||
mod m20260227_000009_soundboard_file_path_nullable;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
|
@ -19,6 +22,9 @@ impl MigratorTrait for Migrator {
|
|||
Box::new(m20260213_000004_direct_messages::Migration),
|
||||
Box::new(m20260224_000005_soundboard::Migration),
|
||||
Box::new(m20260227_000006_attachments::Migration),
|
||||
Box::new(m20260227_000007_sessions::Migration),
|
||||
Box::new(m20260227_000008_soundboard_media::Migration),
|
||||
Box::new(m20260227_000009_soundboard_file_path_nullable::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue