risingwave_meta_model_migration/
m20240701_060504_hummock_time_travel.rs1use sea_orm_migration::prelude::*;
2
3use crate::drop_tables;
4use crate::utils::ColumnDefExt;
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 manager
13 .create_table(
14 Table::create()
15 .table(HummockSstableInfo::Table)
16 .if_not_exists()
17 .col(
18 ColumnDef::new(HummockSstableInfo::SstId)
19 .big_integer()
20 .not_null()
21 .primary_key(),
22 )
23 .col(
24 ColumnDef::new(HummockSstableInfo::ObjectId)
25 .big_integer()
26 .not_null(),
27 )
28 .col(
29 ColumnDef::new(HummockSstableInfo::SstableInfo)
30 .rw_binary(manager)
31 .null(),
32 )
33 .to_owned(),
34 )
35 .await?;
36
37 manager
38 .create_table(
39 Table::create()
40 .table(HummockTimeTravelVersion::Table)
41 .if_not_exists()
42 .col(
43 ColumnDef::new(HummockTimeTravelVersion::VersionId)
44 .big_integer()
45 .not_null()
46 .primary_key(),
47 )
48 .col(
49 ColumnDef::new(HummockTimeTravelVersion::Version)
50 .rw_binary(manager)
51 .null(),
52 )
53 .to_owned(),
54 )
55 .await?;
56
57 manager
58 .create_table(
59 Table::create()
60 .table(HummockTimeTravelDelta::Table)
61 .if_not_exists()
62 .col(
63 ColumnDef::new(HummockTimeTravelDelta::VersionId)
64 .big_integer()
65 .not_null()
66 .primary_key(),
67 )
68 .col(
69 ColumnDef::new(HummockTimeTravelDelta::VersionDelta)
70 .rw_binary(manager)
71 .null(),
72 )
73 .to_owned(),
74 )
75 .await?;
76
77 manager
78 .create_table(
79 Table::create()
80 .table(HummockEpochToVersion::Table)
81 .if_not_exists()
82 .col(
83 ColumnDef::new(HummockEpochToVersion::Epoch)
84 .big_integer()
85 .not_null()
86 .primary_key(),
87 )
88 .col(
89 ColumnDef::new(HummockEpochToVersion::VersionId)
90 .big_integer()
91 .not_null(),
92 )
93 .to_owned(),
94 )
95 .await?;
96
97 Ok(())
98 }
99
100 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
101 drop_tables!(
102 manager,
103 HummockSstableInfo,
104 HummockTimeTravelVersion,
105 HummockTimeTravelDelta,
106 HummockEpochToVersion
107 );
108 Ok(())
109 }
110}
111
112#[derive(DeriveIden)]
113pub(crate) enum HummockSstableInfo {
114 Table,
115 SstId,
116 ObjectId,
117 SstableInfo,
118}
119
120#[derive(DeriveIden)]
121enum HummockTimeTravelVersion {
122 Table,
123 VersionId,
124 Version,
125}
126
127#[derive(DeriveIden)]
128enum HummockTimeTravelDelta {
129 Table,
130 VersionId,
131 VersionDelta,
132}
133
134#[derive(DeriveIden)]
135enum HummockEpochToVersion {
136 Table,
137 Epoch,
138 VersionId,
139}