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_menu
   add constraint fk_permissi_reference_permissi foreign key (permission_id)
      references permission (id)
      on delete cascade on update restrict;

alter table permission_menu
   add constraint fk_permissi_reference_menu foreign key (menu_id)
      references menu (id)
      on delete cascade on update restrict;

alter table user_info
   add constraint fk_user_inf_reference_organiza foreign key (org_id)
      references organization (id)
      on delete cascade on update restrict;

alter table user_info
   add constraint fk_user_inf_reference_permissi foreign key (permission_id)
      references permission (id)
      on delete set null on update restrict;

alter table user_role
   add constraint fk_user_rol_reference_user_inf foreign key (user_id)
      references user_info (id)
      on delete cascade on update restrict;

alter table user_role
   add 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:13
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - /home/pg/data:/var/lib/postgresql/data
  pgadmin:
    image: dpage/pgadmin4
    restart: always
    ports:
      - 5050:80
    environment:
      - PGADMIN_DEFAULT_EMAIL=admin@pgadmin.com
      - PGADMIN_DEFAULT_PASSWORD=admin
    volumes:
      - /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.mfbz.cn/a/782689.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

通过SimU-Net进行同时深度学习体素分类的纵向CECT扫描肝病灶变化分析| 文献速递-深度学习自动化疾病检查

Title 题目 Liver lesion changes analysis in longitudinal CECT scans by simultaneous deep learning voxel classification with SimU-Net 通过SimU-Net进行同时深度学习体素分类的纵向CECT扫描肝病灶变化分析 01 文献速递介绍 影像学随访是对影像学研究的解读&#x…

【c++】C++ IO流

本专栏内容为:C学习专栏,分为初阶和进阶两部分。 通过本专栏的深入学习,你可以了解并掌握C。 💓博主csdn个人主页:小小unicorn ⏩专栏分类:C 🚚代码仓库:小小unicorn的代码仓库&…

深圳唯创知音革新健康监测!语音播报,蓝牙传输,电量检测—全能型智能血压计三大方案,让关爱更“声”动人心

01:背景概述 在快节奏的现代生活中,高血压已成为一种常见的健康问题,高血压不仅仅存在于老年人群中,这种慢性健康问题也慢慢往青中年人群蔓延,它被称为“沉默的杀手”,因为很多时候患者并没有明显的症状。…

Mysql系列-Binlog主从同步

原文链接:https://zhuanlan.zhihu.com/p/669450627 一、主从同步概述 mysql主从同步,即MySQL Replication,可以实现将数据从一台数据库服务器同步到多台数据库服务器。MySQL数据库自带主 从同步功能,经过配置,可以实现基于库、表…

SpringBoot开发实用篇(二)

目录 一:Redis 1:SpringBoot整合Redis 2:SpringBoot读写Redis的客户端 3:SpringBoot操作Redis实现技术切换(jedis) 二:Mongodb 1:Mongodb基础操作 2:SpringBoot整合…

ELFK 8.12.2 部署 -- docker部署方式⚽

👨‍🎓博主简介 🏅CSDN博客专家   🏅云计算领域优质创作者   🏅华为云开发者社区专家博主   🏅阿里云开发者社区专家博主 💊交流社区:运维交流社区 欢迎大家的加入&#xff01…

frp内网映射初体验

frp内网映射工具配置 1、配置穿透映射工具服务器信息2、服务器配置3、客户端配置4、配置完毕后 1、配置穿透映射工具服务器信息 1.1、frp版本是 frp_0.57.0 配置文件中文说明文档:https://gofrp.org/zh-cn/docs/ 参考优秀文章:https://blog.hoshiroko.c…

数据库之DML

1,创建表 mysql> create table student(-> id int primary key,-> name varchar(20) not null,-> grade float-> );插入记录 mysql> insert into student values(1,monkey,98.5); Query OK, 1 row affected (0.01 sec)一次性插入多条记录 mysql…

车灯出现破损破损破裂断角掉角断边等等车灯问题如何修复?用泰达克TADHE车灯无痕修复液来解决。车灯合面合壳密封用泰达克TADHE车灯密封UV胶。

