Postgresql - 用戶權限數據庫

1、綜述

????????在實際的軟件項目開發過程中,用戶權限控制可以說是所有運營系統中必不可少的一個重點功能,根據業務的復雜度,設計的時候可深可淺,但無論怎么變化,設計的思路基本都是圍繞著用戶、部門、角色、菜單這幾個部分展開。

1.1 數據庫實體

? ? ? ? 1、用戶:用戶名、密碼、頭像、個人簡介、性別、所屬部門以及個人權限

? ? ? ? 2、角色:角色名稱和描述,暫時無用處,只是定義。后期進行擴展

? ? ? ? 3、部門:部門名稱、父級部門以及描述

? ? ? ? 4、菜單:菜單名稱、標識、排序、父級菜單等信息

? ? ? ? 5、權限:個人菜單的權限,暫定不根據角色劃分

1.2 數據庫分析

? ? ? ? 數據庫設計規范,按照3級范式設計

? ? ? ? 1、用戶-部門:M:1,包括用戶表、部門表,用戶包含部門ID

? ? ? ? 2、用戶-角色:N:M,包括用戶表、角色表、用戶角色表,用戶角色表包括用戶ID,角色ID

? ? ? ? 3、用戶-權限:M:1,包括用戶表、權限表、用戶表中包括權限ID

? ? ? ? 4、權限-菜單:M:M,包括權限表、菜單表、權限菜單表,權限菜單表包括權限ID、菜單ID

2、數據庫表設計

2.1 表設計

? ? ? ? 用戶表、部門表、角色表、用戶角色表、權限表、菜單表、權限菜單表

????????

2.2 生成數據庫完整的SQL

