ryuk-cli 0.1.0

The `ryuk` command: scaffold a Ryuk app (axum, SeaORM, Inertia/Svelte), generate controllers, models, jobs and mails, run migrations and the dev server.
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

// Columns match `ryuk::passkey::passkeys::Model` exactly: the library's own `Passkeys::ensure_tables()`
// also runs at startup (a `CREATE TABLE IF NOT EXISTS`), so it is a no-op once this migration has run;
// this migration exists only to add the `users` foreign key the library cannot know about.
#[derive(DeriveIden)]
enum Passkeys {
    Table,
    Id,
    OwnerId,
    CredentialId,
    PasskeyJson,
    Name,
    CreatedAt,
    LastUsedAt,
}

#[derive(DeriveIden)]
enum Users {
    Table,
    Id,
}

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(Passkeys::Table)
                    .if_not_exists()
                    .col(
                        ColumnDef::new(Passkeys::Id)
                            .big_integer()
                            .not_null()
                            .auto_increment()
                            .primary_key(),
                    )
                    .col(ColumnDef::new(Passkeys::OwnerId).big_integer().not_null())
                    .col(
                        ColumnDef::new(Passkeys::CredentialId)
                            .string_len(512)
                            .not_null()
                            .unique_key(),
                    )
                    .col(ColumnDef::new(Passkeys::PasskeyJson).text().not_null())
                    .col(ColumnDef::new(Passkeys::Name).text().not_null())
                    .col(ColumnDef::new(Passkeys::CreatedAt).big_integer().not_null())
                    .col(ColumnDef::new(Passkeys::LastUsedAt).big_integer().null())
                    .foreign_key(
                        ForeignKey::create()
                            .from(Passkeys::Table, Passkeys::OwnerId)
                            .to(Users::Table, Users::Id)
                            .on_delete(ForeignKeyAction::Cascade),
                    )
                    .to_owned(),
            )
            .await
    }

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