1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use sea_orm_migration::prelude::*;
use crate::iden::{ToolchainComponentIden, ToolchainTargetIden};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Add status column to toolchain_target (defaults to "ready" for existing rows)
manager
.alter_table(
Table::alter()
.table(ToolchainTargetIden::Table)
.add_column(
ColumnDef::new(ToolchainTargetIden::Status)
.text()
.not_null()
.default("ready"),
)
.to_owned(),
)
.await?;
// toolchain_component table for individual component archives
manager
.create_table(
Table::create()
.table(ToolchainComponentIden::Table)
.if_not_exists()
.col(
ColumnDef::new(ToolchainComponentIden::Id)
.big_integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(ToolchainComponentIden::ToolchainTargetFk)
.big_integer()
.not_null(),
)
.col(
ColumnDef::new(ToolchainComponentIden::Name)
.text()
.not_null(),
)
.col(
ColumnDef::new(ToolchainComponentIden::StoragePath)
.text()
.not_null(),
)
.col(
ColumnDef::new(ToolchainComponentIden::Hash)
.text()
.not_null(),
)
.col(
ColumnDef::new(ToolchainComponentIden::Size)
.big_integer()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("toolchain_component_target_fk")
.from(
ToolchainComponentIden::Table,
ToolchainComponentIden::ToolchainTargetFk,
)
.to(ToolchainTargetIden::Table, ToolchainTargetIden::Id)
.on_update(ForeignKeyAction::NoAction)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.if_not_exists()
.name("idx_toolchain_component_unique")
.table(ToolchainComponentIden::Table)
.col(ToolchainComponentIden::ToolchainTargetFk)
.col(ToolchainComponentIden::Name)
.unique()
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(
Table::drop()
.table(ToolchainComponentIden::Table)
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(ToolchainTargetIden::Table)
.drop_column(ToolchainTargetIden::Status)
.to_owned(),
)
.await?;
Ok(())
}
}