/*==============================================================*/
/* DBMS name:      PostgreSQL 9.x                               */
/* Created on:     2024/7/7 17:49:29                            */
/*==============================================================*/drop index  if exists index_7;drop table if exists menu cascade;drop index  if exists index_1;drop table if exists organization cascade;drop index  if exists index_5;drop table if exists permission cascade;drop index  if exists index_6;drop table if exists permission_menu cascade;drop index  if exists index_4;drop table if exists role cascade;drop index  if exists index_2;drop table if exists user_info cascade;drop index  if exists index_3;drop table if exists user_role cascade;/*==============================================================*/
/* Table: menu                                                  */
/*==============================================================*/
create table menu (id                   varchar(128)         not null,name                 varchar(128)         null,parent_id            varchar(128)         null,menu_type            varchar(128)         null,permission           varchar(128)         null,sort                 int4                 null,status               int4                 null,create_user          varchar(128)         null,create_time          timestamp            null,extension            json                 null,constraint pk_menu primary key (id)
);comment on table menu is
'菜單表';comment on column menu.id is
'菜單編號';comment on column menu.name is
'菜單名稱';comment on column menu.parent_id is
'父級編號';comment on column menu.menu_type is
'菜單類別';comment on column menu.permission is
'權限標識';comment on column menu.sort is
'排序';comment on column menu.status is
'狀態';comment on column menu.create_user is
'創建人';comment on column menu.create_time is
'創建時間';comment on column menu.extension is
'擴展信息';/*==============================================================*/
/* Index: index_7                                               */
/*==============================================================*/
create  index index_7 on menu (
parent_id
);/*==============================================================*/
/* Table: organization                                          */
/*==============================================================*/
create table organization (id                   varchar(128)         not null,name                 varchar(128)         null,parent_id            varchar(128)         null,description          varchar(256)         null,create_user          varchar(128)         null,create_time          timestamp            null,extension            json                 null,constraint pk_organization primary key (id)
);comment on table organization is
'組織';comment on column organization.id is
'部門編號';comment on column organization.name is
'部門名稱';comment on column organization.parent_id is
'父級部門';comment on column organization.description is
'部門描述';comment on column organization.create_user is
'創建人';comment on column organization.create_time is
'創建時間';comment on column organization.extension is
'擴展信息';/*==============================================================*/
/* Index: index_1                                               */
/*==============================================================*/
create  index index_1 on organization (
parent_id
);/*==============================================================*/
/* Table: permission                                            */
/*==============================================================*/
create table permission (id                   varchar(128)         not null,name                 varchar(256)         null,description          varchar(256)         null,create_user          varchar(128)         null,create_time          timestamp            null,extension            json                 null,constraint pk_permission primary key (id)
);comment on table permission is
'權限表';comment on column permission.id is
'角色編號';comment on column permission.name is
'角色名稱';comment on column permission.description is
'角色描述';comment on column permission.create_user is
'創建人';comment on column permission.create_time is
'創建時間';comment on column permission.extension is
'擴展信息';/*==============================================================*/
/* Index: index_5                                               */
/*==============================================================*/
create  index index_5 on permission (
name
);/*==============================================================*/
/* Table: permission_menu                                       */
/*==============================================================*/
create table permission_menu (id                   varchar(128)         not null,permission_id        varchar(128)         null,menu_id              varchar(128)         null,constraint pk_permission_menu primary key (id)
);comment on table permission_menu is
'權限菜單表';/*==============================================================*/
/* Index: index_6                                               */
/*==============================================================*/
create  index index_6 on permission_menu (
permission_id,
menu_id
);/*==============================================================*/
/* Table: role                                                  */
/*==============================================================*/
create table role (id                   varchar(128)         not null,name                 varchar(256)         null,description          varchar(256)         null,create_user          varchar(128)         null,create_time          timestamp            null,extension            json                 null,constraint pk_role primary key (id)
);comment on table role is
'角色信息表';comment on column role.id is
'角色編號';comment on column role.name is
'角色名稱';comment on column role.description is
'角色描述';comment on column role.create_user is
'創建人';comment on column role.create_time is
'創建時間';comment on column role.extension is
'擴展信息';/*==============================================================*/
/* Index: index_4                                               */
/*==============================================================*/
create  index index_4 on role (
name
);/*==============================================================*/
/* Table: user_info                                             */
/*==============================================================*/
create table user_info (id                   varchar(128)         not null,username             varchar(128)         null,password             varchar(256)         null,aliasname            varchar(128)         null,phone                varchar(20)          null,face                 varchar(256)         null,profile              varchar(500)         null,sex                  int4                 null,org_id               varchar(128)         null,permission_id        varchar(128)         null,create_user          varchar(128)         null,create_time          timestamp            null,extension            json                 null,constraint pk_user_info primary key (id)
);comment on table user_info is
'用戶信息表';comment on column user_info.id is
'用戶編號';comment on column user_info.username is
'用戶名';comment on column user_info.password is
'用戶密碼';comment on column user_info.aliasname is
'用戶昵稱';comment on column user_info.phone is
'用戶電話';comment on column user_info.face is
'頭像圖片';comment on column user_info.profile is
'個人簡介';comment on column user_info.sex is
'性別';comment on column user_info.org_id is
'所在部門';comment on column user_info.permission_id is
'權限編號';comment on column user_info.create_user is
'創建人';comment on column user_info.create_time is
'創建時間';comment on column user_info.extension is
'擴展信息';/*==============================================================*/
/* Index: index_2                                               */
/*==============================================================*/
create  index index_2 on user_info (
username,
password,
phone
);/*==============================================================*/
/* Table: user_role                                             */
/*==============================================================*/
create table user_role (id                   varchar(128)         not null,user_id              varchar(128)         null,role_id              varchar(128)         null,constraint pk_user_role primary key (id)
);comment on table user_role is
'用戶角色表';comment on column user_role.id is
'編號';comment on column user_role.user_id is
'用戶編號';comment on column user_role.role_id is
'角色編號';/*==============================================================*/
/* Index: index_3                                               */
/*==============================================================*/
create  index index_3 on user_role (
user_id,
role_id
);alter table permission_menuadd constraint fk_permissi_reference_permissi foreign key (permission_id)references permission (id)on delete cascade on update restrict;alter table permission_menuadd constraint fk_permissi_reference_menu foreign key (menu_id)references menu (id)on delete cascade on update restrict;alter table user_infoadd constraint fk_user_inf_reference_organiza foreign key (org_id)references organization (id)on delete cascade on update restrict;alter table user_infoadd constraint fk_user_inf_reference_permissi foreign key (permission_id)references permission (id)on delete set null on update restrict;alter table user_roleadd constraint fk_user_rol_reference_user_inf foreign key (user_id)references user_info (id)on delete cascade on update restrict;alter table user_roleadd constraint fk_user_rol_reference_role foreign key (role_id)references role (id)on delete cascade on update restrict;

