Init
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
@@ -150,7 +150,7 @@ impl MigrationTrait for Migration {
|
||||
.col(
|
||||
ColumnDef::new(Alias::new("pub_key"))
|
||||
.text()
|
||||
.null()
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(
|
||||
@@ -165,6 +165,12 @@ impl MigrationTrait for Migration {
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Alias::new("is_superuser"))
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
@@ -284,7 +290,14 @@ impl MigrationTrait for Migration {
|
||||
.col(
|
||||
ColumnDef::new(Alias::new("updated_at"))
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Alias::new("is_admin"))
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
// Indexes créés après
|
||||
.foreign_key(
|
||||
@@ -325,6 +338,12 @@ impl MigrationTrait for Migration {
|
||||
.not_null()
|
||||
.default("member".to_owned()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Alias::new("permissions"))
|
||||
.big_integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Alias::new("joined_at"))
|
||||
.timestamp_with_time_zone()
|
||||
@@ -501,10 +520,108 @@ impl MigrationTrait for Migration {
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Create table `group`
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Alias::new("group"))
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new("id").uuid().primary_key().not_null())
|
||||
.col(ColumnDef::new("server_id").uuid().not_null())
|
||||
.col(ColumnDef::new("name").string().not_null())
|
||||
.col(
|
||||
ColumnDef::new("permissions")
|
||||
.big_integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new("is_default")
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new("created_at")
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_group_server")
|
||||
.from(Alias::new("group"), Alias::new("server_id"))
|
||||
.to(Alias::new("server"), Alias::new("id"))
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Create table `group_member`
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Alias::new("group_member"))
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new("group_id").uuid().not_null())
|
||||
.col(ColumnDef::new("user_id").uuid().not_null())
|
||||
.primary_key(
|
||||
Index::create()
|
||||
.col(Alias::new("group_id"))
|
||||
.col(Alias::new("user_id")),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_group_member_group")
|
||||
.from(Alias::new("group_member"), Alias::new("group_id"))
|
||||
.to(Alias::new("group"), Alias::new("id"))
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_group_member_user")
|
||||
.from(Alias::new("group_member"), Alias::new("user_id"))
|
||||
.to(Alias::new("user"), Alias::new("id"))
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Index: idx_group_server_id
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_group_server_id")
|
||||
.table(Alias::new("group"))
|
||||
.col(Alias::new("server_id"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Index: idx_group_member_user_id
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_group_member_user_id")
|
||||
.table(Alias::new("group_member"))
|
||||
.col(Alias::new("user_id"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Alias::new("group_member")).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(Alias::new("group")).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Alias::new("channel_user")).to_owned())
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user