Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change primary key structures (pass: 1) #847

Merged
merged 130 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
af12b08
fix(ts-utils): remove hoisted variables
IgnisDa May 20, 2024
d11afff
build(backend): upgrade deps
IgnisDa May 24, 2024
643f63e
feat(backend): update to new apalis version
IgnisDa May 24, 2024
58733be
chore(backend): remove comment
IgnisDa May 24, 2024
78ade83
refactor(backend): do not have star import
IgnisDa May 24, 2024
014376c
feat(backend): change to memory storage
IgnisDa May 26, 2024
89e5703
feat(*): remaining cleanup for new storage
IgnisDa May 26, 2024
8e16946
ci(backend): hoist dep to workspace
IgnisDa May 26, 2024
9c50bcd
feat(database): start migration collection data
IgnisDa May 26, 2024
2ac1560
feat(database): migrate all collection ids
IgnisDa May 26, 2024
8d211d7
chore(backend): change the type of collection id
IgnisDa May 26, 2024
3e02ee7
chore(frontend): migrate to new collection id data type
IgnisDa May 26, 2024
58f4083
chore(database): split steps
IgnisDa May 26, 2024
6762746
fix(backend): do not associate when no entity to associate to
IgnisDa May 26, 2024
c342008
chore(database): change migration script name
IgnisDa May 26, 2024
ae03b00
feat(database): change primary key values of review
IgnisDa May 26, 2024
6384001
chore(backend): adapt to new db schema
IgnisDa May 26, 2024
34f6aee
feat(*): adapt to new gql schema
IgnisDa May 26, 2024
c0f3019
fix(backend): generate new id for creating review
IgnisDa May 26, 2024
1abadc8
chore(backend): do not create ids incorrectly
IgnisDa May 26, 2024
b568c72
feat(backend): setup correct triggers
IgnisDa May 26, 2024
8104352
fix(database): rebuild correct primary keys and indices
IgnisDa May 26, 2024
cc8e9ad
feat(database): change existing migrations
IgnisDa May 26, 2024
6ef2072
feat(database): change primary key for seen table
IgnisDa May 26, 2024
184e2a6
feat(backend): adapt to new gql schema
IgnisDa May 26, 2024
e0ba0a0
chore(frontend): adapt to new gql schema
IgnisDa May 26, 2024
57fa43c
chore(database): change order of new migrations
IgnisDa May 26, 2024
cfe29a3
feat(database): change default value for calendar event
IgnisDa May 26, 2024
f0fbe1c
feat(backend): adapt to new database schema
IgnisDa May 26, 2024
8bf2ee2
chore(backend): remove useless binding
IgnisDa May 26, 2024
4bdd989
chore(database): change order of migrations
IgnisDa May 26, 2024
7c99a19
fix(database): change default prefix
IgnisDa May 26, 2024
f45817c
feat(database): migrate data of import report
IgnisDa May 26, 2024
268030b
Revert "fix(database): change default prefix"
IgnisDa May 26, 2024
b14041c
fix(frontend): add a data import attribute to html
IgnisDa May 26, 2024
5040e7a
chore(backend): adapt to new db schema
IgnisDa May 26, 2024
93904ce
fix(backend): use correct prefix for table
IgnisDa May 26, 2024
672e1d9
feat(database): migrate genre data
IgnisDa May 26, 2024
3b193e2
chore(database): change column types
IgnisDa May 26, 2024
bcae22f
fix(database): change name of constraint
IgnisDa May 26, 2024
dbef89f
chore(backend): additional attributes
IgnisDa May 26, 2024
94c3c0d
feat(backend): adapt to new database schema
IgnisDa May 26, 2024
2400810
chore(frontend): adapt to new gql schema
IgnisDa May 26, 2024
6b07fdd
fix(backend): cast into correct type
IgnisDa May 26, 2024
48e2e0f
feat(backend): remove useless genre
IgnisDa May 26, 2024
216ed94
fix(backend): add relation between entities
IgnisDa May 26, 2024
5a302e8
build(backend): bump version
IgnisDa May 26, 2024
c7d3f6c
chore(backend): remove un-needed deps
IgnisDa May 26, 2024
122b4fe
Merge branch 'main'
IgnisDa May 26, 2024
8f02a09
feat(database): migration for metadata group
IgnisDa May 27, 2024
5238327
feat(backend): adapt to new database schema
IgnisDa May 27, 2024
1a22180
chore(frontend): adapt to new gql schema
IgnisDa May 27, 2024
693882f
fix(backend): create unqiue index again
IgnisDa May 27, 2024
98221b5
feat(database): migration to change person PK
IgnisDa May 27, 2024
29c0836
feat(backend): adapt to new database schema
IgnisDa May 27, 2024
e841d98
chore(frontend): adapt to new gql schema
IgnisDa May 27, 2024
1e7fb97
chore(frontend): remove useless event
IgnisDa May 27, 2024
4642df9
Merge branch 'change-pk-struct-2' into change-pk-struct-1
IgnisDa May 27, 2024
a0a3499
feat(database): perform migration only when necessary
IgnisDa May 28, 2024
7474c1a
feat(database): add checks before migration
IgnisDa May 28, 2024
03edf02
fix(database): change column types for tables
IgnisDa May 28, 2024
758d501
feat(database): perform migration only when necessary
IgnisDa May 28, 2024
d8c8a33
feat(database): add checks before migration
IgnisDa May 28, 2024
38c503b
fix(database): change column types for tables
IgnisDa May 28, 2024
4a2cb57
fix(database): change more column types
IgnisDa May 28, 2024
a062a51
Merge branch 'change-pk-struct-1' into change-pk-struct-2
IgnisDa May 28, 2024
7d52b4e
fix(database): migrate 2 schemas
IgnisDa May 28, 2024
b58fa85
feat(database): migrate most of the tables
IgnisDa May 28, 2024
6f0365d
fix(database): set correct default values
IgnisDa May 28, 2024
f80ebae
feat(database): change order of seen table columns
IgnisDa May 28, 2024
dfe296f
chore(database): change order of columns
IgnisDa May 28, 2024
8a9615b
Merge branch 'change-pk-struct-1' into change-pk-struct-2
IgnisDa May 28, 2024
8d1c151
feat(database): change order of columns
IgnisDa May 28, 2024
c7d6141
chore(database): order of columns
IgnisDa May 28, 2024
f214d77
Merge branch 'change-pk-struct-1' into change-pk-struct-2
IgnisDa May 28, 2024
fdf5c59
feat(database): recreate constraint
IgnisDa May 28, 2024
d31db84
chore(database): change order of columns
IgnisDa May 28, 2024
a195243
chore(database): change order of migrations
IgnisDa May 28, 2024
e4fd8b6
chore(database): change name of migration
IgnisDa May 28, 2024
26d7e36
feat(database): migration to change metadata id to text
IgnisDa May 28, 2024
75651b6
refactor(database): change location of function
IgnisDa May 28, 2024
942c2bf
fix(database): do not set to not null
IgnisDa May 28, 2024
5d52927
feat(database): change types of columns
IgnisDa May 28, 2024
6473c45
chore(backend): remove sql cast
IgnisDa May 28, 2024
9acc891
chore(database): change order of columns
IgnisDa May 28, 2024
ca17848
chore(database): more ordering of columns
IgnisDa May 28, 2024
d01c788
feat(database): create indices
IgnisDa May 28, 2024
09adb20
chore(backend): adjust to new backend schema
IgnisDa May 29, 2024
c9eef45
feat(database): add reset summary migration
IgnisDa May 29, 2024
a1b8694
refactor(database): change order of fns
IgnisDa May 29, 2024
874fc1f
chore(graphql): generate new types
IgnisDa May 29, 2024
18cb6cd
chore(frontend): adapt to new gql schema
IgnisDa May 29, 2024
a37c246
fix(backend): modify partial selects
IgnisDa May 29, 2024
79a4db6
chore(backend): remove outdated volume
IgnisDa May 29, 2024
0d5c076
fix(frontend): use correct input
IgnisDa May 29, 2024
cf5c3eb
chore(docs): remove warning
IgnisDa May 29, 2024
d7c7d03
chore(database): change name of migration
IgnisDa May 29, 2024
10e45b1
chore(backend): change wording
IgnisDa May 29, 2024
79a771e
chore(database/migrations): show trace warnings and infos
IgnisDa May 29, 2024
bcc01c0
refactor(backend): change location of enum
IgnisDa May 30, 2024
f9dea4b
feat(database): add migration to change enums
IgnisDa May 30, 2024
757669e
chore(database): change names of migrations
IgnisDa May 30, 2024
9f942a2
feat(*): upgrade sea-orm version
IgnisDa May 30, 2024
e7a08b3
fix(frontend): revert to old sort by
IgnisDa May 30, 2024
2eff795
fix(frontend): correct filter type
IgnisDa May 30, 2024
11315d9
fix(backend): correct types for filter
IgnisDa May 30, 2024
17b6ac7
fix(backend): use correct filter for seen state
IgnisDa May 30, 2024
41d2bf5
chore(backend): remove state
IgnisDa May 30, 2024
95b0696
fix(database): remove useless attribute
IgnisDa May 30, 2024
5c9d494
feat(backend): prefix new workouts with `wor_`
IgnisDa May 30, 2024
6ab690f
feat(database): new prefix for workouts
IgnisDa May 30, 2024
5729996
feat(backend): do not generate workout id in hook
IgnisDa May 30, 2024
75f9489
chore(database): change name of migration
IgnisDa May 30, 2024
7732b56
fix(backend): correct logic for last updated and id
IgnisDa May 30, 2024
5cb82f1
fix(backend): no more useless processing of old workouts
IgnisDa May 30, 2024
29489b6
build(backend): remove dependency on git branch
IgnisDa May 30, 2024
7fc533e
chore: change name of migrations
IgnisDa May 30, 2024
d1b8aaf
feat(database): change casing of core enum
IgnisDa May 31, 2024
3967a16
fix(database): update one enum correctly
IgnisDa May 31, 2024
11b33e3
fix(database): do not set summary
IgnisDa May 31, 2024
f8bbcaa
feat(database,backend): change casing of stuff
IgnisDa May 31, 2024
d79bf32
fix(database): more casing handling
IgnisDa May 31, 2024
8c644fc
fix(database): update bests correctly
IgnisDa May 31, 2024
380b68e
build(backend): bump version
IgnisDa May 31, 2024
84b4530
fix(database): reset state changes for people
IgnisDa May 31, 2024
f3891b3
Revert "build(backend): bump version"
IgnisDa May 31, 2024
90da20d
Merge branch 'main'
IgnisDa May 31, 2024
e6c710c
Merge branch 'main'
IgnisDa May 31, 2024
feba770
chore(database): add logging to chaning enum
IgnisDa May 31, 2024
071aba7
build(backend): bump version
IgnisDa Jun 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 115 additions & 142 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ resolver = "2"

