Added the playlist generator

This commit is contained in:
Connor Johnstone
2026-03-20 18:09:47 -04:00
parent 8a1435d9e9
commit f03f8f0362
8 changed files with 398 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
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(Playlists::Table)
.if_not_exists()
.col(
ColumnDef::new(Playlists::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Playlists::Name).text().not_null())
.col(ColumnDef::new(Playlists::Description).text())
.col(ColumnDef::new(Playlists::UserId).integer())
.col(
ColumnDef::new(Playlists::CreatedAt)
.date_time()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Playlists::UpdatedAt)
.date_time()
.not_null()
.default(Expr::current_timestamp()),
)
.foreign_key(
ForeignKey::create()
.from(Playlists::Table, Playlists::UserId)
.to(Users::Table, Users::Id),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(PlaylistTracks::Table)
.if_not_exists()
.col(
ColumnDef::new(PlaylistTracks::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(PlaylistTracks::PlaylistId)
.integer()
.not_null(),
)
.col(ColumnDef::new(PlaylistTracks::TrackId).integer().not_null())
.col(
ColumnDef::new(PlaylistTracks::Position)
.integer()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.from(PlaylistTracks::Table, PlaylistTracks::PlaylistId)
.to(Playlists::Table, Playlists::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKey::create()
.from(PlaylistTracks::Table, PlaylistTracks::TrackId)
.to(Tracks::Table, Tracks::Id),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_playlist_tracks_unique")
.table(PlaylistTracks::Table)
.col(PlaylistTracks::PlaylistId)
.col(PlaylistTracks::Position)
.unique()
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(PlaylistTracks::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Playlists::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Playlists {
Table,
Id,
Name,
Description,
UserId,
CreatedAt,
UpdatedAt,
}
#[derive(DeriveIden)]
enum PlaylistTracks {
Table,
Id,
PlaylistId,
TrackId,
Position,
}
#[derive(DeriveIden)]
enum Users {
Table,
Id,
}
#[derive(DeriveIden)]
enum Tracks {
Table,
Id,
}