From 13f5ad367216547d2789ca0322e66d98bbf68c61 Mon Sep 17 00:00:00 2001 From: Natty Date: Fri, 12 Jan 2024 23:13:00 +0100 Subject: [PATCH] Removed the page tables --- .../entity_ck/src/entities/drive_file.rs | 8 -- .../entity_ck/src/entities/mod.rs | 2 - .../entity_ck/src/entities/prelude.rs | 2 - .../src/entities/sea_orm_active_enums.rs | 14 --- .../entity_ck/src/entities/user.rs | 16 --- .../entity_ck/src/entities/user_profile.rs | 16 --- ext_calckey_model/migration/src/lib.rs | 2 + .../src/m20240112_215106_remove_pages.rs | 118 ++++++++++++++++++ 8 files changed, 120 insertions(+), 58 deletions(-) create mode 100644 ext_calckey_model/migration/src/m20240112_215106_remove_pages.rs diff --git a/ext_calckey_model/entity_ck/src/entities/drive_file.rs b/ext_calckey_model/entity_ck/src/entities/drive_file.rs index 2f2e2d6..cda05c6 100644 --- a/ext_calckey_model/entity_ck/src/entities/drive_file.rs +++ b/ext_calckey_model/entity_ck/src/entities/drive_file.rs @@ -65,8 +65,6 @@ pub enum Relation { on_delete = "SetNull" )] DriveFolder, - #[sea_orm(has_many = "super::page::Entity")] - Page, #[sea_orm( belongs_to = "super::user::Entity", from = "Column::UserId", @@ -83,12 +81,6 @@ impl Related for Entity { } } -impl Related for Entity { - fn to() -> RelationDef { - Relation::Page.def() - } -} - impl Related for Entity { fn to() -> RelationDef { Relation::User.def() diff --git a/ext_calckey_model/entity_ck/src/entities/mod.rs b/ext_calckey_model/entity_ck/src/entities/mod.rs index a040ce1..def22eb 100644 --- a/ext_calckey_model/entity_ck/src/entities/mod.rs +++ b/ext_calckey_model/entity_ck/src/entities/mod.rs @@ -36,8 +36,6 @@ pub mod note_thread_muting; pub mod note_unread; pub mod note_watching; pub mod notification; -pub mod page; -pub mod page_like; pub mod password_reset_request; pub mod poll; pub mod poll_vote; diff --git a/ext_calckey_model/entity_ck/src/entities/prelude.rs b/ext_calckey_model/entity_ck/src/entities/prelude.rs index 33ad8c5..d079afd 100644 --- a/ext_calckey_model/entity_ck/src/entities/prelude.rs +++ b/ext_calckey_model/entity_ck/src/entities/prelude.rs @@ -34,8 +34,6 @@ pub use super::note_thread_muting::Entity as NoteThreadMuting; pub use super::note_unread::Entity as NoteUnread; pub use super::note_watching::Entity as NoteWatching; pub use super::notification::Entity as Notification; -pub use super::page::Entity as Page; -pub use super::page_like::Entity as PageLike; pub use super::password_reset_request::Entity as PasswordResetRequest; pub use super::poll::Entity as Poll; pub use super::poll_vote::Entity as PollVote; diff --git a/ext_calckey_model/entity_ck/src/entities/sea_orm_active_enums.rs b/ext_calckey_model/entity_ck/src/entities/sea_orm_active_enums.rs index 531a145..a40f2eb 100644 --- a/ext_calckey_model/entity_ck/src/entities/sea_orm_active_enums.rs +++ b/ext_calckey_model/entity_ck/src/entities/sea_orm_active_enums.rs @@ -118,20 +118,6 @@ pub enum NotificationTypeEnum { Reply, } #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy, Serialize, Deserialize)] -#[sea_orm( - rs_type = "String", - db_type = "Enum", - enum_name = "page_visibility_enum" -)] -pub enum PageVisibilityEnum { - #[sea_orm(string_value = "followers")] - Followers, - #[sea_orm(string_value = "public")] - Public, - #[sea_orm(string_value = "specified")] - Specified, -} -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy, Serialize, Deserialize)] #[sea_orm( rs_type = "String", db_type = "Enum", diff --git a/ext_calckey_model/entity_ck/src/entities/user.rs b/ext_calckey_model/entity_ck/src/entities/user.rs index d64e2a4..3740176 100644 --- a/ext_calckey_model/entity_ck/src/entities/user.rs +++ b/ext_calckey_model/entity_ck/src/entities/user.rs @@ -128,10 +128,6 @@ pub enum Relation { NoteUnread, #[sea_orm(has_many = "super::note_watching::Entity")] NoteWatching, - #[sea_orm(has_many = "super::page::Entity")] - Page, - #[sea_orm(has_many = "super::page_like::Entity")] - PageLike, #[sea_orm(has_many = "super::password_reset_request::Entity")] PasswordResetRequest, #[sea_orm(has_many = "super::poll_vote::Entity")] @@ -276,18 +272,6 @@ impl Related for Entity { } } -impl Related for Entity { - fn to() -> RelationDef { - Relation::Page.def() - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::PageLike.def() - } -} - impl Related for Entity { fn to() -> RelationDef { Relation::PasswordResetRequest.def() diff --git a/ext_calckey_model/entity_ck/src/entities/user_profile.rs b/ext_calckey_model/entity_ck/src/entities/user_profile.rs index 230de24..5e3b082 100644 --- a/ext_calckey_model/entity_ck/src/entities/user_profile.rs +++ b/ext_calckey_model/entity_ck/src/entities/user_profile.rs @@ -42,8 +42,6 @@ pub struct Model { pub security_keys_available: bool, #[sea_orm(column_name = "usePasswordLessLogin")] pub use_password_less_login: bool, - #[sea_orm(column_name = "pinnedPageId", unique)] - pub pinned_page_id: Option, #[sea_orm(column_type = "JsonBinary")] pub room: Json, #[sea_orm(column_type = "JsonBinary")] @@ -77,14 +75,6 @@ pub struct Model { #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm( - belongs_to = "super::page::Entity", - from = "Column::PinnedPageId", - to = "super::page::Column::Id", - on_update = "NoAction", - on_delete = "SetNull" - )] - Page, #[sea_orm( belongs_to = "super::user::Entity", from = "Column::UserId", @@ -95,12 +85,6 @@ pub enum Relation { User, } -impl Related for Entity { - fn to() -> RelationDef { - Relation::Page.def() - } -} - impl Related for Entity { fn to() -> RelationDef { Relation::User.def() diff --git a/ext_calckey_model/migration/src/lib.rs b/ext_calckey_model/migration/src/lib.rs index 2207cbc..1094027 100644 --- a/ext_calckey_model/migration/src/lib.rs +++ b/ext_calckey_model/migration/src/lib.rs @@ -7,6 +7,7 @@ mod m20230806_142918_drop_featured_note_option; mod m20240107_005747_remove_user_groups; mod m20240107_220523_generated_is_quote; mod m20240107_224446_generated_is_renote; +mod m20240112_215106_remove_pages; pub struct Migrator; @@ -21,6 +22,7 @@ impl MigratorTrait for Migrator { Box::new(m20240107_005747_remove_user_groups::Migration), Box::new(m20240107_220523_generated_is_quote::Migration), Box::new(m20240107_224446_generated_is_renote::Migration), + Box::new(m20240112_215106_remove_pages::Migration), ] } } diff --git a/ext_calckey_model/migration/src/m20240112_215106_remove_pages.rs b/ext_calckey_model/migration/src/m20240112_215106_remove_pages.rs new file mode 100644 index 0000000..ee015de --- /dev/null +++ b/ext_calckey_model/migration/src/m20240112_215106_remove_pages.rs @@ -0,0 +1,118 @@ +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> { + let db = manager.get_connection(); + + db.execute_unprepared( + r#" + ALTER TABLE "user_profile" DROP COLUMN "pinnedPageId"; + + DROP TABLE "page_like"; + DROP TABLE "page"; + "#, + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let db = manager.get_connection(); + + db.execute_unprepared( + r#" + create table page + ( + id varchar(32) not null + constraint "PK_742f4117e065c5b6ad21b37ba1f" + primary key, + "createdAt" timestamp with time zone not null, + "updatedAt" timestamp with time zone not null, + title varchar(256) not null, + name varchar(256) not null, + summary varchar(256), + "alignCenter" boolean not null, + font varchar(32) not null, + "userId" varchar(32) not null + constraint "FK_ae1d917992dd0c9d9bbdad06c4a" + references "user" + on delete cascade, + "eyeCatchingImageId" varchar(32) + constraint "FK_a9ca79ad939bf06066b81c9d3aa" + references drive_file + on delete cascade, + content jsonb default '[]'::jsonb not null, + variables jsonb default '[]'::jsonb not null, + visibility page_visibility_enum not null, + "visibleUserIds" varchar(32)[] default '{}'::character varying[] not null, + "likedCount" integer default 0 not null, + "hideTitleWhenPinned" boolean default false not null, + script varchar(16384) default ''::character varying not null, + "isPublic" boolean default true not null + ); + + comment on column page."createdAt" is 'The created date of the Page.'; + + comment on column page."updatedAt" is 'The updated date of the Page.'; + + comment on column page."userId" is 'The ID of author.'; + + create index "IDX_fbb4297c927a9b85e9cefa2eb1" + on page ("createdAt"); + + create index "IDX_af639b066dfbca78b01a920f8a" + on page ("updatedAt"); + + create index "IDX_b82c19c08afb292de4600d99e4" + on page (name); + + create index "IDX_ae1d917992dd0c9d9bbdad06c4" + on page ("userId"); + + create index "IDX_90148bbc2bf0854428786bfc15" + on page ("visibleUserIds"); + + create unique index "IDX_2133ef8317e4bdb839c0dcbf13" + on page ("userId", name); + + create table page_like + ( + id varchar(32) not null + constraint "PK_813f034843af992d3ae0f43c64c" + primary key, + "createdAt" timestamp with time zone not null, + "userId" varchar(32) not null + constraint "FK_0e61efab7f88dbb79c9166dbb48" + references "user" + on delete cascade, + "pageId" varchar(32) not null + constraint "FK_cf8782626dced3176038176a847" + references page + on delete cascade + ); + + create index "IDX_0e61efab7f88dbb79c9166dbb4" + on page_like ("userId"); + + create unique index "IDX_4ce6fb9c70529b4c8ac46c9bfa" + on page_like ("userId", "pageId"); + + alter table user_profile + add "pinnedPageId" varchar(32) + constraint "UQ_6dc44f1ceb65b1e72bacef2ca27" + unique + constraint "FK_6dc44f1ceb65b1e72bacef2ca27" + references page + on delete set null; + "#, + ) + .await?; + + Ok(()) + } +}