3、數據庫部署

3.1 docker部署數據庫

? ? ? ? 1、創建部署文件

????????Docker Compose 簡化了對整個應用程序堆棧的控制,使得在一個易于理解的 YAML 配置文件中輕松管理服務、網絡和數據卷。要使用 Docker Compose 部署 PostgreSQL,首先需創建一個docker-compose.yml文件,如下所示:

version: '3'
services:postgres:image: postgres:13restart: alwaysports:- 5432:5432environment:POSTGRES_USER: postgresPOSTGRES_PASSWORD: postgresvolumes:- /home/pg/data:/var/lib/postgresql/datapgadmin:image: dpage/pgadmin4restart: alwaysports:- 5050:80environment:- PGADMIN_DEFAULT_EMAIL=admin@pgadmin.com- PGADMIN_DEFAULT_PASSWORD=adminvolumes:- /home/pg/admin:/var/lib/pgadmin
  • image:指定了要使用的 Docker 鏡像及其版本。在這里,我們使用了官方的 PostgreSQL 13?版本鏡像。為了確保系統的穩定性和兼容性,推薦使用 PostgreSQL 官方鏡像的一個穩定版本而不是最新版(latest)。通常來說,生產環境中應該避免使用 latest 標簽,因為它指向最新的版本,而最新版本可能包含未經充分測試的特性或變化,這可能會影響到生產環境的穩定性。
  • environment:設置環境變量。我們為 PostgreSQL 數據庫設置了密碼 root。請將其更改為更安全的密碼。這是postgres默認管理員賬戶的密碼。由于這個值是必需的,如果沒有設置,容器將無法啟動。
  • ports:用來將容器的端口映射到宿主機的端口,使得宿主機能夠與集群進行通信。通常,只有服務需要直接從宿主機的網絡訪問時,我們才會映射端口。將容器的 5432 端口映射到宿主機的 5432 端口,使外部可訪問 PostgreSQL。
  • volumes:實現數據持久化的關鍵部分。PostgreSQL 存儲數據在 /var/lib/postgresql/data 路徑,日志存儲在 /var/log/postgresql 路徑。postgres_db 服務將這兩個路徑映射到宿主機的數據卷的 data 和 log 的數據卷上。這意味著即使容器被刪除,存儲在這兩個數據卷上的數據也不會丟失,實現了數據的持久化。配置日志數據卷是一個好的實踐,它可以幫助你更好地管理和保存日志文件,以便于問題診斷和性能監控。

? ? ? ? ?2、啟動服務:docker compose up -d

3.2 創建數據庫表

? ? ? ? 1、登錄數據庫

? ? ? ? 我的地址:http://192.168.0.21:5050/browser/

????????2、創建數據庫

? ? ? ? 3、運行數據庫sql

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/41437.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/41437.shtml
英文地址,請注明出處:http://en.pswp.cn/web/41437.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Django QuerySet對象,filter()方法

