sova_notifications/
migration.rs1use sea_orm_migration::prelude::*;
4
5pub struct NotificationsMigrator;
6
7#[async_trait::async_trait]
8impl MigratorTrait for NotificationsMigrator {
9 fn migrations() -> Vec<Box<dyn MigrationTrait>> {
10 vec![Box::new(m20260308_000001_notifications::Migration)]
11 }
12}
13
14mod m20260308_000001_notifications {
15 use sea_orm_migration::prelude::*;
16
17 pub struct Migration;
18
19 impl MigrationName for Migration {
20 fn name(&self) -> &str {
21 "m20260308_000001_notifications"
22 }
23 }
24
25 #[async_trait::async_trait]
26 impl MigrationTrait for Migration {
27 async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
28 manager
29 .create_table(
30 Table::create()
31 .table(Notifications::Table)
32 .if_not_exists()
33 .col(
34 ColumnDef::new(Notifications::Id)
35 .big_integer()
36 .not_null()
37 .auto_increment()
38 .primary_key(),
39 )
40 .col(
41 ColumnDef::new(Notifications::UserId)
42 .big_integer()
43 .not_null(),
44 )
45 .col(ColumnDef::new(Notifications::Channel).string().not_null())
46 .col(ColumnDef::new(Notifications::Event).string().not_null())
47 .col(ColumnDef::new(Notifications::Title).string().not_null())
48 .col(ColumnDef::new(Notifications::Body).text().null())
49 .col(
50 ColumnDef::new(Notifications::Data)
51 .text()
52 .not_null()
53 .default("{}"),
54 )
55 .col(
56 ColumnDef::new(Notifications::ReadAt)
57 .timestamp_with_time_zone()
58 .null(),
59 )
60 .col(
61 ColumnDef::new(Notifications::CreatedAt)
62 .timestamp_with_time_zone()
63 .not_null(),
64 )
65 .to_owned(),
66 )
67 .await?;
68
69 manager
70 .create_index(
71 Index::create()
72 .if_not_exists()
73 .name("idx_notifications_user_read")
74 .table(Notifications::Table)
75 .col(Notifications::UserId)
76 .col(Notifications::ReadAt)
77 .to_owned(),
78 )
79 .await?;
80 manager
81 .create_index(
82 Index::create()
83 .if_not_exists()
84 .name("idx_notifications_user_channel")
85 .table(Notifications::Table)
86 .col(Notifications::UserId)
87 .col(Notifications::Channel)
88 .to_owned(),
89 )
90 .await?;
91 manager
92 .create_index(
93 Index::create()
94 .if_not_exists()
95 .name("idx_notifications_created")
96 .table(Notifications::Table)
97 .col(Notifications::CreatedAt)
98 .to_owned(),
99 )
100 .await?;
101
102 Ok(())
103 }
104
105 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
106 manager
107 .drop_table(Table::drop().table(Notifications::Table).to_owned())
108 .await?;
109 Ok(())
110 }
111 }
112
113 #[derive(Iden)]
114 enum Notifications {
115 Table,
116 Id,
117 UserId,
118 Channel,
119 Event,
120 Title,
121 Body,
122 Data,
123 ReadAt,
124 CreatedAt,
125 }
126}