Postgresql - 用户权限数据库

news2025/3/1 3:20:01

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.coloradmin.cn/o/1905756.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C语言 | Leetcode C语言题解之第222题完全二叉树的节点个数

题目&#xff1a; 题解&#xff1a; bool exists(struct TreeNode* root, int level, int k) {int bits 1 << (level - 1);struct TreeNode* node root;while (node ! NULL && bits > 0) {if (!(bits & k)) {node node->left;} else {node node-&…

音频处理5_时频谱1

介绍 时频谱&#xff0c;mel谱&#xff0c; MFCC 1. 概念 magnitude&#xff08;幅值&#xff09;& amplitude&#xff08;振幅)&#xff1a; 振幅指时域信号的瞬时强度或波的高度&#xff0c;它表示信号的最大偏离平均值的程度。 对于一个正弦波信号&#xff0c;振幅是从…

根据RTL图编写Verilog程序

目录 描述 输入描述&#xff1a; 输出描述&#xff1a; 参考代码 描述 根据以下RTL图&#xff0c;使用 Verilog HDL语言编写代码&#xff0c;实现相同的功能&#xff0c;并编写testbench验证功能。 输入描述&#xff1a; clk&#xff1a;系统时钟信号 rst_n&#xff1a;…

第11章 规划过程组(二)(11.9估算活动持续时间)

第11章 规划过程组&#xff08;二&#xff09;11.9估算活动持续时间&#xff0c;在第三版教材第393~395页&#xff1b;文字图片音频方式 第一个知识点&#xff1a;主要工具与技术 1、类比估算 是一种使用相似活动或项目的历史数据&#xff0c;来估算当前活动或项目的持续时间或…

【运维】Windows server 2022 开启 telnet 功能

控制面板》启动或关闭Windows 功能 仪表盘》添加角色和功能》功能》telnet客户端

使用Python+OpenCV实现姿态估计--20240705

姿态估计使用Opencv+Mediapipe来时实现 什么是Mediapipe? Mediapipe是主要用于构建多模式音频,视频或任何时间序列数据的框架。借助MediaPipe框架,可以构建令人印象深刻的ML管道,例如TensorFlow,TFLite等推理模型以及媒体处理功能。 安装命令: pip install mediapipe如果…

回顾 DTC 2024 大会——聚焦数据技术创新:揭秘下一代纯实时搜索引擎 INFINI Pizza

2024 年 4 月 12 日至 13 日&#xff0c;备受瞩目的第十三届“数据技术嘉年华”&#xff08;DTC2024&#xff09;在北京新云南皇冠假日酒店盛大开幕。本次大会由中国 DBA 联盟&#xff08;ACDU&#xff09;与墨天轮社区联合主办&#xff0c;以“智能云原生一体化——DB 与 AI 协…

通过IDEA生成webapp及web.xml配置文件

1、选择File->Project Structure 2、选择Modules-> + -> Web 有的springboot工程选择是war工程,这个web可能已经存在了。 如果不存在,就手动创建,创建后,需要修改pom.xml中的配置 <packaging>war</packaging> 3、创建webapp根目录 这步重点就是创建…

Camera Raw:编辑 - 配置文件

Camera Raw “编辑”模块中的配置文件 Profile面板为照片编辑提供了一个坚实的基础&#xff0c;能够显著改善照片的初始外观&#xff0c;使编辑过程更加高效和灵活。 使用配置文件&#xff0c;可以控制如何呈现照片中的颜色和色调。配置文件旨在作为照片编辑的起点和基础。 ◆ …

在BI软件上使用SQL查询其实很简单

如何在BI软件上使用SQL查询&#xff1f; 我理解在BI上使用SQL是对原始数据进行查询、筛选、清洗&#xff0c;这一点主流BI工具像power BI&#xff0c;tableau、superset都可以支持。 你只需要写好SQL代码&#xff0c;对数据里的相关表进行查询&#xff0c;就可以对查询后的新…

C++ | Leetcode C++题解之第221题最大正方形

题目&#xff1a; 题解&#xff1a; class Solution { public:int maximalSquare(vector<vector<char>>& matrix) {if (matrix.size() 0 || matrix[0].size() 0) {return 0;}int maxSide 0;int rows matrix.size(), columns matrix[0].size();vector<…

warning: GOPATH set to GOROOT (D:\go) has no effect

warning: GOPATH set to GOROOT (D:\go) has no effect gopath 设置一下&#xff0c;并且不要和 goroot 设置成同一个目录

学习笔记——动态路由——OSPF(特殊区域)

十、OSPF特殊区域 1、技术背景 早期路由器靠CPU计算转发&#xff0c;由于硬件技术限制问题&#xff0c;因此资源不是特别充足&#xff0c;因此是要节省资源使用&#xff0c;规划是非常必要的。 OSPF路由器需要同时维护域内路由、域间路由、外部路由信息数据库。当网络规模不…

Vue3中为Ant Design Vue中Modal.confirm自定义内容

在一次业务开发时代码时&#xff0c;碰到了一种既想要Modal.confirm样式&#xff0c;又想要定制其content内容的情况。 大部分情况下&#xff0c;使用Modal.method()这种方式时&#xff0c;可能content内容固定都是字符串&#xff0c;那如果想要做更高级的交互怎么办&#xff…

RTK_ROS_导航(1): GNSS里程计

目录 1. RTK 配置2. ROS驱动3. RTK融合IMU实现里程计4. 纯RTK的定位信息5. 即将实现导航&#xff0c;正在更新中&#xff0c;如果遇到问题&#xff0c;欢迎CSDN讨论... 1. RTK 配置 4G CORS 4G 网络 户外有信号&#xff0c;不能实现RTK&#xff0c;就恢复出厂设置输出报文信…

kafka底层原理性能优化详解:大案例解析(第29天)

系列文章目录 一、Kafka简介 二、Kafka架构设计 三、消息传递机制 四、实例说明&#xff08;案例解析&#xff09; 五、kafka性能优化(案例解析) 文章目录 系列文章目录前言一、Kafka简介二、Kafka架构设计1. Producer&#xff08;生产者&#xff09;&#xff1a;2. Broker&am…

Check if a fine-tuned OpenAI model was successfully deleted

题意&#xff1a;检查微调后的OpenAI模型是否已成功删除 问题背景&#xff1a; I am doing some work with the OpenAI API with Python. Im working with fine-tuning and I am working on deleting an existing model and starting over again. I want to be able to check …

Hive 高可用分布式部署详细步骤

目录 系统版本说明 hive安装包下载及解压 上传mysql-connector-java的jar包 配置环境变量 进入conf配置文件中&#xff0c;将文件重命名 在hadoop集群上创建文件夹 创建本地目录 修改hive-site.xml文件 同步到其他的节点服务器 修改node02中的配置 hive-site.xml 修改…

上海-LM科技(面经)

上海-LM科技 hr电话面 个人简介 个人信息的询问 是否知道芋道框架 技术面 算法题 14. 最长公共前缀&#xff08;写出来即可&#xff09; 聊一下Docker Docker核心概念总结Docker实战 聊一下AOP Spring AOP详解 聊一下JWT JWT 基础概念详解JWT 身份认证优缺点分析 Spring…

【C++】类和对象(中)--下篇

个人主页~ 类和对象上 类和对象中-上篇 类和对象 五、赋值运算符重载1、运算符重载2、赋值运算符重载3、前置和后置重载 六、const成员七、日期类的实现Date.hDate.cpptest.cpptest1测试结果test2测试结果test3测试结果test4测试结果test5测试结果test6测试结果test7测试结果 八…