若依管理系统,默认是
mysql
数据库,这里将数据源切换为pg
库
在
ruoyi-admin
项目里引入pg
数据库驱动
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.18</version>
</dependency>
修改配置文件里的数据源为
pg
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: org.postgresql.Driver
druid:
# 主库数据源改为pg库
master:
url: jdbc:postgresql://192.168.119.128:5432/FDS?stringtype=unspecified
username: postgres
password: ts123456
因为pg
库里没有dual
表,所以把配置文件里validationQuery
的值,从SELECT 1 FROM DUAL
换为:select version()
来判断数据库是否正常连接
application.yml
里的PageHelper
分页插件换成pgsql
的
pagehelper:
helperDialect: postgresql
supportMethodsArguments: true
params: count=countSql
mapper.xml
里全局搜索sysdate()
,换为now()
mapper.xml
里全局搜索ifnull(字段,‘’)
函数,换成 COALESCE(字段,‘’)
mapper.xml
文件里,搜索status = 0
,改为 status = '0'
char
类型的值,mysql
可以不加引号,但是pg
必须加单引号'query'
,换为query
database()
,换为CURRENT_SCHEMA()
凡是有自增主键的表,都要加自增序列
CREATE SEQUENCE sys_user_id_seq
START WITH 3
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_user alter column user_id set default nextval('sys_user_id_seq');
-- 从当前最大id依次递增
--select setval('sys_user_id_seq',(select max(user_id) from sys_user));
CREATE SEQUENCE sys_oper_log_id_seq
START WITH 3
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_oper_log alter column oper_id set default nextval('sys_oper_log_id_seq');
-- 从当前最大id依次递增
--select setval('sys_oper_log_id_seq',(select max(oper_id) from sys_oper_log));
CREATE SEQUENCE sys_role_id_seq
START WITH 3
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_role alter column role_id set default nextval('sys_role_id_seq');
CREATE SEQUENCE sys_notice_id_seq
START WITH 3
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_notice alter column notice_id set default nextval('sys_notice_id_seq');
CREATE SEQUENCE sys_dict_type_id_seq
START WITH 11
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_dict_type alter column dict_id set default nextval('sys_dict_type_id_seq');
CREATE SEQUENCE sys_dept_id_seq
START WITH 11
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_dept alter column dept_id set default nextval('sys_dept_id_seq');
SELECT 'CREATE SEQUENCE ' || sequence_name || ' START ' || start_value || ';' from information_schema.sequences;
CREATE SEQUENCE gen_table_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table gen_table alter column table_id set default nextval('gen_table_id_seq');
CREATE SEQUENCE gen_table_column_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table gen_table_column alter column column_id set default nextval('gen_table_column_id_seq');
CREATE SEQUENCE sys_post_id_seq
START WITH 5
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_post alter column post_id set default nextval('sys_post_id_seq');
CREATE SEQUENCE sys_dict_data_code_seq
START WITH 30
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_dict_data alter column dict_code set default nextval('sys_dict_data_code_seq');
CREATE SEQUENCE sys_job_seq
START WITH 4
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_job alter column job_id set default nextval('sys_job_seq');
CREATE SEQUENCE sys_job_log_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 设置表某个字段自增
alter table sys_job_log alter column job_log_id set default nextval('sys_job_log_id_seq');
查询序列语法
SELECT 'CREATE SEQUENCE ' || sequence_name || ' START ' || start_value || ';' from information_schema.sequences;
删除序列语法
# 如果新建的序列有问题,可以使用下边这个语句删除后,再重新新建
DROP SEQUENCE sys_oper_log_id_seq
凡是之前是char
类型的字段,并且有默认值的,都需要在navicat
里添加默认值,如sys_user
表、sys_role
表、sys_dept
表的del_flag
、status
字段,设置默认值,注意,要加引号。sys_menu
、sys_post
、sys_notice
、sys_loggininfo
、sys_job_log
、sys_dict_type
、sys_dict_data
表的status
字段,设置默认值0
,加引号。
SysRole.java
里的menuCheckStrictly
、deptCheckStrictly
改为int
类型,index.vue
里的menuCheckStrictly
、deptCheckStrictly
,由true
改为1
,搜索vue
文件里的“父子联动”,注释掉。
GenTableMapper.xml
里的id=“selectDbTableList”
,修改为
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
select * from information_schema.tables
where table_schema = (select CURRENT_SCHEMA())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table)
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<!--<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!– 开始时间检索 –>
AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!– 结束时间检索 –>
AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>
order by create_time desc-->
</select>
如果不想使用数据库,只使用若依提供的封装工具类,那么把下边这三个类的init构造函数去掉即可:
SysConfigServiceImpl.java:
位置:com/ruoyi/system/service/impl/SysConfigServiceImpl.java
SysDictTypeServiceImpl.java:
位置:com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java:
SysJobServiceImpl.java:
位置:com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
powered by kaifamiao