feat: ship blog platform admin and deploy stack

This commit is contained in:
2026-03-31 21:48:39 +08:00
parent a9a05aa105
commit 313f174fbc
210 changed files with 25476 additions and 5803 deletions

View File

@@ -25,6 +25,17 @@ mod m20260329_000014_create_query_events;
mod m20260330_000015_add_image_ai_settings_to_site_settings;
mod m20260330_000016_add_r2_media_settings_to_site_settings;
mod m20260330_000017_add_media_storage_provider_to_site_settings;
mod m20260331_000018_add_comment_request_metadata;
mod m20260331_000019_create_comment_blacklist;
mod m20260331_000020_create_comment_persona_analysis_logs;
mod m20260331_000021_add_post_lifecycle_and_seo;
mod m20260331_000022_add_site_settings_notifications_and_seo;
mod m20260331_000023_create_content_events;
mod m20260331_000024_create_admin_audit_logs;
mod m20260331_000025_create_post_revisions;
mod m20260331_000026_create_subscriptions;
mod m20260331_000027_create_notification_deliveries;
mod m20260331_000028_expand_subscriptions_and_deliveries;
pub struct Migrator;
#[async_trait::async_trait]
@@ -54,6 +65,17 @@ impl MigratorTrait for Migrator {
Box::new(m20260330_000015_add_image_ai_settings_to_site_settings::Migration),
Box::new(m20260330_000016_add_r2_media_settings_to_site_settings::Migration),
Box::new(m20260330_000017_add_media_storage_provider_to_site_settings::Migration),
Box::new(m20260331_000018_add_comment_request_metadata::Migration),
Box::new(m20260331_000019_create_comment_blacklist::Migration),
Box::new(m20260331_000020_create_comment_persona_analysis_logs::Migration),
Box::new(m20260331_000021_add_post_lifecycle_and_seo::Migration),
Box::new(m20260331_000022_add_site_settings_notifications_and_seo::Migration),
Box::new(m20260331_000023_create_content_events::Migration),
Box::new(m20260331_000024_create_admin_audit_logs::Migration),
Box::new(m20260331_000025_create_post_revisions::Migration),
Box::new(m20260331_000026_create_subscriptions::Migration),
Box::new(m20260331_000027_create_notification_deliveries::Migration),
Box::new(m20260331_000028_expand_subscriptions_and_deliveries::Migration),
// inject-above (do not remove this comment)
]
}

View File

@@ -0,0 +1,85 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
const TABLE: &str = "comments";
const IP_ADDRESS_COLUMN: &str = "ip_address";
const USER_AGENT_COLUMN: &str = "user_agent";
const REFERER_COLUMN: &str = "referer";
const COMMENT_IP_INDEX: &str = "idx_comments_ip_address";
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let table = Alias::new(TABLE);
if !manager.has_column(TABLE, IP_ADDRESS_COLUMN).await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new(IP_ADDRESS_COLUMN))
.string()
.null(),
)
.to_owned(),
)
.await?;
}
if !manager.has_column(TABLE, USER_AGENT_COLUMN).await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(ColumnDef::new(Alias::new(USER_AGENT_COLUMN)).text().null())
.to_owned(),
)
.await?;
}
if !manager.has_column(TABLE, REFERER_COLUMN).await? {
manager
.alter_table(
Table::alter()
.table(table)
.add_column(ColumnDef::new(Alias::new(REFERER_COLUMN)).text().null())
.to_owned(),
)
.await?;
}
manager
.get_connection()
.execute_unprepared(&format!(
"CREATE INDEX IF NOT EXISTS {COMMENT_IP_INDEX} ON {TABLE} ({IP_ADDRESS_COLUMN})"
))
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared(&format!("DROP INDEX IF EXISTS {COMMENT_IP_INDEX}"))
.await?;
for column in [REFERER_COLUMN, USER_AGENT_COLUMN, IP_ADDRESS_COLUMN] {
if manager.has_column(TABLE, column).await? {
manager
.alter_table(
Table::alter()
.table(Alias::new(TABLE))
.drop_column(Alias::new(column))
.to_owned(),
)
.await?;
}
}
Ok(())
}
}

View File

@@ -0,0 +1,103 @@
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(Alias::new("comment_blacklist"))
.if_not_exists()
.col(
ColumnDef::new(Alias::new("id"))
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(Alias::new("matcher_type"))
.string()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("matcher_value"))
.string()
.not_null(),
)
.col(ColumnDef::new(Alias::new("reason")).text().null())
.col(ColumnDef::new(Alias::new("active")).boolean().null())
.col(
ColumnDef::new(Alias::new("expires_at"))
.timestamp_with_time_zone()
.null(),
)
.col(
ColumnDef::new(Alias::new("created_at"))
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Alias::new("updated_at"))
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_comment_blacklist_matcher")
.table(Alias::new("comment_blacklist"))
.col(Alias::new("matcher_type"))
.col(Alias::new("matcher_value"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_comment_blacklist_active_expires")
.table(Alias::new("comment_blacklist"))
.col(Alias::new("active"))
.col(Alias::new("expires_at"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for index_name in [
"idx_comment_blacklist_active_expires",
"idx_comment_blacklist_matcher",
] {
manager
.drop_index(
Index::drop()
.name(index_name)
.table(Alias::new("comment_blacklist"))
.to_owned(),
)
.await?;
}
manager
.drop_table(
Table::drop()
.table(Alias::new("comment_blacklist"))
.if_exists()
.to_owned(),
)
.await
}
}

View File

@@ -0,0 +1,131 @@
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(Alias::new("comment_persona_analysis_logs"))
.if_not_exists()
.col(
ColumnDef::new(Alias::new("id"))
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(Alias::new("matcher_type"))
.string()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("matcher_value"))
.string()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("from_at"))
.timestamp_with_time_zone()
.null(),
)
.col(
ColumnDef::new(Alias::new("to_at"))
.timestamp_with_time_zone()
.null(),
)
.col(
ColumnDef::new(Alias::new("total_comments"))
.integer()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("pending_comments"))
.integer()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("distinct_posts"))
.integer()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("analysis_text"))
.text()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("sample_json"))
.json_binary()
.null(),
)
.col(
ColumnDef::new(Alias::new("created_at"))
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Alias::new("updated_at"))
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_comment_persona_analysis_logs_matcher_created_at")
.table(Alias::new("comment_persona_analysis_logs"))
.col(Alias::new("matcher_type"))
.col(Alias::new("matcher_value"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_comment_persona_analysis_logs_created_at")
.table(Alias::new("comment_persona_analysis_logs"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for index_name in [
"idx_comment_persona_analysis_logs_created_at",
"idx_comment_persona_analysis_logs_matcher_created_at",
] {
manager
.drop_index(
Index::drop()
.name(index_name)
.table(Alias::new("comment_persona_analysis_logs"))
.to_owned(),
)
.await?;
}
manager
.drop_table(
Table::drop()
.table(Alias::new("comment_persona_analysis_logs"))
.if_exists()
.to_owned(),
)
.await
}
}

View File

@@ -0,0 +1,168 @@
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> {
let table = Alias::new("posts");
if !manager.has_column("posts", "status").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("status"))
.string()
.null()
.default("published"),
)
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "visibility").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("visibility"))
.string()
.null()
.default("public"),
)
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "publish_at").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("publish_at"))
.timestamp_with_time_zone()
.null(),
)
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "unpublish_at").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("unpublish_at"))
.timestamp_with_time_zone()
.null(),
)
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "canonical_url").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(ColumnDef::new(Alias::new("canonical_url")).text().null())
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "noindex").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("noindex"))
.boolean()
.null()
.default(false),
)
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "og_image").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(ColumnDef::new(Alias::new("og_image")).text().null())
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "redirect_from").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("redirect_from"))
.json_binary()
.null(),
)
.to_owned(),
)
.await?;
}
if !manager.has_column("posts", "redirect_to").await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(ColumnDef::new(Alias::new("redirect_to")).text().null())
.to_owned(),
)
.await?;
}
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let table = Alias::new("posts");
for column in [
"redirect_to",
"redirect_from",
"og_image",
"noindex",
"canonical_url",
"unpublish_at",
"publish_at",
"visibility",
"status",
] {
if manager.has_column("posts", column).await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.drop_column(Alias::new(column))
.to_owned(),
)
.await?;
}
}
Ok(())
}
}

View File

@@ -0,0 +1,149 @@
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> {
let table = Alias::new("site_settings");
if !manager
.has_column("site_settings", "seo_default_og_image")
.await?
{
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("seo_default_og_image"))
.text()
.null(),
)
.to_owned(),
)
.await?;
}
if !manager
.has_column("site_settings", "seo_default_twitter_handle")
.await?
{
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("seo_default_twitter_handle"))
.string()
.null(),
)
.to_owned(),
)
.await?;
}
if !manager
.has_column("site_settings", "notification_webhook_url")
.await?
{
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("notification_webhook_url"))
.text()
.null(),
)
.to_owned(),
)
.await?;
}
if !manager
.has_column("site_settings", "notification_comment_enabled")
.await?
{
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("notification_comment_enabled"))
.boolean()
.null()
.default(false),
)
.to_owned(),
)
.await?;
}
if !manager
.has_column("site_settings", "notification_friend_link_enabled")
.await?
{
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("notification_friend_link_enabled"))
.boolean()
.null()
.default(false),
)
.to_owned(),
)
.await?;
}
if !manager
.has_column("site_settings", "search_synonyms")
.await?
{
manager
.alter_table(
Table::alter()
.table(table.clone())
.add_column(
ColumnDef::new(Alias::new("search_synonyms"))
.json_binary()
.null(),
)
.to_owned(),
)
.await?;
}
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let table = Alias::new("site_settings");
for column in [
"search_synonyms",
"notification_friend_link_enabled",
"notification_comment_enabled",
"notification_webhook_url",
"seo_default_twitter_handle",
"seo_default_og_image",
] {
if manager.has_column("site_settings", column).await? {
manager
.alter_table(
Table::alter()
.table(table.clone())
.drop_column(Alias::new(column))
.to_owned(),
)
.await?;
}
}
Ok(())
}
}

View File

@@ -0,0 +1,82 @@
use loco_rs::schema::*;
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> {
create_table(
manager,
"content_events",
&[
("id", ColType::PkAuto),
("event_type", ColType::String),
("path", ColType::String),
("post_slug", ColType::StringNull),
("session_id", ColType::StringNull),
("referrer", ColType::StringNull),
("user_agent", ColType::TextNull),
("duration_ms", ColType::IntegerNull),
("progress_percent", ColType::IntegerNull),
("metadata", ColType::JsonBinaryNull),
],
&[],
)
.await?;
manager
.create_index(
Index::create()
.name("idx_content_events_event_type_created_at")
.table(Alias::new("content_events"))
.col(Alias::new("event_type"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_content_events_post_slug_created_at")
.table(Alias::new("content_events"))
.col(Alias::new("post_slug"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_content_events_referrer")
.table(Alias::new("content_events"))
.col(Alias::new("referrer"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for index_name in [
"idx_content_events_referrer",
"idx_content_events_post_slug_created_at",
"idx_content_events_event_type_created_at",
] {
manager
.drop_index(
Index::drop()
.name(index_name)
.table(Alias::new("content_events"))
.to_owned(),
)
.await?;
}
drop_table(manager, "content_events").await
}
}

View File

@@ -0,0 +1,70 @@
use loco_rs::schema::*;
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> {
create_table(
manager,
"admin_audit_logs",
&[
("id", ColType::PkAuto),
("actor_username", ColType::StringNull),
("actor_email", ColType::StringNull),
("actor_source", ColType::StringNull),
("action", ColType::String),
("target_type", ColType::String),
("target_id", ColType::StringNull),
("target_label", ColType::StringNull),
("metadata", ColType::JsonBinaryNull),
],
&[],
)
.await?;
manager
.create_index(
Index::create()
.name("idx_admin_audit_logs_action_created_at")
.table(Alias::new("admin_audit_logs"))
.col(Alias::new("action"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_admin_audit_logs_target_type_created_at")
.table(Alias::new("admin_audit_logs"))
.col(Alias::new("target_type"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for index_name in [
"idx_admin_audit_logs_target_type_created_at",
"idx_admin_audit_logs_action_created_at",
] {
manager
.drop_index(
Index::drop()
.name(index_name)
.table(Alias::new("admin_audit_logs"))
.to_owned(),
)
.await?;
}
drop_table(manager, "admin_audit_logs").await
}
}

View File

@@ -0,0 +1,71 @@
use loco_rs::schema::*;
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> {
create_table(
manager,
"post_revisions",
&[
("id", ColType::PkAuto),
("post_slug", ColType::String),
("post_title", ColType::StringNull),
("operation", ColType::String),
("revision_reason", ColType::TextNull),
("actor_username", ColType::StringNull),
("actor_email", ColType::StringNull),
("actor_source", ColType::StringNull),
("markdown", ColType::TextNull),
("metadata", ColType::JsonBinaryNull),
],
&[],
)
.await?;
manager
.create_index(
Index::create()
.name("idx_post_revisions_post_slug_created_at")
.table(Alias::new("post_revisions"))
.col(Alias::new("post_slug"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_post_revisions_operation_created_at")
.table(Alias::new("post_revisions"))
.col(Alias::new("operation"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for index_name in [
"idx_post_revisions_operation_created_at",
"idx_post_revisions_post_slug_created_at",
] {
manager
.drop_index(
Index::drop()
.name(index_name)
.table(Alias::new("post_revisions"))
.to_owned(),
)
.await?;
}
drop_table(manager, "post_revisions").await
}
}

View File

@@ -0,0 +1,74 @@
use loco_rs::schema::*;
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> {
create_table(
manager,
"subscriptions",
&[
("id", ColType::PkAuto),
("channel_type", ColType::String),
("target", ColType::String),
("display_name", ColType::StringNull),
("status", ColType::String),
("filters", ColType::JsonBinaryNull),
("secret", ColType::TextNull),
("notes", ColType::TextNull),
("verified_at", ColType::StringNull),
("last_notified_at", ColType::StringNull),
("failure_count", ColType::IntegerNull),
("last_delivery_status", ColType::StringNull),
],
&[],
)
.await?;
manager
.create_index(
Index::create()
.name("idx_subscriptions_channel_status")
.table(Alias::new("subscriptions"))
.col(Alias::new("channel_type"))
.col(Alias::new("status"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_subscriptions_channel_target_unique")
.table(Alias::new("subscriptions"))
.col(Alias::new("channel_type"))
.col(Alias::new("target"))
.unique()
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for index_name in [
"idx_subscriptions_channel_target_unique",
"idx_subscriptions_channel_status",
] {
manager
.drop_index(
Index::drop()
.name(index_name)
.table(Alias::new("subscriptions"))
.to_owned(),
)
.await?;
}
drop_table(manager, "subscriptions").await
}
}

View File

@@ -0,0 +1,71 @@
use loco_rs::schema::*;
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> {
create_table(
manager,
"notification_deliveries",
&[
("id", ColType::PkAuto),
("subscription_id", ColType::IntegerNull),
("channel_type", ColType::String),
("target", ColType::String),
("event_type", ColType::String),
("status", ColType::String),
("provider", ColType::StringNull),
("response_text", ColType::TextNull),
("payload", ColType::JsonBinaryNull),
("delivered_at", ColType::StringNull),
],
&[],
)
.await?;
manager
.create_index(
Index::create()
.name("idx_notification_deliveries_event_created_at")
.table(Alias::new("notification_deliveries"))
.col(Alias::new("event_type"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_notification_deliveries_subscription_created_at")
.table(Alias::new("notification_deliveries"))
.col(Alias::new("subscription_id"))
.col(Alias::new("created_at"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for index_name in [
"idx_notification_deliveries_subscription_created_at",
"idx_notification_deliveries_event_created_at",
] {
manager
.drop_index(
Index::drop()
.name(index_name)
.table(Alias::new("notification_deliveries"))
.to_owned(),
)
.await?;
}
drop_table(manager, "notification_deliveries").await
}
}

View File

@@ -0,0 +1,144 @@
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(Alias::new("subscriptions"))
.add_column_if_not_exists(
ColumnDef::new(Alias::new("confirm_token"))
.string()
.null(),
)
.add_column_if_not_exists(
ColumnDef::new(Alias::new("manage_token"))
.string()
.null(),
)
.add_column_if_not_exists(
ColumnDef::new(Alias::new("metadata"))
.json_binary()
.null(),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_subscriptions_confirm_token_unique")
.table(Alias::new("subscriptions"))
.col(Alias::new("confirm_token"))
.unique()
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_subscriptions_manage_token_unique")
.table(Alias::new("subscriptions"))
.col(Alias::new("manage_token"))
.unique()
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Alias::new("notification_deliveries"))
.add_column_if_not_exists(
ColumnDef::new(Alias::new("attempts_count"))
.integer()
.not_null()
.default(0),
)
.add_column_if_not_exists(
ColumnDef::new(Alias::new("next_retry_at"))
.string()
.null(),
)
.add_column_if_not_exists(
ColumnDef::new(Alias::new("last_attempt_at"))
.string()
.null(),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_notification_deliveries_status_next_retry")
.table(Alias::new("notification_deliveries"))
.col(Alias::new("status"))
.col(Alias::new("next_retry_at"))
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_index(
Index::drop()
.name("idx_notification_deliveries_status_next_retry")
.table(Alias::new("notification_deliveries"))
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Alias::new("notification_deliveries"))
.drop_column(Alias::new("last_attempt_at"))
.drop_column(Alias::new("next_retry_at"))
.drop_column(Alias::new("attempts_count"))
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.name("idx_subscriptions_manage_token_unique")
.table(Alias::new("subscriptions"))
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.name("idx_subscriptions_confirm_token_unique")
.table(Alias::new("subscriptions"))
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Alias::new("subscriptions"))
.drop_column(Alias::new("metadata"))
.drop_column(Alias::new("manage_token"))
.drop_column(Alias::new("confirm_token"))
.to_owned(),
)
.await?;
Ok(())
}
}