diff --git a/migrations/202206181000_site/down.sql b/migrations/202206181000_site/down.sql new file mode 100644 index 0000000..6da63be --- /dev/null +++ b/migrations/202206181000_site/down.sql @@ -0,0 +1,4 @@ +DROP UNIQUE INDEX uidx_sites_url; +DROP TRIGGER tg_sites_updated_at; +DROP TABLE sites; + diff --git a/migrations/202206201210_member_site/up.sql b/migrations/202206181000_site/up.sql similarity index 75% rename from migrations/202206201210_member_site/up.sql rename to migrations/202206181000_site/up.sql index c37f565..9b2e64b 100644 --- a/migrations/202206201210_member_site/up.sql +++ b/migrations/202206181000_site/up.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS member_sites ( +CREATE TABLE IF NOT EXISTS sites ( id UUID DEFAULT uuid_generate_v4(), url TEXT NOT NULL, show BOOLEAN NOT NULL DEFAULT TRUE, @@ -10,11 +10,11 @@ CREATE TABLE IF NOT EXISTS member_sites ( UNIQUE (url) ); -CREATE UNIQUE INDEX uidx_member_sites_url ON member_sites (url); +CREATE UNIQUE INDEX uidx_sites_url ON sites (url); -- trigger (updated_at) -CREATE TRIGGER tg_member_sites_updated_at +CREATE TRIGGER tg_sites_updated_at BEFORE UPDATE - ON member_sites + ON sites FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); diff --git a/migrations/202206201210_member_site/down.sql b/migrations/202206201210_member_site/down.sql deleted file mode 100644 index da5eec4..0000000 --- a/migrations/202206201210_member_site/down.sql +++ /dev/null @@ -1,4 +0,0 @@ -DROP UNIQUE INDEX uidx_member_sites_url; -DROP TRIGGER tg_member_sites_updated_at; -DROP TABLE member_sites; - diff --git a/migrations/202206201240_member/up.sql b/migrations/202206201240_member/up.sql index f52b9b7..c1dddf0 100644 --- a/migrations/202206201240_member/up.sql +++ b/migrations/202206201240_member/up.sql @@ -3,7 +3,7 @@ CREATE TYPE member_state AS ENUM ('normal', 'pending', 'withdrawal', 'dormancy', CREATE TABLE IF NOT EXISTS members ( id UUID DEFAULT uuid_generate_v4(), - member_site_id UUID NOT NULL, + site_id UUID NOT NULL, member_class_id UUID NOT NULL, member_level_id UUID NOT NULL, username TEXT NOT NULL, @@ -21,9 +21,9 @@ CREATE TABLE IF NOT EXISTS members ( deleted_at BIGINT, PRIMARY KEY (id), UNIQUE (username), - CONSTRAINT fk_members_member_site_id - FOREIGN KEY(member_site_id) - REFERENCES member_sites(id), + CONSTRAINT fk_members_site_id + FOREIGN KEY(site_id) + REFERENCES sites(id), CONSTRAINT fk_members_member_class_id FOREIGN KEY(member_class_id) REFERENCES member_classes(id), diff --git a/migrations/202208011200_initial_data/up.sql b/migrations/202208011200_initial_data/up.sql index 7d7e0fc..18a5182 100644 --- a/migrations/202208011200_initial_data/up.sql +++ b/migrations/202208011200_initial_data/up.sql @@ -70,9 +70,9 @@ INSERT INTO role_resource_actions (role_id, resource_action_id) VALUES ('b6a2b66 -- identity.signout INSERT INTO role_resource_actions (role_id, resource_action_id) VALUES ('b6a2b662-e21e-44e7-a96c-dacd86f9d6b8', '37b99823-188b-4b30-afb7-815a7e79662b'); +INSERT INTO sites (id, url, show) VALUES ('d7cbae26-53b6-4cb1-85a4-66b956cbe1d4', '*', false); +INSERT INTO sites (id, url, show) VALUES ('8429a7ab-b9de-400b-a209-28ff46e22bec', '127.0.0.1', true); -INSERT INTO member_sites (id, url, show) VALUES ('d7cbae26-53b6-4cb1-85a4-66b956cbe1d4', '*', false); -INSERT INTO member_sites (id, url, show) VALUES ('8429a7ab-b9de-400b-a209-28ff46e22bec', '127.0.0.1', true); INSERT INTO member_levels (id, name, sort_order, show) VALUES ('c238463f-949d-49eb-92ab-dca7a09371db', 'LEVEL0', 0, false); INSERT INTO member_levels (id, name, sort_order, show) VALUES ('c56231ac-2120-4a81-a30a-5d41fafb6c57', 'LEVEL1', 1, true); @@ -92,7 +92,7 @@ INSERT INTO member_classes (id, name, parent_id, show) VALUES ('4598f07a-86d1-42 INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -104,7 +104,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -116,7 +116,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -128,7 +128,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -140,7 +140,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -152,7 +152,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -164,7 +164,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -176,7 +176,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -188,7 +188,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -205,7 +205,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -217,7 +217,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -229,7 +229,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -241,7 +241,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -257,7 +257,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -269,7 +269,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -281,7 +281,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -293,7 +293,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -310,7 +310,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -322,7 +322,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -334,7 +334,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -346,7 +346,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -363,7 +363,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -375,7 +375,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -387,7 +387,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( @@ -399,7 +399,7 @@ INSERT INTO members( INSERT INTO members( id, - member_site_id, member_class_id, member_level_id, + site_id, member_class_id, member_level_id, username, password, nickname, mobile_phone_number, state ) VALUES ( diff --git a/src/repositories/member/models.rs b/src/repositories/member/models.rs index cd64120..027ad2d 100644 --- a/src/repositories/member/models.rs +++ b/src/repositories/member/models.rs @@ -8,7 +8,7 @@ pub struct Member { /// pub id: uuid::Uuid, /// - pub member_site_id: uuid::Uuid, + pub site_id: uuid::Uuid, /// pub member_class_id: uuid::Uuid, /// @@ -46,7 +46,7 @@ pub struct Member { #[table_name = "members"] pub struct NewMember { /// - pub member_site_id: uuid::Uuid, + pub site_id: uuid::Uuid, /// pub member_class_id: uuid::Uuid, /// @@ -68,7 +68,7 @@ pub struct NewMember { #[table_name = "members"] pub struct ModifyMember { /// - pub member_site_id: Option, + pub site_id: Option, /// pub member_level_id: Option, /// @@ -99,7 +99,7 @@ pub struct ModifyMember4DeletedAt { #[derive(Debug, Clone)] pub struct FindAll { /// - pub member_site_id: Option, + pub site_id: Option, /// pub member_class_id: Option, /// diff --git a/src/repositories/member/repository.rs b/src/repositories/member/repository.rs index 1ce056a..c4bc9c3 100644 --- a/src/repositories/member/repository.rs +++ b/src/repositories/member/repository.rs @@ -105,8 +105,8 @@ impl Repository { let mut q = members::table.into_boxed(); - if let Some(sp) = find_all.member_site_id { - q = q.filter(dsl::member_site_id.eq(sp)); + if let Some(sp) = find_all.site_id { + q = q.filter(dsl::site_id.eq(sp)); } if let Some(sp) = find_all.member_class_id { q = q.filter(dsl::member_class_id.eq(sp)); @@ -148,8 +148,8 @@ impl Repository { let mut q = members::table.into_boxed(); - if let Some(sp) = find_all.member_site_id { - q = q.filter(dsl::member_site_id.eq(sp)); + if let Some(sp) = find_all.site_id { + q = q.filter(dsl::site_id.eq(sp)); } if let Some(sp) = find_all.member_class_id { q = q.filter(dsl::member_class_id.eq(sp)); diff --git a/src/repositories/member/schema.rs b/src/repositories/member/schema.rs index f46c388..935cc22 100644 --- a/src/repositories/member/schema.rs +++ b/src/repositories/member/schema.rs @@ -21,7 +21,7 @@ table! { /// id -> Uuid, /// - member_site_id -> Uuid, + site_id -> Uuid, /// member_class_id -> Uuid, /// diff --git a/src/repositories/mod.rs b/src/repositories/mod.rs index f9f9829..849ee36 100644 --- a/src/repositories/mod.rs +++ b/src/repositories/mod.rs @@ -4,8 +4,8 @@ pub mod member_level; pub mod member_permission; pub mod member_role; pub mod member_session; -pub mod member_site; pub mod resource; pub mod resource_action; pub mod role; pub mod role_resource_action; +pub mod site; diff --git a/src/repositories/member_site/mod.rs b/src/repositories/site/mod.rs similarity index 100% rename from src/repositories/member_site/mod.rs rename to src/repositories/site/mod.rs diff --git a/src/repositories/member_site/models.rs b/src/repositories/site/models.rs similarity index 84% rename from src/repositories/member_site/models.rs rename to src/repositories/site/models.rs index eab252f..d5061df 100644 --- a/src/repositories/member_site/models.rs +++ b/src/repositories/site/models.rs @@ -1,10 +1,10 @@ -use super::schema::member_sites; +use super::schema::sites; use beteran_common_rust as bcr; /// #[derive(Eq, Hash, Identifiable, Queryable, PartialEq, Debug, Clone)] -#[table_name = "member_sites"] -pub struct MemberSite { +#[table_name = "sites"] +pub struct Site { /// pub id: uuid::Uuid, /// diff --git a/src/repositories/member_site/repository.rs b/src/repositories/site/repository.rs similarity index 62% rename from src/repositories/member_site/repository.rs rename to src/repositories/site/repository.rs index 2e43a09..7d4c966 100644 --- a/src/repositories/member_site/repository.rs +++ b/src/repositories/site/repository.rs @@ -1,6 +1,6 @@ //! //! -use super::{models, schema::member_sites}; +use super::{models, schema::sites}; use beteran_common_rust as bcr; use diesel::prelude::*; use diesel::result::Error; @@ -10,7 +10,7 @@ pub struct Repository {} impl std::fmt::Debug for Repository { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_struct("Repository of member_sites").finish() + f.debug_struct("Repository of sites").finish() } } @@ -27,14 +27,10 @@ impl Repository { } /// - pub fn select( - &self, - conn: &diesel::PgConnection, - id: uuid::Uuid, - ) -> Result { - member_sites::table + pub fn select(&self, conn: &diesel::PgConnection, id: uuid::Uuid) -> Result { + sites::table .find(id as uuid::Uuid) - .first::(conn) + .first::(conn) } /// @@ -42,12 +38,12 @@ impl Repository { &self, conn: &diesel::PgConnection, url: &str, - ) -> Result, Error> { - use member_sites::dsl; + ) -> Result, Error> { + use sites::dsl; - match member_sites::table + match sites::table .filter(dsl::url.eq(url)) - .first::(conn) + .first::(conn) { Ok(m) => Ok(Some(m)), Err(e) => match e { @@ -63,10 +59,10 @@ impl Repository { conn: &diesel::PgConnection, find_all: models::FindAll, ) -> Result { - let mut q = member_sites::table.into_boxed(); + let mut q = sites::table.into_boxed(); if let Some(sp) = find_all.url_like { - q = q.filter(member_sites::dsl::url.like(sp)); + q = q.filter(sites::dsl::url.like(sp)); } q.count().get_result(conn) @@ -77,11 +73,11 @@ impl Repository { &self, conn: &diesel::PgConnection, find_all: models::FindAll, - ) -> Result, Error> { - let mut q = member_sites::table.into_boxed(); + ) -> Result, Error> { + let mut q = sites::table.into_boxed(); if let Some(sp) = find_all.url_like { - q = q.filter(member_sites::dsl::url.like(sp)); + q = q.filter(sites::dsl::url.like(sp)); } if let Some(p) = find_all.pagination { @@ -97,31 +93,31 @@ impl Repository { match s { bcr::models::pagination::Sort::ASC(property) => match property.as_str() { "url" => { - q = q.order_by(member_sites::url.asc()); + q = q.order_by(sites::url.asc()); } "created_at" => { - q = q.order_by(member_sites::created_at.asc()); + q = q.order_by(sites::created_at.asc()); } "updated_at" => { - q = q.order_by(member_sites::updated_at.asc()); + q = q.order_by(sites::updated_at.asc()); } "deleted_at" => { - q = q.order_by(member_sites::deleted_at.asc()); + q = q.order_by(sites::deleted_at.asc()); } _ => {} }, bcr::models::pagination::Sort::DESC(property) => match property.as_str() { "url" => { - q = q.order_by(member_sites::url.desc()); + q = q.order_by(sites::url.desc()); } "created_at" => { - q = q.order_by(member_sites::created_at.desc()); + q = q.order_by(sites::created_at.desc()); } "updated_at" => { - q = q.order_by(member_sites::updated_at.desc()); + q = q.order_by(sites::updated_at.desc()); } "deleted_at" => { - q = q.order_by(member_sites::deleted_at.desc()); + q = q.order_by(sites::deleted_at.desc()); } _ => {} }, @@ -129,6 +125,6 @@ impl Repository { } } - q.load::(conn) + q.load::(conn) } } diff --git a/src/repositories/member_site/schema.rs b/src/repositories/site/schema.rs similarity index 90% rename from src/repositories/member_site/schema.rs rename to src/repositories/site/schema.rs index f8f52e4..fc9835f 100644 --- a/src/repositories/member_site/schema.rs +++ b/src/repositories/site/schema.rs @@ -3,7 +3,7 @@ table! { /// - member_sites(id) { + sites(id) { /// id -> Uuid, /// diff --git a/src/services/identity/service.rs b/src/services/identity/service.rs index d984a9c..3b849f9 100644 --- a/src/services/identity/service.rs +++ b/src/services/identity/service.rs @@ -16,7 +16,7 @@ pub struct Service<'a> { queue_broker: String, pool: Pool>, member_repository: repositories::member::repository::Repository, - member_site_repository: repositories::member_site::repository::Repository, + member_site_repository: repositories::site::repository::Repository, member_session_repository: repositories::member_session::repository::Repository, argon2_config: argon2::Config<'a>, captcha_salt: String, @@ -44,7 +44,7 @@ impl Service<'_> { queue_broker, pool, member_repository: repositories::member::repository::Repository::new(), - member_site_repository: repositories::member_site::repository::Repository::new(), + member_site_repository: repositories::site::repository::Repository::new(), member_session_repository: repositories::member_session::repository::Repository::new(), argon2_config: argon2::Config::default(), captcha_salt, @@ -544,7 +544,7 @@ impl Service<'_> { } }; - if m.member_site_id != ms.id { + if m.site_id != ms.id { return Err(bcr::error::rpc::Error::InvalidParams( bcr::error::rpc::InvalidParams { message: "invalid site_url".to_string(),