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
use pagetop::prelude::*;
#[rustfmt::skip]
#[derive(Iden)]
enum NodeAccess {
Table, // node_access: Identifies which realm/grant pairs a user must possess in
// order to view, update, or delete specific nodes.
Nid, // The Node.nid this record affects.
Gid, // The grant ID a user must possess in the specified realm to gain this
// row's privileges on the node.
Realm, // The realm in which the user must possess the grant ID. Each node access
// node can define one or more realms.
GrantView, // Boolean indicating whether a user with the realm/grant pair can view this
// node.
GrantUpdate, // Boolean indicating whether a user with the realm/grant pair can edit this
// node.
GrantDelete, // Boolean indicating whether a user with the realm/grant pair can delete
// this node.
}
new_migration!(Migration);
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(NodeAccess::Table)
.if_not_exists()
.col(
ColumnDef::new(NodeAccess::Nid)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(NodeAccess::Gid).string().not_null())
.col(ColumnDef::new(NodeAccess::Realm).string().not_null())
.col(ColumnDef::new(NodeAccess::GrantView).string().not_null())
.col(ColumnDef::new(NodeAccess::GrantUpdate).string().not_null())
.col(ColumnDef::new(NodeAccess::GrantDelete).string().not_null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(NodeAccess::Table).to_owned())
.await
}
}