小车车灯无痕修复用的胶是什么? 可以使用在小车车灯无痕修复中的胶水,通常使用的车灯无痕修复专用UV胶。 车灯无痕修复专用胶主要成份是改性丙烯酸UV树脂,主要应用在车灯的专业无痕修复领域。它可以用于修复车灯壳的裂缝或破损,使…

十大护眼落地灯品牌排行榜:2024十大王炸护眼大路灯分享

十大护眼落地灯品牌排行榜有哪些?护眼落地灯作为一款有效的照明神器,广受消费者们的喜爱。然而,市场上护眼落地灯品牌众多,品质参差不齐,一些护眼落地灯在光线舒适度方面的表现并不理想,甚至可能光线不稳定…

SpringBoot后端验证码-防止密码爆破功能

一、简介 为了防止网站的用户被通过密码典爆破。引入验证码的功能是十分有必要的。而前端的验证码又仅仅是只防君子不防小人。通过burpsuit等工具很容易就会被绕过。所以后端实现的验证码才是对用户信息安全的一大重要保障。 实现思路: 1.引入图形生成的依赖 2.生成…

VPN 的入门介绍

VPN(虚拟专用网络) 简介 虚拟专用网络,简称虚拟专网(VPN),其主要功能是在公用网络上建立专用网络,进行加密通讯。在企业网络中有广泛应用。VPN网关通过对数据包的加密和数据包目标地址的转换实…

SpringBoot日常:封装rabbitmq starter组件

文章目录 逻辑实现RabbitExchangeEnumRabbitConfigRabbitModuleInfoRabbitModuleInitializerRabbitPropertiesRabbitProducerManagerPOM.xmlspring.factories 功能测试application.yml配置生产者:消费者:测试结果:总结 本章内容主要介绍编写一…

【电机控制】EG2134无刷电机驱动、控制一体板——开环、无感SMO验证

【电机控制】EG2134无刷电机驱动、控制一体板——开环、无感SMO验证 文章目录 前言一、硬件二、软件三、开环SVPWM四、SMO无感观测器闭环控制五、参考文献总结 前言 【电机控制】直流有刷电机、无刷电机汇总——持续更新 【电机控制】EG2134无感FOC驱控一体板-滑模观测器 使用…

C++11中新特性介绍-之(二)

11.自动类型推导 (1) auto类型自动推导 auto自动推导变量的类型 auto并不代表某个实际的类型,只是一个类型声明的占位符 auto并不是万能的在任意场景下都能推导,使用auto声明的变量必须进行初始化,以让编译器推导出它的实际类型,…

苏东坡传-读书笔记十

不管怎么说,能使读者快乐的确是苏东坡作品的一个特点。苏东坡最快乐就是写作之时。一天,苏东坡对朋友说:“我一生之至乐在执笔为文之时,心中错综复杂之情思,我笔皆可畅达之。我自谓人生之乐,未有过于此者也…

红黑树模拟实现

概念 红黑树,是一种二叉搜索树,但在每个结点上增加一个存储位表示结点的颜色,可以是Red或Black。通过对任何一条从根到叶子的路径上各个结点着色方式的限制,红黑树确保没有一条路径会比其他路径长出俩倍,因而是接近平衡…

昇思25天学习打卡营第20天|RNN实现情感分类

数据准备 使用IMDB影评数据集,包含Positive和Negative两类。 数据下载 import os import shutil import requests import tempfile from tqdm import tqdm from typing import IO from pathlib import Path# 指定保存路径为 home_path/.mindspore_examples cache…

蚓链实践告诉你“企业确保达成数字化营销效果的方法”

在如今这个数字化盛行的时代,企业想在激烈的市场竞争里崭露头角,确保数字营销效果那可是至关重要!今天就来给大家聊聊实现这一目标的基本条件,来自蚓链数字化营销系统的广大用户体验总结。 一、精准的目标定位 企业一定要清楚地知…

第一作者讲述《生态系统架构:人工智能时代从业者的新思维》背后的故事:Episode One

当前,人工智能技术正不断渗透到各行各业,对企业和组织的系统和流程带来深刻的影响。生态系统架构可以帮助企业进行更好的规划和管理人工智能系统,使人工智能技术能够更好地为企业所用,从而实现企业的数字化转型和更好的商业表现。…