This commit is contained in:
parent
cc8fcd682b
commit
91db5861c8
21 changed files with 1263 additions and 79 deletions
|
|
@ -4,6 +4,7 @@ mod m20220101_000001_create_table;
|
|||
mod m20260210_000002_add_answer_column;
|
||||
mod m20260210_000003_separate_runs;
|
||||
mod m20260210_000004_add_cron_column;
|
||||
mod m20260212_000005_notifications;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
|
|||
Box::new(m20260210_000002_add_answer_column::Migration),
|
||||
Box::new(m20260210_000003_separate_runs::Migration),
|
||||
Box::new(m20260210_000004_add_cron_column::Migration),
|
||||
Box::new(m20260212_000005_notifications::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
115
migration/src/m20260212_000005_notifications.rs
Normal file
115
migration/src/m20260212_000005_notifications.rs
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
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> {
|
||||
// Push Subscriptions table
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(PushSubscriptions::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(PushSubscriptions::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(PushSubscriptions::UserSub)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(PushSubscriptions::Endpoint)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(PushSubscriptions::P256dh)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(PushSubscriptions::Auth).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(PushSubscriptions::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Task Subscriptions table
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(TaskSubscriptions::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(TaskSubscriptions::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(TaskSubscriptions::UserSub)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(TaskSubscriptions::TaskId).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(TaskSubscriptions::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-task-subscription-task-id")
|
||||
.from(TaskSubscriptions::Table, TaskSubscriptions::TaskId)
|
||||
.to(Tasks::Table, Tasks::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(TaskSubscriptions::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(PushSubscriptions::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum PushSubscriptions {
|
||||
Table,
|
||||
Id,
|
||||
UserSub,
|
||||
Endpoint,
|
||||
P256dh,
|
||||
Auth,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum TaskSubscriptions {
|
||||
Table,
|
||||
Id,
|
||||
UserSub,
|
||||
TaskId,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Tasks {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue