|
| 1 | +use ::entity::{event_model, notification}; |
| 2 | +use sea_orm_migration::prelude::*; |
| 3 | + |
| 4 | +/// `notification_to_identity_id_idx`: `list_notifications` grabs the notifications |
| 5 | +/// for an identity reverse sorted by the primary key. |
| 6 | +/// |
| 7 | +/// `events_collection_created_at_id_idx`: feeds are sorted in reverse-chronological |
| 8 | +/// order, with the primary key as a fallback to keep the sort order stable. |
| 9 | +/// |
| 10 | +/// `events_identity_heads_idx`: `list_heads` gets only the head for each "event stream" |
| 11 | +/// for efficient syncing. |
| 12 | +#[derive(DeriveMigrationName)] |
| 13 | +pub struct Migration; |
| 14 | + |
| 15 | +#[async_trait::async_trait] |
| 16 | +impl MigrationTrait for Migration { |
| 17 | + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { |
| 18 | + manager |
| 19 | + .create_index( |
| 20 | + Index::create() |
| 21 | + .if_not_exists() |
| 22 | + .name("notification_to_identity_id_idx") |
| 23 | + .table(notification::Entity) |
| 24 | + .col(notification::Column::ToIdentity) |
| 25 | + .col(notification::Column::Id) |
| 26 | + .to_owned(), |
| 27 | + ) |
| 28 | + .await?; |
| 29 | + |
| 30 | + manager |
| 31 | + .create_index( |
| 32 | + Index::create() |
| 33 | + .if_not_exists() |
| 34 | + .name("events_collection_created_at_id_idx") |
| 35 | + .table(event_model::Entity) |
| 36 | + .col(event_model::Column::Collection) |
| 37 | + .col(event_model::Column::CreatedAt) |
| 38 | + .col(event_model::Column::Id) |
| 39 | + .to_owned(), |
| 40 | + ) |
| 41 | + .await?; |
| 42 | + |
| 43 | + manager |
| 44 | + .create_index( |
| 45 | + Index::create() |
| 46 | + .if_not_exists() |
| 47 | + .name("events_identity_heads_idx") |
| 48 | + .table(event_model::Entity) |
| 49 | + .col(event_model::Column::Identity) |
| 50 | + .col(event_model::Column::PublicKeyType) |
| 51 | + .col(event_model::Column::PublicKey) |
| 52 | + .col(event_model::Column::Collection) |
| 53 | + .col(event_model::Column::Sequence) |
| 54 | + .to_owned(), |
| 55 | + ) |
| 56 | + .await?; |
| 57 | + |
| 58 | + Ok(()) |
| 59 | + } |
| 60 | + |
| 61 | + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { |
| 62 | + manager |
| 63 | + .drop_index( |
| 64 | + Index::drop() |
| 65 | + .name("events_identity_heads_idx") |
| 66 | + .table(event_model::Entity) |
| 67 | + .to_owned(), |
| 68 | + ) |
| 69 | + .await?; |
| 70 | + |
| 71 | + manager |
| 72 | + .drop_index( |
| 73 | + Index::drop() |
| 74 | + .name("events_collection_created_at_id_idx") |
| 75 | + .table(event_model::Entity) |
| 76 | + .to_owned(), |
| 77 | + ) |
| 78 | + .await?; |
| 79 | + |
| 80 | + manager |
| 81 | + .drop_index( |
| 82 | + Index::drop() |
| 83 | + .name("notification_to_identity_id_idx") |
| 84 | + .table(notification::Entity) |
| 85 | + .to_owned(), |
| 86 | + ) |
| 87 | + .await?; |
| 88 | + |
| 89 | + Ok(()) |
| 90 | + } |
| 91 | +} |
0 commit comments