Throw away flix files in favor of a flix database

This commit is contained in:
2025-09-18 22:41:34 -06:00
parent ba9c3fa03d
commit 06110b91a1
117 changed files with 8645 additions and 1054 deletions
+53
View File
@@ -0,0 +1,53 @@
//! Adds entity/info tables:
//! - Collections
//! - Movies
//! - Shows
//! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections;
mod episodes;
mod movies;
mod seasons;
mod shows;
#[allow(unused_imports)]
pub use collections::FlixInfoCollections;
#[allow(unused_imports)]
pub use episodes::FlixInfoEpisodes;
#[allow(unused_imports)]
pub use movies::FlixInfoMovies;
#[allow(unused_imports)]
pub use seasons::FlixInfoSeasons;
#[allow(unused_imports)]
pub use shows::FlixInfoShows;
#[derive(DeriveMigrationName)]
pub(super) struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
collections::up(manager).await?;
movies::up(manager).await?;
shows::up(manager).await?;
seasons::up(manager).await?;
episodes::up(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::down(manager).await?;
seasons::down(manager).await?;
shows::down(manager).await?;
movies::down(manager).await?;
collections::down(manager).await?;
Ok(())
}
}
@@ -0,0 +1,46 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::string;
#[derive(Iden)]
pub enum FlixInfoCollections {
Table,
Id,
Title,
Overview,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixInfoCollections::Table)
.col(sqlite_rowid_alias(FlixInfoCollections::Id))
.col(string(FlixInfoCollections::Title))
.col(string(FlixInfoCollections::Overview))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_info_collections-title")
.table(FlixInfoCollections::Table)
.col(FlixInfoCollections::Title)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixInfoCollections::Table).to_owned())
.await
}
@@ -0,0 +1,68 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer, string};
use crate::migration::m_000001::FlixInfoShows;
use super::FlixInfoSeasons;
#[derive(Iden)]
pub enum FlixInfoEpisodes {
Table,
Show,
Season,
Episode,
Title,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixInfoEpisodes::Table)
.col(integer(FlixInfoEpisodes::Show))
.col(integer(FlixInfoEpisodes::Season))
.col(integer(FlixInfoEpisodes::Episode))
.col(string(FlixInfoEpisodes::Title))
.col(string(FlixInfoEpisodes::Overview))
.col(date(FlixInfoEpisodes::Date))
.primary_key(
Index::create()
.col(FlixInfoEpisodes::Show)
.col(FlixInfoEpisodes::Season)
.col(FlixInfoEpisodes::Episode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_info_episodes-show")
.from_tbl(FlixInfoEpisodes::Table)
.from_col(FlixInfoEpisodes::Show)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_info_episodes-show_season")
.from_tbl(FlixInfoEpisodes::Table)
.from_col(FlixInfoEpisodes::Show)
.from_col(FlixInfoEpisodes::Season)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixInfoEpisodes::Table).to_owned())
.await
}
@@ -0,0 +1,60 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, string};
#[derive(Iden)]
pub enum FlixInfoMovies {
Table,
Id,
Title,
Tagline,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixInfoMovies::Table)
.col(sqlite_rowid_alias(FlixInfoMovies::Id))
.col(string(FlixInfoMovies::Title))
.col(string(FlixInfoMovies::Tagline))
.col(string(FlixInfoMovies::Overview))
.col(date(FlixInfoMovies::Date))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_info_movies-title")
.table(FlixInfoMovies::Table)
.col(FlixInfoMovies::Title)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_info_movies-date")
.table(FlixInfoMovies::Table)
.col(FlixInfoMovies::Date)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixInfoMovies::Table).to_owned())
.await
}
@@ -0,0 +1,53 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer, string};
use super::FlixInfoShows;
#[derive(Iden)]
pub enum FlixInfoSeasons {
Table,
Show,
Season,
Title,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixInfoSeasons::Table)
.col(integer(FlixInfoSeasons::Show))
.col(integer(FlixInfoSeasons::Season))
.col(string(FlixInfoSeasons::Title))
.col(string(FlixInfoSeasons::Overview))
.col(date(FlixInfoSeasons::Date))
.primary_key(
Index::create()
.col(FlixInfoSeasons::Show)
.col(FlixInfoSeasons::Season),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_info_seasons-show")
.from_tbl(FlixInfoSeasons::Table)
.from_col(FlixInfoSeasons::Show)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixInfoSeasons::Table).to_owned())
.await
}
+60
View File
@@ -0,0 +1,60 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, string};
#[derive(Iden)]
pub enum FlixInfoShows {
Table,
Id,
Title,
Tagline,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixInfoShows::Table)
.col(sqlite_rowid_alias(FlixInfoShows::Id))
.col(string(FlixInfoShows::Title))
.col(string(FlixInfoShows::Tagline))
.col(string(FlixInfoShows::Overview))
.col(date(FlixInfoShows::Date))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_info_shows-title")
.table(FlixInfoShows::Table)
.col(FlixInfoShows::Title)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_info_shows-date")
.table(FlixInfoShows::Table)
.col(FlixInfoShows::Date)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixInfoShows::Table).to_owned())
.await
}
+53
View File
@@ -0,0 +1,53 @@
//! Adds entity/tmdb tables:
//! - Collections
//! - Movies
//! - Shows
//! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections;
mod episodes;
mod movies;
mod seasons;
mod shows;
#[allow(unused_imports)]
pub use collections::FlixTmdbCollections;
#[allow(unused_imports)]
pub use episodes::FlixTmdbEpisodes;
#[allow(unused_imports)]
pub use movies::FlixTmdbMovies;
#[allow(unused_imports)]
pub use seasons::FlixTmdbSeasons;
#[allow(unused_imports)]
pub use shows::FlixTmdbShows;
#[derive(DeriveMigrationName)]
pub(super) struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
collections::up(manager).await?;
movies::up(manager).await?;
shows::up(manager).await?;
seasons::up(manager).await?;
episodes::up(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::down(manager).await?;
seasons::down(manager).await?;
shows::down(manager).await?;
movies::down(manager).await?;
collections::down(manager).await?;
Ok(())
}
}
@@ -0,0 +1,58 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use super::super::m_000001::FlixInfoCollections;
#[derive(Iden)]
pub enum FlixTmdbCollections {
Table,
TmdbId,
FlixId,
LastUpdate,
MovieCount,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbCollections::Table)
.col(sqlite_rowid_alias(FlixTmdbCollections::TmdbId))
.col(integer(FlixTmdbCollections::FlixId).unique_key())
.col(date(FlixTmdbCollections::LastUpdate))
.col(integer(FlixTmdbCollections::MovieCount))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_collections-flixid")
.from_tbl(FlixTmdbCollections::Table)
.from_col(FlixTmdbCollections::FlixId)
.to_tbl(FlixInfoCollections::Table)
.to_col(FlixInfoCollections::Id),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_tmdb_collections-flixid")
.table(FlixTmdbCollections::Table)
.col(FlixTmdbCollections::FlixId)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbCollections::Table).to_owned())
.await
}
@@ -0,0 +1,94 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use super::super::m_000001::{FlixInfoEpisodes, FlixInfoSeasons};
use super::FlixTmdbSeasons;
#[derive(Iden)]
pub enum FlixTmdbEpisodes {
Table,
TmdbShow,
TmdbSeason,
TmdbEpisode,
FlixShow,
FlixSeason,
FlixEpisode,
LastUpdate,
Runtime,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbEpisodes::Table)
.col(integer(FlixTmdbEpisodes::TmdbShow))
.col(integer(FlixTmdbEpisodes::TmdbSeason))
.col(integer(FlixTmdbEpisodes::TmdbEpisode))
.col(integer(FlixTmdbEpisodes::FlixShow))
.col(integer(FlixTmdbEpisodes::FlixSeason))
.col(integer(FlixTmdbEpisodes::FlixEpisode))
.col(date(FlixTmdbEpisodes::LastUpdate))
.col(integer(FlixTmdbEpisodes::Runtime))
.primary_key(
Index::create()
.col(FlixTmdbEpisodes::TmdbShow)
.col(FlixTmdbEpisodes::TmdbSeason)
.col(FlixTmdbEpisodes::TmdbEpisode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_episodes-tmdb_show_season")
.from_tbl(FlixTmdbEpisodes::Table)
.from_col(FlixTmdbEpisodes::TmdbShow)
.from_col(FlixTmdbEpisodes::TmdbSeason)
.to_tbl(FlixTmdbSeasons::Table)
.to_col(FlixTmdbSeasons::TmdbShow)
.to_col(FlixTmdbSeasons::TmdbSeason),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_episodes-flix_show_season")
.from_tbl(FlixTmdbEpisodes::Table)
.from_col(FlixTmdbEpisodes::FlixShow)
.from_col(FlixTmdbEpisodes::FlixSeason)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_episodes-flix_show_season_episode")
.from_tbl(FlixTmdbEpisodes::Table)
.from_col(FlixTmdbEpisodes::FlixShow)
.from_col(FlixTmdbEpisodes::FlixSeason)
.from_col(FlixTmdbEpisodes::FlixEpisode)
.to_tbl(FlixInfoEpisodes::Table)
.to_col(FlixInfoEpisodes::Show)
.to_col(FlixInfoEpisodes::Season)
.to_col(FlixInfoEpisodes::Episode),
)
.index(
Index::create()
.unique()
.name("idx-flix_tmdb_episodes-flix_show_season_episode")
.col(FlixTmdbEpisodes::FlixShow)
.col(FlixTmdbEpisodes::FlixSeason)
.col(FlixTmdbEpisodes::FlixEpisode),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbEpisodes::Table).to_owned())
.await
}
@@ -0,0 +1,70 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer, integer_null};
use crate::migration::m_000002::FlixTmdbCollections;
use super::super::m_000001::FlixInfoMovies;
#[derive(Iden)]
pub enum FlixTmdbMovies {
Table,
TmdbId,
FlixId,
LastUpdate,
Runtime,
Collection,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbMovies::Table)
.col(sqlite_rowid_alias(FlixTmdbMovies::TmdbId))
.col(integer(FlixTmdbMovies::FlixId).unique_key())
.col(date(FlixTmdbMovies::LastUpdate))
.col(integer(FlixTmdbMovies::Runtime))
.col(integer_null(FlixTmdbMovies::Collection))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_movies-flixid")
.from_tbl(FlixTmdbMovies::Table)
.from_col(FlixTmdbMovies::FlixId)
.to_tbl(FlixInfoMovies::Table)
.to_col(FlixInfoMovies::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_movies-collectionid")
.from_tbl(FlixTmdbMovies::Table)
.from_col(FlixTmdbMovies::Collection)
.to_tbl(FlixTmdbCollections::Table)
.to_col(FlixTmdbCollections::TmdbId),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_tmdb_movies-flixid")
.table(FlixTmdbMovies::Table)
.col(FlixTmdbMovies::FlixId)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbMovies::Table).to_owned())
.await
}
@@ -0,0 +1,82 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use crate::migration::m_000001::FlixInfoShows;
use super::super::m_000001::FlixInfoSeasons;
use super::FlixTmdbShows;
#[derive(Iden)]
pub enum FlixTmdbSeasons {
Table,
TmdbShow,
TmdbSeason,
FlixShow,
FlixSeason,
LastUpdate,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbSeasons::Table)
.col(integer(FlixTmdbSeasons::TmdbShow))
.col(integer(FlixTmdbSeasons::TmdbSeason))
.col(integer(FlixTmdbSeasons::FlixShow))
.col(integer(FlixTmdbSeasons::FlixSeason))
.col(date(FlixTmdbSeasons::LastUpdate))
.primary_key(
Index::create()
.col(FlixTmdbSeasons::TmdbShow)
.col(FlixTmdbSeasons::TmdbSeason),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_seasons-tmdb_show")
.from_tbl(FlixTmdbSeasons::Table)
.from_col(FlixTmdbSeasons::FlixShow)
.to_tbl(FlixTmdbShows::Table)
.to_col(FlixTmdbShows::FlixId),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_seasons-flix_show")
.from_tbl(FlixTmdbSeasons::Table)
.from_col(FlixTmdbSeasons::FlixShow)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_seasons-flix_show_season")
.from_tbl(FlixTmdbSeasons::Table)
.from_col(FlixTmdbSeasons::FlixShow)
.from_col(FlixTmdbSeasons::FlixSeason)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.index(
Index::create()
.unique()
.name("idx-flix_tmdb_seasons-flix_show_season")
.col(FlixTmdbSeasons::FlixShow)
.col(FlixTmdbSeasons::FlixSeason),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbSeasons::Table).to_owned())
.await
}
+58
View File
@@ -0,0 +1,58 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use super::super::m_000001::FlixInfoShows;
#[derive(Iden)]
pub enum FlixTmdbShows {
Table,
TmdbId,
FlixId,
LastUpdate,
NumberOfSeasons,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbShows::Table)
.col(sqlite_rowid_alias(FlixTmdbShows::TmdbId))
.col(integer(FlixTmdbShows::FlixId).unique_key())
.col(date(FlixTmdbShows::LastUpdate))
.col(integer(FlixTmdbShows::NumberOfSeasons))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_shows-flixid")
.from_tbl(FlixTmdbShows::Table)
.from_col(FlixTmdbShows::FlixId)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_tmdb_shows-flixid")
.table(FlixTmdbShows::Table)
.col(FlixTmdbShows::FlixId)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbShows::Table).to_owned())
.await
}
+59
View File
@@ -0,0 +1,59 @@
//! Adds entity/content tables:
//! - Libraries
//! - Collections
//! - Movies
//! - Shows
//! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections;
mod episodes;
mod libraries;
mod movies;
mod seasons;
mod shows;
#[allow(unused_imports)]
pub use collections::FlixCollections;
#[allow(unused_imports)]
pub use episodes::FlixEpisodes;
#[allow(unused_imports)]
pub use libraries::FlixLibraries;
#[allow(unused_imports)]
pub use movies::FlixMovies;
#[allow(unused_imports)]
pub use seasons::FlixSeasons;
#[allow(unused_imports)]
pub use shows::FlixShows;
#[derive(DeriveMigrationName)]
pub(super) struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
libraries::up(manager).await?;
collections::up(manager).await?;
movies::up(manager).await?;
shows::up(manager).await?;
seasons::up(manager).await?;
episodes::up(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::down(manager).await?;
seasons::down(manager).await?;
shows::down(manager).await?;
movies::down(manager).await?;
collections::down(manager).await?;
libraries::down(manager).await?;
Ok(())
}
}
@@ -0,0 +1,69 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, binary_null, integer, integer_null, string};
use crate::migration::m_000001::FlixInfoCollections;
use crate::migration::m_000003::FlixLibraries;
#[derive(Iden)]
pub enum FlixCollections {
Table,
Id,
Parent,
Slug,
Library,
Directory,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixCollections::Table)
.col(sqlite_rowid_alias(FlixCollections::Id))
.col(integer_null(FlixCollections::Parent))
.col(string(FlixCollections::Slug))
.col(integer(FlixCollections::Library))
.col(binary(FlixCollections::Directory))
.col(binary_null(FlixCollections::RelativePosterPath))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_collections-id")
.from_tbl(FlixCollections::Table)
.from_col(FlixCollections::Id)
.to_tbl(FlixInfoCollections::Table)
.to_col(FlixInfoCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_collections-parent")
.from_tbl(FlixCollections::Table)
.from_col(FlixCollections::Parent)
.to_tbl(FlixCollections::Table)
.to_col(FlixCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_collections-library")
.from_tbl(FlixCollections::Table)
.from_col(FlixCollections::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixCollections::Table).to_owned())
.await
}
@@ -0,0 +1,73 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, binary_null, integer, string};
use crate::migration::m_000001::FlixInfoEpisodes;
use crate::migration::m_000003::FlixLibraries;
#[derive(Iden)]
pub enum FlixEpisodes {
Table,
Show,
Season,
Episode,
Slug,
Library,
Directory,
RelativeMediaPath,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixEpisodes::Table)
.col(integer(FlixEpisodes::Show))
.col(integer(FlixEpisodes::Season))
.col(integer(FlixEpisodes::Episode))
.col(string(FlixEpisodes::Slug))
.col(integer(FlixEpisodes::Library))
.col(binary(FlixEpisodes::Directory))
.col(binary(FlixEpisodes::RelativeMediaPath))
.col(binary_null(FlixEpisodes::RelativePosterPath))
.primary_key(
Index::create()
.col(FlixEpisodes::Show)
.col(FlixEpisodes::Season)
.col(FlixEpisodes::Episode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_episodes-show_season_episode")
.from_tbl(FlixEpisodes::Table)
.from_col(FlixEpisodes::Show)
.from_col(FlixEpisodes::Season)
.from_col(FlixEpisodes::Episode)
.to_tbl(FlixInfoEpisodes::Table)
.to_col(FlixInfoEpisodes::Show)
.to_col(FlixInfoEpisodes::Season)
.to_col(FlixInfoEpisodes::Episode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_episodes-library")
.from_tbl(FlixEpisodes::Table)
.from_col(FlixEpisodes::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixEpisodes::Table).to_owned())
.await
}
@@ -0,0 +1,34 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::Table;
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::binary;
#[derive(Iden)]
pub enum FlixLibraries {
Table,
Id,
Directory,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixLibraries::Table)
.col(sqlite_rowid_alias(FlixLibraries::Id))
.col(binary(FlixLibraries::Directory))
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixLibraries::Table).to_owned())
.await
}
@@ -0,0 +1,71 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, binary_null, integer, integer_null, string};
use crate::migration::m_000001::FlixInfoMovies;
use crate::migration::m_000003::{FlixCollections, FlixLibraries};
#[derive(Iden)]
pub enum FlixMovies {
Table,
Id,
Parent,
Slug,
Library,
Directory,
RelativeMediaPath,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixMovies::Table)
.col(sqlite_rowid_alias(FlixMovies::Id))
.col(integer_null(FlixMovies::Parent))
.col(string(FlixMovies::Slug))
.col(integer(FlixMovies::Library))
.col(binary(FlixMovies::Directory))
.col(binary(FlixMovies::RelativeMediaPath))
.col(binary_null(FlixMovies::RelativePosterPath))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_movies-id")
.from_tbl(FlixMovies::Table)
.from_col(FlixMovies::Id)
.to_tbl(FlixInfoMovies::Table)
.to_col(FlixInfoMovies::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_movies-parent")
.from_tbl(FlixMovies::Table)
.from_col(FlixMovies::Parent)
.to_tbl(FlixCollections::Table)
.to_col(FlixCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_movies-library")
.from_tbl(FlixMovies::Table)
.from_col(FlixMovies::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixMovies::Table).to_owned())
.await
}
@@ -0,0 +1,66 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, binary_null, integer, string};
use crate::migration::m_000001::FlixInfoSeasons;
use crate::migration::m_000003::FlixLibraries;
#[derive(Iden)]
pub enum FlixSeasons {
Table,
Show,
Season,
Slug,
Library,
Directory,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixSeasons::Table)
.col(integer(FlixSeasons::Show))
.col(integer(FlixSeasons::Season))
.col(string(FlixSeasons::Slug))
.col(integer(FlixSeasons::Library))
.col(binary(FlixSeasons::Directory))
.col(binary_null(FlixSeasons::RelativePosterPath))
.primary_key(
Index::create()
.col(FlixSeasons::Show)
.col(FlixSeasons::Season),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_seasons-show_season")
.from_tbl(FlixSeasons::Table)
.from_col(FlixSeasons::Show)
.from_col(FlixSeasons::Season)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_seasons-library")
.from_tbl(FlixSeasons::Table)
.from_col(FlixSeasons::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixSeasons::Table).to_owned())
.await
}
+69
View File
@@ -0,0 +1,69 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, binary_null, integer, integer_null, string};
use crate::migration::m_000001::FlixInfoShows;
use crate::migration::m_000003::{FlixCollections, FlixLibraries};
#[derive(Iden)]
pub enum FlixShows {
Table,
Id,
Parent,
Slug,
Library,
Directory,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixShows::Table)
.col(sqlite_rowid_alias(FlixShows::Id))
.col(integer_null(FlixShows::Parent))
.col(string(FlixShows::Slug))
.col(integer(FlixShows::Library))
.col(binary(FlixShows::Directory))
.col(binary_null(FlixShows::RelativePosterPath))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_shows-id")
.from_tbl(FlixShows::Table)
.from_col(FlixShows::Id)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_shows-parent")
.from_tbl(FlixShows::Table)
.from_col(FlixShows::Parent)
.to_tbl(FlixCollections::Table)
.to_col(FlixCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_shows-library")
.from_tbl(FlixShows::Table)
.from_col(FlixShows::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixShows::Table).to_owned())
.await
}
+47
View File
@@ -0,0 +1,47 @@
//! Adds entity/watched tables:
//! - Collections
//! - Movies
//! - Shows
//! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections;
mod episodes;
mod movies;
mod seasons;
mod shows;
#[allow(unused_imports)]
pub use episodes::FlixWatchedEpisodes;
#[allow(unused_imports)]
pub use movies::FlixWatchedMovies;
#[derive(DeriveMigrationName)]
pub(super) struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::up(manager).await?;
seasons::up(manager).await?;
shows::up(manager).await?;
movies::up(manager).await?;
collections::up(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
collections::down(manager).await?;
movies::down(manager).await?;
shows::down(manager).await?;
seasons::down(manager).await?;
episodes::down(manager).await?;
Ok(())
}
}
@@ -0,0 +1,98 @@
use sea_orm::DbErr;
use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm_migration::SchemaManager;
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
CREATE VIEW flix_watched_collections AS
WITH RECURSIVE
watched_items AS (
SELECT
w.id,
w.user_id,
w.watched_date,
'movie' AS type
FROM flix_watched_movies w
UNION ALL
SELECT
w.id,
w.user_id,
w.watched_date,
'show' AS type
FROM flix_watched_shows w
),
collection_items AS (
SELECT
m.parent,
m.id,
'movie' AS type
FROM flix_movies m
WHERE m.parent IS NOT NULL
UNION ALL
SELECT
s.parent,
s.id,
'show' AS type
FROM flix_shows s
WHERE s.parent IS NOT NULL
UNION ALL
SELECT
c.parent,
ci.id,
ci.type
FROM collection_items ci
JOIN flix_collections c
ON c.id = ci.parent
)
SELECT
ci.parent AS id,
wi.user_id,
MAX(wi.watched_date) AS watched_date
FROM collection_items ci
JOIN watched_items wi
ON wi.id = ci.id
AND wi.type = ci.type
WHERE NOT EXISTS (
SELECT 1
FROM collection_items ci2
WHERE ci2.parent = ci.parent
AND NOT EXISTS (
SELECT 1
FROM watched_items wi2
WHERE wi2.id = ci2.id
AND wi2.type = ci2.type
AND wi2.user_id = wi.user_id
)
)
GROUP BY ci.parent, wi.user_id;
"#,
))
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_collections
;
"#,
))
.await?;
Ok(())
}
@@ -0,0 +1,60 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use crate::migration::m_000001::FlixInfoEpisodes;
#[derive(Iden)]
pub enum FlixWatchedEpisodes {
Table,
Show,
Season,
Episode,
UserId,
WatchedDate,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixWatchedEpisodes::Table)
.col(integer(FlixWatchedEpisodes::Show))
.col(integer(FlixWatchedEpisodes::Season))
.col(integer(FlixWatchedEpisodes::Episode))
.col(integer(FlixWatchedEpisodes::UserId))
.col(date(FlixWatchedEpisodes::WatchedDate))
.primary_key(
Index::create()
.col(FlixWatchedEpisodes::Show)
.col(FlixWatchedEpisodes::Season)
.col(FlixWatchedEpisodes::Episode)
.col(FlixWatchedEpisodes::UserId),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_watched_episodes-show_season_episode")
.from_tbl(FlixWatchedEpisodes::Table)
.from_tbl(FlixWatchedEpisodes::Table)
.from_col(FlixWatchedEpisodes::Show)
.from_col(FlixWatchedEpisodes::Season)
.from_col(FlixWatchedEpisodes::Episode)
.to_tbl(FlixInfoEpisodes::Table)
.to_col(FlixInfoEpisodes::Show)
.to_col(FlixInfoEpisodes::Season)
.to_col(FlixInfoEpisodes::Episode),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixWatchedEpisodes::Table).to_owned())
.await
}
@@ -0,0 +1,49 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use crate::migration::m_000001::FlixInfoMovies;
#[derive(Iden)]
pub enum FlixWatchedMovies {
Table,
Id,
UserId,
WatchedDate,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixWatchedMovies::Table)
.col(integer(FlixWatchedMovies::Id))
.col(integer(FlixWatchedMovies::UserId))
.col(date(FlixWatchedMovies::WatchedDate))
.primary_key(
Index::create()
.col(FlixWatchedMovies::Id)
.col(FlixWatchedMovies::UserId),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_watched_movies-id")
.from_tbl(FlixWatchedMovies::Table)
.from_col(FlixWatchedMovies::Id)
.to_tbl(FlixInfoMovies::Table)
.to_col(FlixInfoMovies::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixWatchedMovies::Table).to_owned())
.await
}
@@ -0,0 +1,54 @@
use sea_orm::DbErr;
use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm_migration::SchemaManager;
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
CREATE VIEW flix_watched_seasons AS
SELECT
w.show,
w.season,
w.user_id,
MAX(w.watched_date) AS watched_date
FROM flix_watched_episodes w
WHERE NOT EXISTS (
SELECT 1
FROM flix_episodes e
WHERE e.show = w.show
AND e.season = w.season
AND NOT EXISTS (
SELECT 1
FROM flix_watched_episodes wc
WHERE wc.show = e.show
AND wc.season = e.season
AND wc.episode = e.episode
AND wc.user_id = w.user_id
)
)
GROUP BY w.show, w.season, w.user_id
;
"#,
))
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_seasons
;
"#,
))
.await?;
Ok(())
}
+51
View File
@@ -0,0 +1,51 @@
use sea_orm::DbErr;
use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm_migration::SchemaManager;
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
CREATE VIEW flix_watched_shows AS
SELECT
w.show as id,
w.user_id,
MAX(w.watched_date) AS watched_date
FROM flix_watched_seasons w
WHERE NOT EXISTS (
SELECT 1
FROM flix_seasons s
WHERE s.show = w.show
AND NOT EXISTS (
SELECT 1
FROM flix_watched_seasons wc
WHERE wc.show = s.show
AND wc.season = s.season
AND wc.user_id = w.user_id
)
)
GROUP BY w.show, w.user_id
;
"#,
))
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_shows
;
"#,
))
.await?;
Ok(())
}
+9
View File
@@ -0,0 +1,9 @@
//! Migrations for maintaining the database schema
seamantic::migrations! {
"seaql_migrations_flix";
m_000001,
m_000002,
m_000003,
m_000004,
}