init
This commit is contained in:
23
migration/Cargo.toml
Normal file
23
migration/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "migration"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "migration"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
async-std = { version = "1", features = ["attributes", "tokio1"] }
|
||||
loco-rs = { workspace = true }
|
||||
|
||||
|
||||
[dependencies.sea-orm-migration]
|
||||
version = "1.1.0"
|
||||
features = [
|
||||
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
|
||||
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
|
||||
# e.g.
|
||||
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
||||
]
|
22
migration/src/lib.rs
Normal file
22
migration/src/lib.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
#![allow(elided_lifetimes_in_paths)]
|
||||
#![allow(clippy::wildcard_imports)]
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
mod m20220101_000001_users;
|
||||
|
||||
mod m20250724_214338_music_libraries;
|
||||
mod m20250724_214844_music_files;
|
||||
mod m20250724_223717_add_idx_unique_path_per_library;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20220101_000001_users::Migration),
|
||||
Box::new(m20250724_214338_music_libraries::Migration),
|
||||
Box::new(m20250724_214844_music_files::Migration),
|
||||
Box::new(m20250724_223717_add_idx_unique_path_per_library::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
}
|
41
migration/src/m20220101_000001_users.rs
Normal file
41
migration/src/m20220101_000001_users.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"users",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("pid", ColType::Uuid),
|
||||
("email", ColType::StringUniq),
|
||||
("password", ColType::String),
|
||||
("api_key", ColType::StringUniq),
|
||||
("name", ColType::String),
|
||||
("reset_token", ColType::StringNull),
|
||||
("reset_sent_at", ColType::TimestampWithTimeZoneNull),
|
||||
("email_verification_token", ColType::StringNull),
|
||||
(
|
||||
"email_verification_sent_at",
|
||||
ColType::TimestampWithTimeZoneNull,
|
||||
),
|
||||
("email_verified_at", ColType::TimestampWithTimeZoneNull),
|
||||
("magic_link_token", ColType::StringNull),
|
||||
("magic_link_expiration", ColType::TimestampWithTimeZoneNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "users").await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
26
migration/src/m20250724_214338_music_libraries.rs
Normal file
26
migration/src/m20250724_214338_music_libraries.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(m, "music_libraries",
|
||||
&[
|
||||
|
||||
("id", ColType::PkAuto),
|
||||
|
||||
("path", ColType::StringNull),
|
||||
],
|
||||
&[
|
||||
("user", ""),
|
||||
]
|
||||
).await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "music_libraries").await
|
||||
}
|
||||
}
|
29
migration/src/m20250724_214844_music_files.rs
Normal file
29
migration/src/m20250724_214844_music_files.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"music_files",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("path", ColType::String),
|
||||
("title", ColType::StringNull),
|
||||
("artist", ColType::StringNull),
|
||||
("album", ColType::StringNull),
|
||||
("metadata", ColType::JsonNull),
|
||||
],
|
||||
&[("music_library", "")],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "music_files").await
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum MusicFiles {
|
||||
Table,
|
||||
MusicLibraryId,
|
||||
Path,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx_unique_path_per_library")
|
||||
.table(MusicFiles::Table)
|
||||
.col(MusicFiles::MusicLibraryId)
|
||||
.col(MusicFiles::Path)
|
||||
.unique()
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_index(Index::drop().name("idx_unique_path_per_library").to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user