From 26f5db6b61ba722bb7cb80e20d7152c0b40bf69c Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Thu, 27 Apr 2023 13:51:08 -0400 Subject: [PATCH] migrations and entities for hosts --- .../trifid_api_entities/src/entity/api_key.rs | 41 +++++++++++ .../src/entity/api_key_scope.rs | 32 +++++++++ .../src/entity/auth_token.rs | 32 +++++++++ .../src/entity/firewall_rule.rs | 38 ++++++++++ .../trifid_api_entities/src/entity/host.rs | 68 ++++++++++++++++++ .../src/entity/host_config_override.rs | 33 +++++++++ .../src/entity/host_static_address.rs | 32 +++++++++ .../src/entity/magic_link.rs | 32 +++++++++ .../trifid_api_entities/src/entity/mod.rs | 19 +++++ .../trifid_api_entities/src/entity/network.rs | 60 ++++++++++++++++ .../src/entity/organization.rs | 57 +++++++++++++++ .../trifid_api_entities/src/entity/prelude.rs | 17 +++++ .../trifid_api_entities/src/entity/role.rs | 44 ++++++++++++ .../src/entity/session_token.rs | 32 +++++++++ .../src/entity/signing_ca.rs | 31 +++++++++ .../src/entity/totp_authenticator.rs | 38 ++++++++++ .../trifid_api_entities/src/entity/user.rs | 58 ++++++++++++++++ .../m20230427_170037_create_table_hosts.rs | 69 +++++++++++++++++++ ...517_create_table_hosts_static_addresses.rs | 43 ++++++++++++ ...529_create_table_hosts_config_overrides.rs | 51 ++++++++++++++ 20 files changed, 827 insertions(+) create mode 100644 trifid-api/trifid_api_entities/src/entity/api_key.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/api_key_scope.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/auth_token.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/firewall_rule.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/host.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/host_config_override.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/host_static_address.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/magic_link.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/mod.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/network.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/organization.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/prelude.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/role.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/session_token.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/signing_ca.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/totp_authenticator.rs create mode 100644 trifid-api/trifid_api_entities/src/entity/user.rs create mode 100644 trifid-api/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs create mode 100644 trifid-api/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs create mode 100644 trifid-api/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs diff --git a/trifid-api/trifid_api_entities/src/entity/api_key.rs b/trifid-api/trifid_api_entities/src/entity/api_key.rs new file mode 100644 index 0000000..04aa795 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/api_key.rs @@ -0,0 +1,41 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "api_key")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + #[sea_orm(unique)] + pub key: String, + pub organization: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::api_key_scope::Entity")] + ApiKeyScope, + #[sea_orm( + belongs_to = "super::organization::Entity", + from = "Column::Organization", + to = "super::organization::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Organization, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::ApiKeyScope.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Organization.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/api_key_scope.rs b/trifid-api/trifid_api_entities/src/entity/api_key_scope.rs new file mode 100644 index 0000000..1deffbc --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/api_key_scope.rs @@ -0,0 +1,32 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "api_key_scope")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub scope: String, + pub api_key: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::api_key::Entity", + from = "Column::ApiKey", + to = "super::api_key::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + ApiKey, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::ApiKey.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/auth_token.rs b/trifid-api/trifid_api_entities/src/entity/auth_token.rs new file mode 100644 index 0000000..db14039 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/auth_token.rs @@ -0,0 +1,32 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "auth_token")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub user: String, + pub expires_on: i64, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::User", + to = "super::user::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/firewall_rule.rs b/trifid-api/trifid_api_entities/src/entity/firewall_rule.rs new file mode 100644 index 0000000..6a8c64f --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/firewall_rule.rs @@ -0,0 +1,38 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "firewall_rule")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub role: String, + pub protocol: String, + pub description: String, + pub allowed_role_id: Option, + pub port_range_from: i32, + pub port_range_to: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::role::Entity", + from = "Column::AllowedRoleId", + to = "super::role::Column::Id", + on_update = "NoAction", + on_delete = "Cascade" + )] + Role2, + #[sea_orm( + belongs_to = "super::role::Entity", + from = "Column::Role", + to = "super::role::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Role1, +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/host.rs b/trifid-api/trifid_api_entities/src/entity/host.rs new file mode 100644 index 0000000..f2d689a --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/host.rs @@ -0,0 +1,68 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "host")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub name: String, + pub network: String, + pub role: String, + pub ip: String, + pub listen_port: i32, + pub is_lighthouse: bool, + pub is_relay: bool, + pub counter: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::host_config_override::Entity")] + HostConfigOverride, + #[sea_orm(has_many = "super::host_static_address::Entity")] + HostStaticAddress, + #[sea_orm( + belongs_to = "super::network::Entity", + from = "Column::Network", + to = "super::network::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Network, + #[sea_orm( + belongs_to = "super::role::Entity", + from = "Column::Role", + to = "super::role::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Role, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::HostConfigOverride.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::HostStaticAddress.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Network.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Role.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/host_config_override.rs b/trifid-api/trifid_api_entities/src/entity/host_config_override.rs new file mode 100644 index 0000000..bfe77d2 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/host_config_override.rs @@ -0,0 +1,33 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "host_config_override")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub key: String, + pub value: String, + pub host: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::host::Entity", + from = "Column::Host", + to = "super::host::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Host, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Host.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/host_static_address.rs b/trifid-api/trifid_api_entities/src/entity/host_static_address.rs new file mode 100644 index 0000000..9b74220 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/host_static_address.rs @@ -0,0 +1,32 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "host_static_address")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub host: String, + pub address: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::host::Entity", + from = "Column::Host", + to = "super::host::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Host, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Host.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/magic_link.rs b/trifid-api/trifid_api_entities/src/entity/magic_link.rs new file mode 100644 index 0000000..1707d7e --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/magic_link.rs @@ -0,0 +1,32 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "magic_link")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub user: String, + pub expires_on: i64, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::User", + to = "super::user::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/mod.rs b/trifid-api/trifid_api_entities/src/entity/mod.rs new file mode 100644 index 0000000..d82ab21 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/mod.rs @@ -0,0 +1,19 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +pub mod prelude; + +pub mod api_key; +pub mod api_key_scope; +pub mod auth_token; +pub mod firewall_rule; +pub mod host; +pub mod host_config_override; +pub mod host_static_address; +pub mod magic_link; +pub mod network; +pub mod organization; +pub mod role; +pub mod session_token; +pub mod signing_ca; +pub mod totp_authenticator; +pub mod user; diff --git a/trifid-api/trifid_api_entities/src/entity/network.rs b/trifid-api/trifid_api_entities/src/entity/network.rs new file mode 100644 index 0000000..c747e2a --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/network.rs @@ -0,0 +1,60 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "network")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub cidr: String, + #[sea_orm(unique)] + pub organization: String, + #[sea_orm(unique)] + pub signing_ca: String, + pub created_at: i64, + pub name: String, + pub lighthouses_as_relays: bool, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::host::Entity")] + Host, + #[sea_orm( + belongs_to = "super::organization::Entity", + from = "Column::Organization", + to = "super::organization::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Organization, + #[sea_orm( + belongs_to = "super::signing_ca::Entity", + from = "Column::SigningCa", + to = "super::signing_ca::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + SigningCa, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Host.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Organization.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::SigningCa.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/organization.rs b/trifid-api/trifid_api_entities/src/entity/organization.rs new file mode 100644 index 0000000..25d4ff9 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/organization.rs @@ -0,0 +1,57 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "organization")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub name: String, + #[sea_orm(unique)] + pub owner: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::api_key::Entity")] + ApiKey, + #[sea_orm(has_one = "super::network::Entity")] + Network, + #[sea_orm(has_many = "super::role::Entity")] + Role, + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::Owner", + to = "super::user::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::ApiKey.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Network.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Role.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/prelude.rs b/trifid-api/trifid_api_entities/src/entity/prelude.rs new file mode 100644 index 0000000..2042b24 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/prelude.rs @@ -0,0 +1,17 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +pub use super::api_key::Entity as ApiKey; +pub use super::api_key_scope::Entity as ApiKeyScope; +pub use super::auth_token::Entity as AuthToken; +pub use super::firewall_rule::Entity as FirewallRule; +pub use super::host::Entity as Host; +pub use super::host_config_override::Entity as HostConfigOverride; +pub use super::host_static_address::Entity as HostStaticAddress; +pub use super::magic_link::Entity as MagicLink; +pub use super::network::Entity as Network; +pub use super::organization::Entity as Organization; +pub use super::role::Entity as Role; +pub use super::session_token::Entity as SessionToken; +pub use super::signing_ca::Entity as SigningCa; +pub use super::totp_authenticator::Entity as TotpAuthenticator; +pub use super::user::Entity as User; diff --git a/trifid-api/trifid_api_entities/src/entity/role.rs b/trifid-api/trifid_api_entities/src/entity/role.rs new file mode 100644 index 0000000..d664163 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/role.rs @@ -0,0 +1,44 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "role")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + #[sea_orm(unique)] + pub name: String, + pub description: String, + pub organization: String, + pub created_at: i64, + pub modified_at: i64, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::host::Entity")] + Host, + #[sea_orm( + belongs_to = "super::organization::Entity", + from = "Column::Organization", + to = "super::organization::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + Organization, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Host.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Organization.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/session_token.rs b/trifid-api/trifid_api_entities/src/entity/session_token.rs new file mode 100644 index 0000000..a648966 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/session_token.rs @@ -0,0 +1,32 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "session_token")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub user: String, + pub expires_on: i64, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::User", + to = "super::user::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/signing_ca.rs b/trifid-api/trifid_api_entities/src/entity/signing_ca.rs new file mode 100644 index 0000000..d0770a9 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/signing_ca.rs @@ -0,0 +1,31 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "signing_ca")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + pub organization: String, + pub cert: String, + #[sea_orm(unique)] + pub key: String, + pub expires: i64, + #[sea_orm(unique)] + pub nonce: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_one = "super::network::Entity")] + Network, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Network.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/totp_authenticator.rs b/trifid-api/trifid_api_entities/src/entity/totp_authenticator.rs new file mode 100644 index 0000000..5437596 --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/totp_authenticator.rs @@ -0,0 +1,38 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "totp_authenticator")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + #[sea_orm(unique)] + pub secret: String, + #[sea_orm(unique)] + pub url: String, + pub verified: bool, + pub expires_on: i64, + #[sea_orm(unique)] + pub user: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::User", + to = "super::user::Column::Id", + on_update = "Cascade", + on_delete = "Cascade" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_entities/src/entity/user.rs b/trifid-api/trifid_api_entities/src/entity/user.rs new file mode 100644 index 0000000..0d7b61f --- /dev/null +++ b/trifid-api/trifid_api_entities/src/entity/user.rs @@ -0,0 +1,58 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "user")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: String, + #[sea_orm(unique)] + pub email: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::auth_token::Entity")] + AuthToken, + #[sea_orm(has_many = "super::magic_link::Entity")] + MagicLink, + #[sea_orm(has_one = "super::organization::Entity")] + Organization, + #[sea_orm(has_many = "super::session_token::Entity")] + SessionToken, + #[sea_orm(has_one = "super::totp_authenticator::Entity")] + TotpAuthenticator, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::AuthToken.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::MagicLink.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Organization.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::SessionToken.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::TotpAuthenticator.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/trifid-api/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs b/trifid-api/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs new file mode 100644 index 0000000..9ad0b96 --- /dev/null +++ b/trifid-api/trifid_api_migration/src/m20230427_170037_create_table_hosts.rs @@ -0,0 +1,69 @@ +use sea_orm_migration::prelude::*; +use crate::m20230403_173431_create_table_networks::Network; +use crate::m20230404_133809_create_table_roles::Role; + +#[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(Host::Table) + .col(ColumnDef::new(Host::Id).string().not_null().primary_key()) + .col(ColumnDef::new(Host::Name).string().not_null()) + .col(ColumnDef::new(Host::Network).string().not_null()) + .col(ColumnDef::new(Host::Role).string().not_null()) + .col(ColumnDef::new(Host::IP).string().not_null()) + .col(ColumnDef::new(Host::ListenPort).unsigned().not_null()) + .col(ColumnDef::new(Host::IsLighthouse).boolean().not_null()) + .col(ColumnDef::new(Host::IsRelay).boolean().not_null()) + .col(ColumnDef::new(Host::Counter).unsigned().not_null()) + .foreign_key( + ForeignKey::create() + .from(Host::Table, Host::Network) + .to(Network::Table, Network::Id) + .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) + ) + .foreign_key( + ForeignKey::create() + .from(Host::Table, Host::Role) + .to(Role::Table, Role::Id) + .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) + ) + .index( + Index::create() + .name("idx-hosts-id-name-unique") + .table(Host::Table) + .col(Host::Id) + .col(Host::Name) + .unique() + ) + .to_owned() + ).await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Host::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +pub enum Host { + Table, + Id, + Name, + Network, + Role, + IP, + ListenPort, + IsLighthouse, + IsRelay, + Counter +} diff --git a/trifid-api/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs b/trifid-api/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs new file mode 100644 index 0000000..7de7d76 --- /dev/null +++ b/trifid-api/trifid_api_migration/src/m20230427_171517_create_table_hosts_static_addresses.rs @@ -0,0 +1,43 @@ +use sea_orm_migration::prelude::*; +use crate::m20230427_170037_create_table_hosts::Host; + +#[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(HostStaticAddress::Table) + .col(ColumnDef::new(HostStaticAddress::Id).string().not_null().primary_key()) + .col(ColumnDef::new(HostStaticAddress::Host).string().not_null()) + .col(ColumnDef::new(HostStaticAddress::Address).string().not_null()) + .foreign_key( + ForeignKey::create() + .from(HostStaticAddress::Table, HostStaticAddress::Host) + .to(Host::Table, Host::Id) + .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(HostStaticAddress::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +pub enum HostStaticAddress { + Table, + Id, + Host, + Address +} diff --git a/trifid-api/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs b/trifid-api/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs new file mode 100644 index 0000000..86ee883 --- /dev/null +++ b/trifid-api/trifid_api_migration/src/m20230427_171529_create_table_hosts_config_overrides.rs @@ -0,0 +1,51 @@ +use sea_orm_migration::prelude::*; +use crate::m20230427_170037_create_table_hosts::Host; + +#[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(HostConfigOverride::Table) + .col(ColumnDef::new(HostConfigOverride::Id).string().not_null().primary_key()) + .col(ColumnDef::new(HostConfigOverride::Key).string().not_null()) + .col(ColumnDef::new(HostConfigOverride::Value).string().not_null()) + .col(ColumnDef::new(HostConfigOverride::Host).string().not_null()) + .foreign_key( + ForeignKey::create() + .from(HostConfigOverride::Table, HostConfigOverride::Host) + .to(Host::Table, Host::Id) + .on_delete(ForeignKeyAction::Cascade) + .on_update(ForeignKeyAction::Cascade) + ) + .index( + Index::create() + .name("idx_hosts_config_overrides-key-host-unique") + .table(HostConfigOverride::Table) + .col(HostConfigOverride::Key) + .col(HostConfigOverride::Id) + .unique() + ) + .to_owned() + ).await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(HostConfigOverride::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +pub enum HostConfigOverride { + Table, + Host, + Id, + Key, + Value, +}