From 0565328ea8b15137bb06d78f51e97803de198af0 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sun, 13 Aug 2023 21:16:43 +0200 Subject: [PATCH] feat(server): start distro table --- .../m20230813_000001_create_dist_tables.rs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/server/src/db/migrator/m20230813_000001_create_dist_tables.rs b/server/src/db/migrator/m20230813_000001_create_dist_tables.rs index 97191b8..46a2842 100644 --- a/server/src/db/migrator/m20230813_000001_create_dist_tables.rs +++ b/server/src/db/migrator/m20230813_000001_create_dist_tables.rs @@ -11,6 +11,34 @@ impl MigrationName for Migration { #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(Distro::Table) + .col( + ColumnDef::new(Distro::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col( + ColumnDef::new(Distro::Slug) + .string_len(255) + .not_null() + .unique_key(), + ) + .col( + ColumnDef::new(Distro::Name) + .string() + .not_null() + .unique_key(), + ) + .col(ColumnDef::new(Distro::Description).string()) + .col(ColumnDef::new(Distro::Url).string()) + .to_owned(), + ) + .await?; manager .create_table( Table::create() @@ -22,8 +50,16 @@ impl MigrationTrait for Migration { .auto_increment() .primary_key(), ) + .col(ColumnDef::new(Repo::DistroId).integer().not_null()) .col(ColumnDef::new(Repo::Name).string().not_null().unique_key()) .col(ColumnDef::new(Repo::Description).string()) + .foreign_key( + ForeignKey::create() + .name("fk-repo-distro_id") + .from(Repo::Table, Repo::DistroId) + .to(Distro::Table, Distro::Id) + .on_delete(ForeignKeyAction::Cascade), + ) .to_owned(), ) .await?; @@ -35,14 +71,28 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(Repo::Table).to_owned()) + .await?; + manager + .drop_table(Table::drop().table(Distro::Table).to_owned()) .await } } +#[derive(Iden)] +pub enum Distro { + Table, + Id, + Slug, + Name, + Description, + Url, +} + #[derive(Iden)] pub enum Repo { Table, Id, + DistroId, Name, Description, }