workspace reshape
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "migration"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "migration"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "migration"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
sea-orm-migration = { version = "1", features = ["runtime-tokio-rustls", "sqlx-sqlite"] }
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
|
||||
@@ -0,0 +1,12 @@
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20260616_000001_create_tables;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20260616_000001_create_tables::Migration)]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
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(StreamKey::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(StreamKey::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(StreamKey::KeyValue)
|
||||
.string()
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(StreamKey::Label).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(StreamKey::IsActive)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(true),
|
||||
)
|
||||
.col(ColumnDef::new(StreamKey::CreatedAt).date_time().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(StreamSession::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(StreamSession::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(StreamSession::StreamKeyId).integer().not_null())
|
||||
.col(ColumnDef::new(StreamSession::StartedAt).date_time().not_null())
|
||||
.col(ColumnDef::new(StreamSession::EndedAt).date_time().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.from(StreamSession::Table, StreamSession::StreamKeyId)
|
||||
.to(StreamKey::Table, StreamKey::Id),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Seed the default stream key so OBS can connect out of the box
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared(
|
||||
"INSERT OR IGNORE INTO stream_key (key_value, label, is_active, created_at) \
|
||||
VALUES ('test', 'Default', 1, datetime('now'))",
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(StreamSession::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(StreamKey::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum StreamKey {
|
||||
Table,
|
||||
Id,
|
||||
KeyValue,
|
||||
Label,
|
||||
IsActive,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum StreamSession {
|
||||
Table,
|
||||
Id,
|
||||
StreamKeyId,
|
||||
StartedAt,
|
||||
EndedAt,
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
cli::run_cli(migration::Migrator).await;
|
||||
}
|
||||
Reference in New Issue
Block a user