-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
465 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ pub mod base; | |
pub mod id; | ||
pub mod migrations; | ||
pub mod user; | ||
pub mod video; | ||
pub mod view; | ||
pub mod watch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod m20240204_000001_users; | ||
pub mod m20240218_000002_videos; | ||
pub mod m20240218_000003_views; | ||
pub mod m20240218_000004_watches; | ||
pub mod migrator; |
81 changes: 81 additions & 0 deletions
81
backend-rs/streamfox/src/models/migrations/m20240218_000002_videos.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use crate::models::migrations::m20240204_000001_users::User; | ||
use sea_orm_migration::prelude::*; | ||
|
||
pub struct Migration; | ||
|
||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m_20240218_000002_videos" | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(Video::Table) | ||
.col( | ||
ColumnDef::new(Video::Id) | ||
.big_integer() | ||
.not_null() | ||
.primary_key(), | ||
) | ||
.col( | ||
ColumnDef::new(Video::CreatedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(Video::UpdatedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col(ColumnDef::new(Video::Status).small_integer().not_null()) | ||
.col(ColumnDef::new(Video::MimeType).text().not_null()) | ||
.col(ColumnDef::new(Video::DurationSecs).integer().not_null()) | ||
.col(ColumnDef::new(Video::SizeBytes).big_integer().not_null()) | ||
.col( | ||
ColumnDef::new(Video::SubtitlesExtracted) | ||
.boolean() | ||
.not_null(), | ||
) | ||
.col(ColumnDef::new(Video::CreatorId).big_integer().not_null()) | ||
.col(ColumnDef::new(Video::Name).text().not_null()) | ||
.col(ColumnDef::new(Video::Description).text().not_null()) | ||
.col(ColumnDef::new(Video::Visibility).small_integer().not_null()) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-video-creator") | ||
.from(Video::Table, Video::CreatorId) | ||
.to(User::Table, User::Id), | ||
) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(Video::Table).to_owned()) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(Iden)] | ||
pub enum Video { | ||
Table, | ||
Id, | ||
CreatedAt, | ||
UpdatedAt, | ||
Status, | ||
MimeType, | ||
DurationSecs, | ||
SizeBytes, | ||
SubtitlesExtracted, | ||
CreatorId, | ||
Name, | ||
Description, | ||
Visibility, | ||
} |
78 changes: 78 additions & 0 deletions
78
backend-rs/streamfox/src/models/migrations/m20240218_000003_views.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use crate::models::migrations::m20240204_000001_users::User; | ||
use crate::models::migrations::m20240218_000002_videos::Video; | ||
use sea_orm_migration::prelude::*; | ||
|
||
pub struct Migration; | ||
|
||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m_20240218_000003_views" | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(View::Table) | ||
.col( | ||
ColumnDef::new(View::Id) | ||
.big_integer() | ||
.not_null() | ||
.primary_key(), | ||
) | ||
.col( | ||
ColumnDef::new(View::CreatedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(View::UpdatedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col(ColumnDef::new(View::UserId).big_integer().not_null()) | ||
.col(ColumnDef::new(View::VideoId).big_integer().not_null()) | ||
.col( | ||
ColumnDef::new(View::StartedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col(ColumnDef::new(View::BytesStreamed).big_integer().not_null()) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-view-user") | ||
.from(View::Table, View::UserId) | ||
.to(User::Table, User::Id), | ||
) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-view-video") | ||
.from(View::Table, View::VideoId) | ||
.to(Video::Table, Video::Id), | ||
) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(View::Table).to_owned()) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(Iden)] | ||
pub enum View { | ||
Table, | ||
Id, | ||
CreatedAt, | ||
UpdatedAt, | ||
UserId, | ||
VideoId, | ||
StartedAt, | ||
BytesStreamed, | ||
} |
87 changes: 87 additions & 0 deletions
87
backend-rs/streamfox/src/models/migrations/m20240218_000004_watches.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use crate::models::migrations::m20240204_000001_users::User; | ||
use crate::models::migrations::m20240218_000002_videos::Video; | ||
use sea_orm_migration::prelude::*; | ||
|
||
pub struct Migration; | ||
|
||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m_20240218_000004_watches" | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(Watch::Table) | ||
.col( | ||
ColumnDef::new(Watch::UserId) | ||
.big_integer() | ||
.not_null() | ||
.primary_key(), | ||
) | ||
.col(ColumnDef::new(Watch::VideoId).big_integer().not_null()) | ||
.col( | ||
ColumnDef::new(Watch::ViewId) | ||
.big_integer() | ||
.not_null() | ||
.unique_key(), | ||
) | ||
.col( | ||
ColumnDef::new(Watch::CreatedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(Watch::UpdatedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(Watch::StartedAt) | ||
.timestamp_with_time_zone() | ||
.not_null(), | ||
) | ||
.col( | ||
ColumnDef::new(Watch::BytesStreamed) | ||
.big_integer() | ||
.not_null(), | ||
) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-watch-user") | ||
.from(Watch::Table, Watch::UserId) | ||
.to(User::Table, User::Id), | ||
) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-watch-video") | ||
.from(Watch::Table, Watch::VideoId) | ||
.to(Video::Table, Video::Id), | ||
) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(Watch::Table).to_owned()) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(Iden)] | ||
pub enum Watch { | ||
Table, | ||
UserId, | ||
VideoId, | ||
ViewId, | ||
CreatedAt, | ||
UpdatedAt, | ||
StartedAt, | ||
BytesStreamed, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
use crate::models::migrations::m20240204_000001_users; | ||
use crate::models::migrations::{ | ||
m20240204_000001_users, m20240218_000002_videos, m20240218_000003_views, m20240218_000004_watches, | ||
}; | ||
use sea_orm_migration::prelude::*; | ||
|
||
pub struct Migrator; | ||
|
||
#[async_trait::async_trait] | ||
impl MigratorTrait for Migrator { | ||
fn migrations() -> Vec<Box<dyn MigrationTrait>> { | ||
vec![Box::new(m20240204_000001_users::Migration)] | ||
vec![ | ||
Box::new(m20240204_000001_users::Migration), | ||
Box::new(m20240218_000002_videos::Migration), | ||
Box::new(m20240218_000003_views::Migration), | ||
Box::new(m20240218_000004_watches::Migration), | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use crate::models::id::Id; | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] | ||
#[sea_orm(rs_type = "i16", db_type = "SmallInteger")] | ||
#[serde(untagged)] | ||
pub enum Status { | ||
Created = 0, | ||
Uploading = 1, | ||
Processing = 2, | ||
Complete = 3, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] | ||
#[sea_orm(rs_type = "i16", db_type = "SmallInteger")] | ||
#[serde(untagged)] | ||
pub enum Visibility { | ||
Private = 0, | ||
Unlisted = 1, | ||
Public = 2, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(table_name = "video")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id: Id, | ||
pub created_at: DateTimeWithTimeZone, | ||
pub updated_at: DateTimeWithTimeZone, | ||
pub status: Status, | ||
#[sea_orm(column_type = "Text")] | ||
pub mime_type: String, | ||
pub duration_secs: i32, | ||
pub size_bytes: i64, | ||
pub subtitles_extracted: bool, | ||
pub creator_id: Id, | ||
#[sea_orm(column_type = "Text")] | ||
pub name: String, | ||
#[sea_orm(column_type = "Text")] | ||
pub description: String, | ||
pub visibility: Visibility, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::user::Entity", | ||
from = "Column::CreatorId", | ||
to = "super::user::Column::Id", | ||
on_update = "NoAction", | ||
on_delete = "NoAction" | ||
)] | ||
User, | ||
#[sea_orm(has_many = "super::view::Entity")] | ||
View, | ||
#[sea_orm(has_many = "super::watch::Entity")] | ||
Watch, | ||
} | ||
|
||
impl Related<super::user::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::User.def() | ||
} | ||
} | ||
|
||
impl Related<super::view::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::View.def() | ||
} | ||
} | ||
|
||
impl Related<super::watch::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Watch.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
Oops, something went wrong.