This commit is contained in:
2026-07-11 11:21:09 +02:00
parent 75bc9d2440
commit 825db3a292
9 changed files with 207 additions and 94 deletions
+98 -64
View File
@@ -27,30 +27,13 @@ impl MigrationTrait for Migration {
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Alias::new("default_server_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("default_channel_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("default_voice_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("is_default"))
.boolean()
.not_null()
.default(false),
)
.col(ColumnDef::new(Alias::new("owner_id")).uuid().not_null())
.to_owned(),
)
.await?;
@@ -125,16 +108,6 @@ impl MigrationTrait for Migration {
.integer()
.not_null(),
)
.col(
ColumnDef::new(Alias::new("default_channel_permissions"))
.big_integer()
.null(),
)
.col(
ColumnDef::new(Alias::new("default_voice_permissions"))
.big_integer()
.null(),
)
.col(ColumnDef::new(Alias::new("name")).string().null())
.col(
ColumnDef::new(Alias::new("created_at"))
@@ -327,36 +300,6 @@ impl MigrationTrait for Migration {
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Alias::new("is_admin"))
.boolean()
.not_null()
.default(false),
)
.col(
ColumnDef::new(Alias::new("is_owner"))
.boolean()
.not_null()
.default(false),
)
.col(
ColumnDef::new(Alias::new("server_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("channel_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("voice_permissions"))
.big_integer()
.not_null()
.default(0),
)
// Indexes créés après
.foreign_key(
ForeignKey::create()
@@ -390,12 +333,6 @@ impl MigrationTrait for Migration {
)
.col(ColumnDef::new(Alias::new("channel_id")).uuid().not_null())
.col(ColumnDef::new(Alias::new("user_id")).uuid().not_null())
.col(
ColumnDef::new(Alias::new("role"))
.string()
.not_null()
.default("member".to_owned()),
)
.col(
ColumnDef::new(Alias::new("joined_at"))
.timestamp_with_time_zone()
@@ -636,6 +573,8 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(ColumnDef::new("group_id").uuid().not_null())
.col(ColumnDef::new("user_id").uuid().not_null())
.col(ColumnDef::new("scope_type").integer().not_null())
.col(ColumnDef::new("scope_id").uuid().not_null())
.primary_key(
Index::create()
.col(Alias::new("group_id"))
@@ -681,6 +620,101 @@ impl MigrationTrait for Migration {
)
.await?;
// Create table `user_permission`
manager
.create_table(
Table::create()
.table(Alias::new("user_permission"))
.if_not_exists()
.col(ColumnDef::new("id").uuid().primary_key().not_null())
.col(ColumnDef::new("user_id").uuid().not_null())
.col(ColumnDef::new("server_id").uuid().not_null())
.col(ColumnDef::new("scope_type").integer().not_null())
.col(ColumnDef::new("scope_id").uuid().not_null())
.col(
ColumnDef::new(Alias::new("server_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("channel_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("voice_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new("created_at")
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.foreign_key(
ForeignKey::create()
.name("fk_user_permission_user")
.from(Alias::new("user_permission"), Alias::new("user_id"))
.to(Alias::new("user"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKey::create()
.name("fk_user_permission_server")
.from(Alias::new("user_permission"), Alias::new("server_id"))
.to(Alias::new("server"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
// Create CACHE table `computed_permission`
manager
.create_table(
Table::create()
.table(Alias::new("computed_permission"))
.if_not_exists()
.col(ColumnDef::new("user_id").uuid().not_null())
.col(ColumnDef::new("resource_id").uuid().not_null())
.col(
ColumnDef::new(Alias::new("server_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("channel_permissions"))
.big_integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Alias::new("voice_permissions"))
.big_integer()
.not_null()
.default(0),
)
.primary_key(
Index::create()
.col(Alias::new("user_id"))
.col(Alias::new("resource_id")),
)
.foreign_key(
ForeignKey::create()
.name("fk_computed_permission_user")
.from(Alias::new("computed_permission"), Alias::new("user_id"))
.to(Alias::new("user"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
Ok(())
}