[workspace.dependencies]
anyhow = "1.0.82"
async-graphql = { version = "7.0.3", features = [
async-graphql = { version = "7.0.5", features = [
"chrono",
"decimal",
"log",
"tracing",
"uuid",
] }
chrono = "0.4.38"
nanoid = "0.4.0"
schematic = { version = "0.16", features = [
"config",
"json",
Expand All @@ -24,7 +25,7 @@ schematic = { version = "0.16", features = [
"renderer_template",
"yaml",
], default-features = false }
sea-orm = { version = "0.12.15", features = [
sea-orm = { version = "1.0.0-rc.5", features = [
"debug-print",
"postgres-array",
"macros",
Expand All @@ -35,7 +36,7 @@ sea-orm = { version = "0.12.15", features = [
"with-rust_decimal",
"with-uuid",
], default-features = false }
sea-orm-migration = "0.12.15"
sea-orm-migration = "1.0.0-rc.5"
serde = { version = "1.0.202", features = ["derive"] }
serde_json = "1.0.116"
strum = { version = "0.26.2", features = ["derive"] }
Expand Down
16 changes: 5 additions & 11 deletions apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
[package]
name = "ryot"
version = "5.4.7"
version = "5.5.0"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-3.0"

[dependencies]
anyhow = { workspace = true }
# TODO: Upgrade when https://github.com/geofmureithi/apalis/issues/301 is fixed
apalis = { version = "0.4.9", features = [
"cron",
"extensions",
"limit",
"sqlite",
] }
apalis = { version = "0.5.3", features = ["cron", "limit"] }
argon2 = "0.5.3"
async-graphql = { workspace = true }
async-graphql-axum = "7.0.3"
Expand Down Expand Up @@ -54,7 +48,7 @@ lettre = { version = "0.11.6", features = [
"builder",
], default-features = false }
markdown = "1.0.0-alpha.15"
nanoid = "0.4.0"
nanoid = { workspace = true }
openidconnect = "3.5.0"
paginate = "1.1.11"
rand = "0.8.5"
Expand All @@ -67,19 +61,19 @@ schematic = { workspace = true }
scraper = "0.19.0"
sea-orm = { workspace = true }
sea-orm-migration = { workspace = true }
sea-query = "0.30.7"
sea-query = "0.31.0-rc.6"
serde = { workspace = true }
serde_json = { workspace = true }
serde_with = { version = "3.7.0", features = ["chrono_0_4"] }
serde-xml-rs = "0.6.0"
slug = "0.1.5"
sqlx = { version = "0.7.4", default-features = false }
strum = { workspace = true }
struson = { version = "0.5.0", features = ["serde"] }
surf = { version = "2.3.2", features = [
"h1-client-rustls",
], default-features = false }
tokio = { version = "1.37.0", features = ["full"] }
tower = { version = "0.4.13", features = ["buffer"] }
tower-http = { version = "0.5.2", features = ["catch-panic", "cors", "trace"] }
tracing = { workspace = true }
tracing-subscriber = "0.3.18"
Expand Down
43 changes: 22 additions & 21 deletions apps/backend/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,26 @@ impl Job for ScheduledJob {
const NAME: &'static str = "apalis::ScheduledJob";
}

pub async fn media_jobs(_information: ScheduledJob, ctx: JobContext) -> Result<(), JobError> {
let misc_service = ctx.data::<Arc<MiscellaneousService>>().unwrap();
pub async fn media_jobs(
_information: ScheduledJob,
misc_service: Data<Arc<MiscellaneousService>>,
) -> Result<(), Error> {
misc_service.perform_media_jobs().await.unwrap();
Ok(())
}

pub async fn user_jobs(_information: ScheduledJob, ctx: JobContext) -> Result<(), JobError> {
let misc_service = ctx.data::<Arc<MiscellaneousService>>().unwrap();
pub async fn user_jobs(
_information: ScheduledJob,
misc_service: Data<Arc<MiscellaneousService>>,
) -> Result<(), Error> {
misc_service.perform_user_jobs().await.unwrap();
Ok(())
}

pub async fn yank_integrations_data(
_information: ScheduledJob,
ctx: JobContext,
) -> Result<(), JobError> {
let misc_service = ctx.data::<Arc<MiscellaneousService>>().unwrap();
misc_service: Data<Arc<MiscellaneousService>>,
) -> Result<(), Error> {
tracing::trace!("Getting data from yanked integrations for all users");
misc_service.yank_integrations_data().await.unwrap();
Ok(())
Expand All @@ -64,15 +67,14 @@ pub enum CoreApplicationJob {
BulkProgressUpdate(i32, Vec<ProgressUpdateInput>),
}

impl Job for CoreApplicationJob {
impl Message for CoreApplicationJob {
const NAME: &'static str = "apalis::CoreApplicationJob";
}

pub async fn perform_core_application_job(
information: CoreApplicationJob,
ctx: JobContext,
) -> Result<(), JobError> {
let misc_service = ctx.data::<Arc<MiscellaneousService>>().unwrap();
misc_service: Data<Arc<MiscellaneousService>>,
) -> Result<(), Error> {
let name = information.to_string();
tracing::trace!("Started job: {:#?}", name);
let start = Instant::now();
Expand Down Expand Up @@ -100,9 +102,9 @@ pub async fn perform_core_application_job(
pub enum ApplicationJob {
ImportFromExternalSource(i32, Box<DeployImportJobInput>),
ReEvaluateUserWorkouts(i32),
UpdateMetadata(i32),
UpdateMetadata(String),
UpdateGithubExerciseJob(Exercise),
UpdatePerson(i32),
UpdatePerson(String),
RecalculateCalendarEvents,
AssociateGroupWithMetadata(MediaLot, MediaSource, String),
ReviewPosted(ReviewPostedEvent),
Expand All @@ -111,18 +113,17 @@ pub enum ApplicationJob {
PerformBackgroundTasks,
}

impl Job for ApplicationJob {
impl Message for ApplicationJob {
const NAME: &'static str = "apalis::ApplicationJob";
}

pub async fn perform_application_job(
information: ApplicationJob,
ctx: JobContext,
) -> Result<(), JobError> {
let importer_service = ctx.data::<Arc<ImporterService>>().unwrap();
let exporter_service = ctx.data::<Arc<ExporterService>>().unwrap();
let misc_service = ctx.data::<Arc<MiscellaneousService>>().unwrap();
let exercise_service = ctx.data::<Arc<ExerciseService>>().unwrap();
misc_service: Data<Arc<MiscellaneousService>>,
importer_service: Data<Arc<ImporterService>>,
exporter_service: Data<Arc<ExporterService>>,
exercise_service: Data<Arc<ExerciseService>>,
) -> Result<(), Error> {
let name = information.to_string();
tracing::trace!("Started job: {:#?}", name);
let start = Instant::now();
Expand All @@ -140,7 +141,7 @@ pub async fn perform_application_job(
.await
.is_ok(),
ApplicationJob::UpdateMetadata(metadata_id) => misc_service
.update_metadata_and_notify_users(metadata_id)
.update_metadata_and_notify_users(&metadata_id)
.await
.is_ok(),
ApplicationJob::UpdatePerson(person_id) => misc_service
Expand Down
23 changes: 18 additions & 5 deletions apps/backend/src/entities/calendar_event.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2

use async_trait::async_trait;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use nanoid::nanoid;
use sea_orm::{entity::prelude::*, ActiveValue};
use serde::{Deserialize, Serialize};

use crate::models::media::{SeenPodcastExtraInformation, SeenShowExtraInformation};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "calendar_event")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub date: NaiveDate,
pub metadata_id: Option<i32>,
pub metadata_id: Option<String>,
pub metadata_show_extra_information: Option<SeenShowExtraInformation>,
pub metadata_podcast_extra_information: Option<SeenPodcastExtraInformation>,
}
Expand All @@ -35,4 +37,15 @@ impl Related<super::metadata::Entity> for Entity {
}
}

impl ActiveModelBehavior for ActiveModel {}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(mut self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
if insert {
self.id = ActiveValue::Set(format!("cal_{}", nanoid!(12)));
}
Ok(self)
}
}
20 changes: 17 additions & 3 deletions apps/backend/src/entities/collection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3

use async_graphql::SimpleObject;
use async_trait::async_trait;
use nanoid::nanoid;
use sea_orm::entity::prelude::*;
use sea_orm::ActiveValue;
use serde::{Deserialize, Serialize};

use crate::miscellaneous::CollectionExtraInformation;
Expand All @@ -10,8 +13,8 @@ use crate::miscellaneous::CollectionExtraInformation;
#[sea_orm(table_name = "collection")]
#[graphql(name = "Collection")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub created_on: DateTimeUtc,
pub last_updated_on: DateTimeUtc,
pub name: String,
Expand Down Expand Up @@ -63,4 +66,15 @@ impl Related<super::user_to_collection::Entity> for Entity {
}
}

impl ActiveModelBehavior for ActiveModel {}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(mut self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
if insert {
self.id = ActiveValue::Set(format!("col_{}", nanoid!(12)));
}
Ok(self)
}
}
8 changes: 4 additions & 4 deletions apps/backend/src/entities/collection_to_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub last_updated_on: DateTimeUtc,
pub collection_id: i32,
pub metadata_id: Option<i32>,
pub person_id: Option<i32>,
pub metadata_group_id: Option<i32>,
pub collection_id: String,
pub metadata_id: Option<String>,
pub person_id: Option<String>,
pub metadata_group_id: Option<String>,
pub exercise_id: Option<String>,
pub information: Option<serde_json::Value>,
}
Expand Down
21 changes: 17 additions & 4 deletions apps/backend/src/entities/genre.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2

use sea_orm::entity::prelude::*;
use async_trait::async_trait;
use nanoid::nanoid;
use sea_orm::{entity::prelude::*, ActiveValue};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "genre")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
#[sea_orm(unique)]
pub name: String,
}
Expand All @@ -33,4 +35,15 @@ impl Related<super::metadata_to_genre::Entity> for Entity {
}
}

impl ActiveModelBehavior for ActiveModel {}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(mut self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
if insert {
self.id = ActiveValue::Set(format!("gen_{}", nanoid!(12)));
}
Ok(self)
}
}
21 changes: 17 additions & 4 deletions apps/backend/src/entities/import_report.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3

use async_graphql::SimpleObject;
use async_trait::async_trait;
use database::ImportSource;
use sea_orm::entity::prelude::*;
use nanoid::nanoid;
use sea_orm::{entity::prelude::*, ActiveValue};
use serde::{Deserialize, Serialize};

use crate::importer::ImportResultResponse;
Expand All @@ -11,8 +13,8 @@ use crate::importer::ImportResultResponse;
#[sea_orm(table_name = "import_report")]
#[graphql(name = "ImportReport")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub user_id: i32,
pub source: ImportSource,
pub started_on: DateTimeUtc,
Expand All @@ -39,4 +41,15 @@ impl Related<super::user::Entity> for Entity {
}
}

impl ActiveModelBehavior for ActiveModel {}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(mut self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
if insert {
self.id = ActiveValue::Set(format!("imp_{}", nanoid!(12)));
}
Ok(self)
}
}
21 changes: 17 additions & 4 deletions apps/backend/src/entities/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2

use async_trait::async_trait;
use chrono::NaiveDate;
use database::{MediaLot, MediaSource};
use nanoid::nanoid;
use rust_decimal::Decimal;
use sea_orm::entity::prelude::*;
use sea_orm::{entity::prelude::*, ActiveValue};
use serde::{Deserialize, Serialize};

use crate::models::media::{
Expand All @@ -15,8 +17,8 @@ use crate::models::media::{
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, Default)]
#[sea_orm(table_name = "metadata")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub created_on: DateTimeUtc,
pub lot: MediaLot,
pub last_updated_on: DateTimeUtc,
Expand Down Expand Up @@ -141,4 +143,15 @@ impl Related<super::metadata_group::Entity> for Entity {
}
}

impl ActiveModelBehavior for ActiveModel {}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(mut self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
if insert {
self.id = ActiveValue::Set(format!("met_{}", nanoid!(12)));
}
Ok(self)
}
}
Loading