filter()方法 用于實現數據過濾功能&#xff0c;相當于sql語句中的where子句。 filter(字段名__exact10) 或 filter(字段名10)類似sql 中的 10 filter(字段名__gt10) 類似SQL中的 >10 filter(price__lt29.99) 類似sql中的 <29.99 filter(字段名__gte10, 字段名__lte20…

程序升級bootloader

文章目錄 概述什么是bootloader&#xff1f;為什么用&#xff1f;bootloader啟動流程圖步驟 下載過程代碼獲取本地配置信息獲取主機傳過來的配置信息bootloader發送2給上位機&#xff0c;上位機發送文件給bootloader根據網站復制CRC 燒寫flasherase啟動編譯問題 概述 用keil編…

聲明隊列和交換機 + 消息轉換器

目錄 1、聲明隊列和交換機 方法一&#xff1a;基于Bean的方式聲明 方法二&#xff1a;基于Spring注解的方式聲明 2、消息轉換器 1、聲明隊列和交換機 方法一&#xff1a;基于Bean的方式聲明 注&#xff1a;隊列和交換機的聲明是放在消費者這邊的&#xff0c;這位發送的人他…

Dynamic Web Module facet version問題

The default superclass, "javax.servlet.http.HttpServlet", according to the projects Dynamic Web Module facet version (3.1), was not found on the Java Build Path. 1.右鍵項目 2.點擊Properties 3.點擊Java Build Path&#xff0c;右邊找到Libraries&…

大模型在營銷領域的探索及創新

1 AIGA介紹 2 AIGA在營銷領域的 應用和探索 3 總結與展望

java 如何暴露header給前端

在Java中&#xff0c;將HTTP響應的Header暴露給前端通常涉及在Web應用程序的服務器端代碼中設置這些Header。這可以通過不同的Java Web框架來實現&#xff0c;比如Spring MVC、JAX-RS&#xff08;Jersey&#xff09;、Servlet等。這里&#xff0c;我將提供一個使用Spring MVC框…

學習筆記——交通安全分析13

目錄 前言 當天學習筆記整理 5城市主干道交通安全分析 結束語 前言 #隨著上一輪SPSS學習完成之后&#xff0c;本人又開始了新教材《交通安全分析》的學習 #整理過程不易&#xff0c;喜歡UP就點個免費的關注趴 #本期內容接上一期12筆記 當天學習筆記整理 5城市主干道交…

docker-compose Install gitlab 17.1.1

gitlab 前言 GitLab 是一個非常流行的開源 DevOps 平臺,用于軟件開發項目的整個生命周期管理。它提供了從版本控制、持續集成/持續部署(CI/CD)、項目規劃到監控和安全的一系列工具。 前提要求 Linux安裝 docker docker-compose 參考Windows 10 ,11 2022 docker docker-c…

多線程爬蟲技術詳解

&#x1f380;引言?? 在當今信息爆炸的時代&#xff0c;網絡爬蟲&#xff08;Web Crawler&#xff09;作為一種自動獲取網頁內容的程序&#xff0c;已經成為數據挖掘和信息檢索不可或缺的工具。多線程爬蟲作為提高爬蟲效率的重要手段&#xff0c;通過并行處理技術大幅度提升…

開發個人Go-ChatGPT--4 用戶管理

開發個人Go-ChatGPT–4 用戶管理 先看下我的目錄結構&#xff0c;可以根據個人愛好&#xff0c;進行重構 |-- Dockerfile |-- LICENSE |-- common | |-- callmodel | | |-- gemma.go | | -- models.go | |-- consts | | |-- code.go | | |-- common.go |…

k8s 部署RuoYi-Vue-Plus之nginx部署

1.掛載存儲 可參考 之前文章設置 https://blog.csdn.net/weimeibuqieryu/article/details/140183843 2.部署yaml 先創建命名空間ruoyi, 有就不用創建了 kubectl create namespace ruoyi我暫不需要使用xxjob和Monitor模塊, 所以去除了. 有需要再自行添加 需要先啟動后端服務…

(ECCV,2022)Mask-CLIP:從CLIP中提取自由密集標簽

文章目錄 Extract Free Dense Labels from CLIP相關資料摘要引言方法Mask-CLIPMask-CLIP 實驗 Extract Free Dense Labels from CLIP 相關資料 代碼&#xff1a;https://github.com/chongzhou96/MaskCLIP 論文&#xff1a;https://arxiv.org/abs/2112.01071 摘要 對比語言-…

SprongBoot及其基礎應用全套部署腳本和配置

POM.xml配置 </dependencies> <!--skywalking日志監控依賴--><dependency><groupId>org.apache.skywalking</groupId><artifactId>apm-toolkit-logback-1.x</artifactId><version>8.5.0</version></dependency&g…

修改編譯依賴openssl的libcrypto.so

由于centos7默認使用openssl1.0.2k的libcrypto.so.10共享庫。即使openssl升級為3.0.11后&#xff0c;編譯使用ldd命令查看共享庫依舊會引用libcrypto.so.10。 現希望引用libcrypto.so.3&#xff0c;需要在生成動態鏈接庫的CMakeLists.txt中增加如下配置&#xff0c;明確指定ope…

《警世賢文》摘抄:守法篇、惜時篇、修性篇、修身篇、待人篇、防人篇(建議多讀書、多看報、少吃零食多睡覺)

若該文為原創文章&#xff0c;轉載請注明原文出處 本文章博客地址&#xff1a;https://hpzwl.blog.csdn.net/article/details/140243440 長沙紅胖子Qt&#xff08;長沙創微智科&#xff09;博文大全&#xff1a;開發技術集合&#xff08;包含Qt實用技術、樹莓派、三維、OpenCV…

mysql 連接出現 Public Key Retrieval is not allowed

在MySQL連接中出現“Public Key Retrieval is not allowed”錯誤&#xff0c;通常是因為在使用安全套接字層&#xff08;SSL&#xff09;連接時遇到了問題。這是因為MySQL 8.0及以上版本對安全性要求更高&#xff0c;特別是在使用密碼插件如caching_sha2_password時&#xff0c…

【周末閑談】AI“搶飯碗”?絕對不是危言聳聽

AI是在幫助開發者還是取代他們? 在軟件開發領域,生成式人工智能(AIGC)正在改變開發者的工作方式。無論是代碼生成、錯誤檢測還是自動化測試,AI工具正在成為開發者的得力助手。然而,這也引發了對開發者職業前景和技能需求變化的討論。AI究竟是在幫助開發者還是取代他們?…

2024組裝一臺能跑AI大模型的電腦

title: 2024組裝一臺能跑AI大模型的電腦 tags: [組裝電腦, AI大模型] categories: [其他, 電腦, windows] 這里不寫組裝步驟&#xff0c;哪里接線&#xff0c;購買什么品牌網上一大堆。 這里只寫如何根據你自己的需求&#xff0c;選擇合適的、兼容的配件。 概述 需求&#xff…

本地多卡(3090)部署通義千問Qwen2-72B大模型提速實踐:從龜速到夠用

最近在做文本風格轉化&#xff0c;涉及千萬token級別的文本。想用大模型轉寫&#xff0c;在線的模型一來涉及數據隱私&#xff0c;二來又不想先墊錢再找報銷。本地的7-9B小模型又感覺效果有限&#xff0c;正好實驗室給俺配了4卡3090的機子&#xff0c;反正也就是做個推理&#…

運維系列.Nginx配置中的高級指令和流程控制

運維專題 Nginx配置中的高級指令和流程控制 - 文章信息 - Author: 李俊才 (jcLee95) Visit me at CSDN: https://jclee95.blog.csdn.netMy WebSite&#xff1a;http://thispage.tech/Email: 291148484163.com. Shenzhen ChinaAddress of this article:https://blog.csdn.net/…