70 lines
2 KiB
Rust
70 lines
2 KiB
Rust
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(Defaults::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(Defaults::Key)
|
|
.string()
|
|
.not_null()
|
|
.primary_key(),
|
|
)
|
|
.col(ColumnDef::new(Defaults::Value).string().not_null())
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
manager
|
|
.create_table(
|
|
Table::create()
|
|
.table(InstanceInfo::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(InstanceInfo::Id)
|
|
.big_integer()
|
|
.not_null()
|
|
.primary_key(),
|
|
)
|
|
.col(ColumnDef::new(InstanceInfo::Hostname).string().not_null())
|
|
.col(ColumnDef::new(InstanceInfo::MacAddress).string().not_null())
|
|
.col(ColumnDef::new(InstanceInfo::SshKeys).string())
|
|
.col(ColumnDef::new(InstanceInfo::UserData).binary())
|
|
.to_owned(),
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(Defaults::Table).to_owned())
|
|
.await?;
|
|
manager
|
|
.drop_table(Table::drop().table(InstanceInfo::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(Iden)]
|
|
enum InstanceInfo {
|
|
Table,
|
|
Id,
|
|
Hostname,
|
|
MacAddress,
|
|
SshKeys,
|
|
UserData,
|
|
}
|
|
|
|
#[derive(Iden)]
|
|
enum Defaults {
|
|
Table,
|
|
Key,
|
|
Value,
|
|
}
|