risingwave_meta_model_migration/
m20231008_020431_hummock.rs

1use sea_orm_migration::prelude::*;
2
3use crate::utils::ColumnDefExt;
4use crate::{assert_not_has_tables, drop_tables};
5
6#[derive(DeriveMigrationName)]
7pub struct Migration;
8
9#[async_trait::async_trait]
10impl MigrationTrait for Migration {
11    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
12        assert_not_has_tables!(
13            manager,
14            CompactionTask,
15            CompactionConfig,
16            CompactionStatus,
17            HummockPinnedVersion,
18            HummockPinnedSnapshot,
19            HummockVersionDelta,
20            HummockVersionStats,
21            HummockSequence
22        );
23
24        manager
25            .create_table(
26                Table::create()
27                    .table(CompactionTask::Table)
28                    .col(
29                        ColumnDef::new(CompactionTask::Id)
30                            .big_integer()
31                            .not_null()
32                            .primary_key(),
33                    )
34                    .col(
35                        ColumnDef::new(CompactionTask::Task)
36                            .rw_binary(manager)
37                            .not_null(),
38                    )
39                    .col(
40                        ColumnDef::new(CompactionTask::ContextId)
41                            .integer()
42                            .not_null(),
43                    )
44                    .to_owned(),
45            )
46            .await?;
47
48        manager
49            .create_table(
50                Table::create()
51                    .table(CompactionConfig::Table)
52                    .col(
53                        ColumnDef::new(CompactionConfig::CompactionGroupId)
54                            .big_integer()
55                            .not_null()
56                            .primary_key(),
57                    )
58                    .col(ColumnDef::new(CompactionConfig::Config).rw_binary(manager))
59                    .to_owned(),
60            )
61            .await?;
62
63        manager
64            .create_table(
65                Table::create()
66                    .table(CompactionStatus::Table)
67                    .col(
68                        ColumnDef::new(CompactionStatus::CompactionGroupId)
69                            .big_integer()
70                            .not_null()
71                            .primary_key(),
72                    )
73                    .col(ColumnDef::new(CompactionStatus::Status).rw_binary(manager))
74                    .to_owned(),
75            )
76            .await?;
77
78        manager
79            .create_table(
80                Table::create()
81                    .table(HummockPinnedVersion::Table)
82                    .col(
83                        ColumnDef::new(HummockPinnedVersion::ContextId)
84                            .integer()
85                            .not_null()
86                            .primary_key(),
87                    )
88                    .col(
89                        ColumnDef::new(HummockPinnedVersion::MinPinnedId)
90                            .big_integer()
91                            .not_null(),
92                    )
93                    .to_owned(),
94            )
95            .await?;
96
97        manager
98            .create_table(
99                Table::create()
100                    .table(HummockPinnedSnapshot::Table)
101                    .col(
102                        ColumnDef::new(HummockPinnedSnapshot::ContextId)
103                            .integer()
104                            .not_null()
105                            .primary_key(),
106                    )
107                    .col(
108                        ColumnDef::new(HummockPinnedSnapshot::MinPinnedSnapshot)
109                            .big_integer()
110                            .not_null(),
111                    )
112                    .to_owned(),
113            )
114            .await?;
115
116        manager
117            .create_table(
118                Table::create()
119                    .table(HummockVersionDelta::Table)
120                    .col(
121                        ColumnDef::new(HummockVersionDelta::Id)
122                            .big_integer()
123                            .not_null()
124                            .primary_key(),
125                    )
126                    .col(
127                        ColumnDef::new(HummockVersionDelta::PrevId)
128                            .big_integer()
129                            .not_null(),
130                    )
131                    .col(
132                        ColumnDef::new(HummockVersionDelta::MaxCommittedEpoch)
133                            .big_integer()
134                            .not_null(),
135                    )
136                    .col(
137                        ColumnDef::new(HummockVersionDelta::SafeEpoch)
138                            .big_integer()
139                            .not_null(),
140                    )
141                    .col(
142                        ColumnDef::new(HummockVersionDelta::TrivialMove)
143                            .boolean()
144                            .not_null(),
145                    )
146                    .col(ColumnDef::new(HummockVersionDelta::FullVersionDelta).rw_binary(manager))
147                    .to_owned(),
148            )
149            .await?;
150
151        manager
152            .create_table(
153                Table::create()
154                    .table(HummockVersionStats::Table)
155                    .col(
156                        ColumnDef::new(HummockVersionStats::Id)
157                            .big_integer()
158                            .not_null()
159                            .primary_key(),
160                    )
161                    .col(
162                        ColumnDef::new(HummockVersionStats::Stats)
163                            .json_binary()
164                            .not_null(),
165                    )
166                    .to_owned(),
167            )
168            .await?;
169        manager
170            .create_table(
171                Table::create()
172                    .table(HummockSequence::Table)
173                    .col(
174                        ColumnDef::new(HummockSequence::Name)
175                            .string()
176                            .not_null()
177                            .primary_key(),
178                    )
179                    .col(
180                        ColumnDef::new(HummockSequence::Seq)
181                            .big_integer()
182                            .not_null(),
183                    )
184                    .to_owned(),
185            )
186            .await?;
187
188        Ok(())
189    }
190
191    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
192        drop_tables!(
193            manager,
194            CompactionTask,
195            CompactionConfig,
196            CompactionStatus,
197            HummockPinnedVersion,
198            HummockPinnedSnapshot,
199            HummockVersionDelta,
200            HummockVersionStats,
201            HummockSequence
202        );
203        Ok(())
204    }
205}
206
207#[derive(DeriveIden)]
208enum CompactionTask {
209    Table,
210    Id,
211    Task,
212    ContextId,
213}
214
215#[derive(DeriveIden)]
216enum CompactionConfig {
217    Table,
218    CompactionGroupId,
219    Config,
220}
221
222#[derive(DeriveIden)]
223enum CompactionStatus {
224    Table,
225    CompactionGroupId,
226    Status,
227}
228
229#[derive(DeriveIden)]
230enum HummockPinnedVersion {
231    Table,
232    ContextId,
233    MinPinnedId,
234}
235
236#[derive(DeriveIden)]
237enum HummockPinnedSnapshot {
238    Table,
239    ContextId,
240    MinPinnedSnapshot,
241}
242
243#[derive(DeriveIden)]
244enum HummockVersionDelta {
245    Table,
246    Id,
247    PrevId,
248    MaxCommittedEpoch,
249    SafeEpoch,
250    TrivialMove,
251    FullVersionDelta,
252}
253
254#[derive(DeriveIden)]
255enum HummockVersionStats {
256    Table,
257    Id,
258    Stats,
259}
260
261#[derive(DeriveIden)]
262enum HummockSequence {
263    Table,
264    Name,
265    Seq,
266}