From 2afe00857321427a9fc85db4d70c88e1370ad796 Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Tue, 4 Apr 2023 09:44:19 -0400 Subject: [PATCH] add some migs --- trifid-api/src/routes/v1/auth/magic_link.rs | 2 + trifid-api/trifid_api_migration/src/lib.rs | 4 ++ .../m20230404_133809_create_table_roles.rs | 41 ++++++++++++++++ ...0404_133813_create_table_firewall_rules.rs | 48 +++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs create mode 100644 trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs diff --git a/trifid-api/src/routes/v1/auth/magic_link.rs b/trifid-api/src/routes/v1/auth/magic_link.rs index b42f1d7..0dac832 100644 --- a/trifid-api/src/routes/v1/auth/magic_link.rs +++ b/trifid-api/src/routes/v1/auth/magic_link.rs @@ -1,3 +1,5 @@ + + use actix_web::{HttpResponse, post}; use actix_web::web::{Data, Json}; use log::error; diff --git a/trifid-api/trifid_api_migration/src/lib.rs b/trifid-api/trifid_api_migration/src/lib.rs index 35bee9d..cd1b240 100644 --- a/trifid-api/trifid_api_migration/src/lib.rs +++ b/trifid-api/trifid_api_migration/src/lib.rs @@ -12,6 +12,8 @@ pub mod m20230402_234025_create_table_totp_authenticators; pub mod m20230403_002256_create_table_auth_tokens; pub mod m20230403_142517_create_table_signing_cas; pub mod m20230403_173431_create_table_networks; +mod m20230404_133809_create_table_roles; +mod m20230404_133813_create_table_firewall_rules; #[async_trait::async_trait] impl MigratorTrait for Migrator { @@ -27,6 +29,8 @@ impl MigratorTrait for Migrator { Box::new(m20230403_002256_create_table_auth_tokens::Migration), Box::new(m20230403_142517_create_table_signing_cas::Migration), Box::new(m20230403_173431_create_table_networks::Migration), + Box::new(m20230404_133809_create_table_roles::Migration), + Box::new(m20230404_133813_create_table_firewall_rules::Migration), ] } } diff --git a/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs b/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs new file mode 100644 index 0000000..b478620 --- /dev/null +++ b/trifid-api/trifid_api_migration/src/m20230404_133809_create_table_roles.rs @@ -0,0 +1,41 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager.create_table( + Table::create() + .table(Role::Table) + .col(ColumnDef::new(Role::Id).string().not_null().primary_key()) + .col(ColumnDef::new(Role::Name).string().not_null()) + .col(ColumnDef::new(Role::Description).string().not_null()) + .col(ColumnDef::new(Role::Organization).string().not_null()) + .foreign_key( + ForeignKey::create() + .from(Role::Table, Role::Organization ) + ) + ) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + todo!(); + + manager + .drop_table(Table::drop().table(Post::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +pub enum Role { + Table, + Id, + Name, + Description, + Organization +} diff --git a/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs b/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs new file mode 100644 index 0000000..b058244 --- /dev/null +++ b/trifid-api/trifid_api_migration/src/m20230404_133813_create_table_firewall_rules.rs @@ -0,0 +1,48 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + todo!(); + + manager + .create_table( + Table::create() + .table(Post::Table) + .if_not_exists() + .col( + ColumnDef::new(Post::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + todo!(); + + manager + .drop_table(Table::drop().table(Post::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +}