Skip to content

Commit

Permalink
Update models and fix build.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Sep 30, 2023
1 parent 1bd77b9 commit da5f9ba
Show file tree
Hide file tree
Showing 28 changed files with 217 additions and 265 deletions.
2 changes: 1 addition & 1 deletion deepwell/migrations/20220906103252_deepwell.sql
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ CREATE TABLE alias (
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
created_by BIGINT NOT NULL REFERENCES "user"(user_id),
target_id BIGINT NOT NULL,
slug TEXT,
slug TEXT NOT NULL,

UNIQUE (alias_type, slug)
);
Expand Down
7 changes: 4 additions & 3 deletions deepwell/scripts/generate-models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ cd "${0%/*}/.."
# Generate models
sea-orm-cli generate entity \
--verbose \
--database-url postgres://wikijump:wikijump@localhost/wikijump \
--output-dir src/models \
--date-time-crate time \
--with-serde both
--with-copy-enums \
--with-serde both \
--database-url postgres://wikijump:wikijump@localhost/wikijump \
--output-dir src/models
13 changes: 9 additions & 4 deletions deepwell/src/models/alias.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use super::sea_orm_active_enums::AliasType;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "alias")]
pub struct Model {
#[sea_orm(primary_key)]
pub alias_id: i64,
pub alias_type: AliasType,
pub created_at: OffsetDateTime,
pub created_at: TimeDateTimeWithTimeZone,
pub created_by: i64,
pub target_id: i64,
#[sea_orm(column_type = "Text")]
pub slug: String,
}

Expand All @@ -30,4 +29,10 @@ pub enum Relation {
User,
}

impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
22 changes: 10 additions & 12 deletions deepwell/src/models/file.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "file")]
pub struct Model {
#[sea_orm(primary_key)]
pub file_id: i64,
pub created_at: OffsetDateTime,
pub updated_at: Option<OffsetDateTime>,
pub deleted_at: Option<OffsetDateTime>,
pub created_at: TimeDateTimeWithTimeZone,
pub updated_at: Option<TimeDateTimeWithTimeZone>,
pub deleted_at: Option<TimeDateTimeWithTimeZone>,
pub from_wikidot: bool,
#[sea_orm(column_type = "Text")]
pub name: String,
Expand All @@ -21,6 +19,8 @@ pub struct Model {

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::file_revision::Entity")]
FileRevision,
#[sea_orm(
belongs_to = "super::page::Entity",
from = "Column::PageId",
Expand All @@ -29,19 +29,17 @@ pub enum Relation {
on_delete = "NoAction"
)]
Page,
#[sea_orm(has_many = "super::file_revision::Entity")]
FileRevision,
}

impl Related<super::page::Entity> for Entity {
impl Related<super::file_revision::Entity> for Entity {
fn to() -> RelationDef {
Relation::Page.def()
Relation::FileRevision.def()
}
}

impl Related<super::file_revision::Entity> for Entity {
impl Related<super::page::Entity> for Entity {
fn to() -> RelationDef {
Relation::FileRevision.def()
Relation::Page.def()
}
}

Expand Down
7 changes: 3 additions & 4 deletions deepwell/src/models/file_revision.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use super::sea_orm_active_enums::FileRevisionType;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "file_revision")]
pub struct Model {
#[sea_orm(primary_key)]
pub revision_id: i64,
pub revision_type: FileRevisionType,
pub created_at: OffsetDateTime,
pub created_at: TimeDateTimeWithTimeZone,
pub revision_number: i32,
pub file_id: i64,
pub page_id: i64,
pub user_id: i64,
#[sea_orm(column_type = "Text")]
pub name: String,
#[sea_orm(column_type = "Binary(BlobSize::Blob(None))")]
pub s3_hash: Vec<u8>,
#[sea_orm(column_type = "Text")]
pub mime_hint: String,
Expand Down
10 changes: 4 additions & 6 deletions deepwell/src/models/filter.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "filter")]
pub struct Model {
#[sea_orm(primary_key)]
pub filter_id: i64,
pub created_at: OffsetDateTime,
pub updated_at: Option<OffsetDateTime>,
pub deleted_at: Option<OffsetDateTime>,
pub created_at: TimeDateTimeWithTimeZone,
pub updated_at: Option<TimeDateTimeWithTimeZone>,
pub deleted_at: Option<TimeDateTimeWithTimeZone>,
pub site_id: Option<i64>,
pub affects_user: bool,
pub affects_email: bool,
Expand Down
3 changes: 1 addition & 2 deletions deepwell/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
pub mod prelude;

Expand All @@ -19,7 +19,6 @@ pub mod page_vote;
pub mod sea_orm_active_enums;
pub mod session;
pub mod site;
pub mod site_alias;
pub mod site_domain;
pub mod site_member;
pub mod text;
Expand Down
70 changes: 34 additions & 36 deletions deepwell/src/models/page.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "page")]
pub struct Model {
#[sea_orm(primary_key)]
pub page_id: i64,
pub created_at: OffsetDateTime,
pub updated_at: Option<OffsetDateTime>,
pub deleted_at: Option<OffsetDateTime>,
pub created_at: TimeDateTimeWithTimeZone,
pub updated_at: Option<TimeDateTimeWithTimeZone>,
pub deleted_at: Option<TimeDateTimeWithTimeZone>,
pub from_wikidot: bool,
pub site_id: i64,
pub latest_revision_id: Option<i64>,
Expand All @@ -24,6 +22,12 @@ pub struct Model {

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::file::Entity")]
File,
#[sea_orm(has_many = "super::file_revision::Entity")]
FileRevision,
#[sea_orm(has_many = "super::page_attribution::Entity")]
PageAttribution,
#[sea_orm(
belongs_to = "super::page_category::Entity",
from = "Column::PageCategoryId",
Expand All @@ -32,6 +36,10 @@ pub enum Relation {
on_delete = "NoAction"
)]
PageCategory,
#[sea_orm(has_many = "super::page_link::Entity")]
PageLink,
#[sea_orm(has_many = "super::page_lock::Entity")]
PageLock,
#[sea_orm(
belongs_to = "super::page_revision::Entity",
from = "Column::LatestRevisionId",
Expand All @@ -40,6 +48,8 @@ pub enum Relation {
on_delete = "NoAction"
)]
PageRevision,
#[sea_orm(has_many = "super::page_vote::Entity")]
PageVote,
#[sea_orm(
belongs_to = "super::site::Entity",
from = "Column::SiteId",
Expand All @@ -48,35 +58,17 @@ pub enum Relation {
on_delete = "NoAction"
)]
Site,
#[sea_orm(has_many = "super::page_attribution::Entity")]
PageAttribution,
#[sea_orm(has_many = "super::page_lock::Entity")]
PageLock,
#[sea_orm(has_many = "super::page_link::Entity")]
PageLink,
#[sea_orm(has_many = "super::page_vote::Entity")]
PageVote,
#[sea_orm(has_many = "super::file::Entity")]
File,
#[sea_orm(has_many = "super::file_revision::Entity")]
FileRevision,
}

impl Related<super::page_category::Entity> for Entity {
fn to() -> RelationDef {
Relation::PageCategory.def()
}
}

impl Related<super::site::Entity> for Entity {
impl Related<super::file::Entity> for Entity {
fn to() -> RelationDef {
Relation::Site.def()
Relation::File.def()
}
}

impl Related<super::page_revision::Entity> for Entity {
impl Related<super::file_revision::Entity> for Entity {
fn to() -> RelationDef {
Relation::PageRevision.def()
Relation::FileRevision.def()
}
}

Expand All @@ -86,9 +78,9 @@ impl Related<super::page_attribution::Entity> for Entity {
}
}

impl Related<super::page_lock::Entity> for Entity {
impl Related<super::page_category::Entity> for Entity {
fn to() -> RelationDef {
Relation::PageLock.def()
Relation::PageCategory.def()
}
}

Expand All @@ -98,21 +90,27 @@ impl Related<super::page_link::Entity> for Entity {
}
}

impl Related<super::page_vote::Entity> for Entity {
impl Related<super::page_lock::Entity> for Entity {
fn to() -> RelationDef {
Relation::PageVote.def()
Relation::PageLock.def()
}
}

impl Related<super::file::Entity> for Entity {
impl Related<super::page_revision::Entity> for Entity {
fn to() -> RelationDef {
Relation::File.def()
Relation::PageRevision.def()
}
}

impl Related<super::file_revision::Entity> for Entity {
impl Related<super::page_vote::Entity> for Entity {
fn to() -> RelationDef {
Relation::FileRevision.def()
Relation::PageVote.def()
}
}

impl Related<super::site::Entity> for Entity {
fn to() -> RelationDef {
Relation::Site.def()
}
}

Expand Down
8 changes: 3 additions & 5 deletions deepwell/src/models/page_attribution.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::{Date, OffsetDateTime};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "page_attribution")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
Expand All @@ -15,8 +13,8 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false, column_type = "Text")]
pub attribution_type: String,
#[sea_orm(primary_key, auto_increment = false)]
pub attribution_date: Date,
pub created_at: OffsetDateTime,
pub attribution_date: TimeDate,
pub created_at: TimeDateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
20 changes: 9 additions & 11 deletions deepwell/src/models/page_category.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "page_category")]
pub struct Model {
#[sea_orm(primary_key)]
pub category_id: i64,
pub created_at: OffsetDateTime,
pub updated_at: Option<OffsetDateTime>,
pub created_at: TimeDateTimeWithTimeZone,
pub updated_at: Option<TimeDateTimeWithTimeZone>,
pub site_id: i64,
#[sea_orm(column_type = "Text")]
pub slug: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::page::Entity")]
Page,
#[sea_orm(
belongs_to = "super::site::Entity",
from = "Column::SiteId",
Expand All @@ -27,19 +27,17 @@ pub enum Relation {
on_delete = "NoAction"
)]
Site,
#[sea_orm(has_many = "super::page::Entity")]
Page,
}

impl Related<super::site::Entity> for Entity {
impl Related<super::page::Entity> for Entity {
fn to() -> RelationDef {
Relation::Site.def()
Relation::Page.def()
}
}

impl Related<super::page::Entity> for Entity {
impl Related<super::site::Entity> for Entity {
fn to() -> RelationDef {
Relation::Page.def()
Relation::Site.def()
}
}

Expand Down
Loading

0 comments on commit da5f9ba

Please sign in to comment.