trifid_api_migration 0.2.0

Database migrations for trifid-api
Documentation
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(KeystoreEntry::Table)
                .col(
                    ColumnDef::new(KeystoreEntry::Id)
                        .string()
                        .not_null()
                        .primary_key()
                )
                .col(
                    ColumnDef::new(KeystoreEntry::Host)
                        .string()
                        .not_null()
                )
                .col(
                    ColumnDef::new(KeystoreEntry::Counter)
                        .integer()
                        .not_null()
                )
                .col(
                    ColumnDef::new(KeystoreEntry::SigningKey)
                        .binary()
                        .not_null()
                )
                .col(
                    ColumnDef::new(KeystoreEntry::ClientSigningKey)
                        .binary()
                        .not_null()
                )
                .col(
                    ColumnDef::new(KeystoreEntry::ClientDHKey)
                        .binary()
                        .not_null()
                )
                .col(
                    ColumnDef::new(KeystoreEntry::Config)
                        .string()
                        .not_null()
                )
                .col(
                    ColumnDef::new(KeystoreEntry::Certificate)
                        .binary()
                        .not_null()
                )
                .foreign_key(
                    ForeignKey::create()
                        .from(KeystoreEntry::Table, KeystoreEntry::Host)
                        .to(Host::Table, Host::Id)
                )
                .index(
                    Index::create()
                        .name("idx-keystore-entry-host-counter-unique")
                        .table(KeystoreEntry::Table)
                        .col(KeystoreEntry::Host)
                        .col(KeystoreEntry::Counter)
                        .unique()
                )
                .to_owned()
        ).await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(KeystoreEntry::Table).to_owned())
            .await
    }
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum KeystoreEntry {
    Table,
    Id,
    Host,
    Counter,
    SigningKey,
    ClientSigningKey,
    ClientDHKey,
    Config,
    Certificate
}