博主已经把若依前后端分离的Postgresql版本的代码和sql脚本做好了,放在了码云上,完全可以正常运行。有需要的可以评论区留下邮箱获取。

一 切换数据源

在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库,注意添加&binaryTransfer=true
            master:
                url: jdbc:postgresql://192.168.119.128:5432/pg?stringtype=unspecified&binaryTransfer=true
                username: postgres
                password: postgres

二 切换函数以及语法

因为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(字段,‘’)

char类型的值,mysql可以不加引号,但是pg必须加单引号

mapper.xml文件里,搜索status = 0 ,改为 status = '0'

搜索`query` ,换为query

全局搜索database(),换为CURRENT_SCHEMA()

GenTableColumnMapper.xml、GenTableMapper.xml这俩文件需要特殊处理,直接使用idea里的AI插件,提示AI来修改,如提示词是 “我的项目,由之前的mysql切换为了postgres数据库,帮我对应修改GenTableColumnMapper.xml、GenTableMapper.xml这俩文件,以适配pg数据库”

我的改成如下内容了,大家可以参考:

GenTableMapper.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
		PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
		"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableMapper">

	<resultMap type="GenTable" id="GenTableResult">
		<id property="tableId" column="table_id"/>
		<result property="tableName" column="table_name"/>
		<result property="tableComment" column="table_comment"/>
		<result property="subTableName" column="sub_table_name"/>
		<result property="subTableFkName" column="sub_table_fk_name"/>
		<result property="className" column="class_name"/>
		<result property="tplCategory" column="tpl_category"/>
		<result property="tplWebType" column="tpl_web_type"/>
		<result property="packageName" column="package_name"/>
		<result property="moduleName" column="module_name"/>
		<result property="businessName" column="business_name"/>
		<result property="functionName" column="function_name"/>
		<result property="functionAuthor" column="function_author"/>
		<result property="genType" column="gen_type"/>
		<result property="genPath" column="gen_path"/>
		<result property="options" column="options"/>
		<result property="createBy" column="create_by"/>
		<result property="createTime" column="create_time"/>
		<result property="updateBy" column="update_by"/>
		<result property="updateTime" column="update_time"/>
		<result property="remark" column="remark"/>
		<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/>
	</resultMap>

	<resultMap type="GenTableColumn" id="GenTableColumnResult">
		<id property="columnId" column="column_id"/>
		<result property="tableId" column="table_id"/>
		<result property="columnName" column="column_name"/>
		<result property="columnComment" column="column_comment"/>
		<result property="columnType" column="column_type"/>
		<result property="javaType" column="java_type"/>
		<result property="javaField" column="java_field"/>
		<result property="isPk" column="is_pk"/>
		<result property="isIncrement" column="is_increment"/>
		<result property="isRequired" column="is_required"/>
		<result property="isInsert" column="is_insert"/>
		<result property="isEdit" column="is_edit"/>
		<result property="isList" column="is_list"/>
		<result property="isQuery" column="is_query"/>
		<result property="queryType" column="query_type"/>
		<result property="htmlType" column="html_type"/>
		<result property="dictType" column="dict_type"/>
		<result property="sort" column="sort"/>
		<result property="createBy" column="create_by"/>
		<result property="createTime" column="create_time"/>
		<result property="updateBy" column="update_by"/>
		<result property="updateTime" column="update_time"/>
	</resultMap>

	<sql id="selectGenTableVo">
		select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name,
			   class_name, tpl_category, tpl_web_type, package_name, module_name,
			   business_name, function_name, function_author, gen_type, gen_path,
			   options, create_by, create_time, update_by, update_time, remark
		from gen_table
	</sql>

	<!-- 查询已生成的表 -->
	<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
		<include refid="selectGenTableVo"/>
		<where>
			<if test="tableName != null and tableName != ''">
				AND lower(table_name) like lower('%' || #{tableName} || '%')
			</if>
			<if test="tableComment != null and tableComment != ''">
				AND lower(table_comment) like lower('%' || #{tableComment} || '%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''">
				AND to_char(create_time, 'YYYYMMDD') >= to_char(#{params.beginTime}, 'YYYYMMDD')
			</if>
			<if test="params.endTime != null and params.endTime != ''">
				AND to_char(create_time, 'YYYYMMDD') &lt;=  to_char (#{params.endTime}, 'YYYYMMDD')
			</if>
		</where>
	</select>

	<!-- 查询数据库中未生成的表 -->
	<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
		SELECT
		t.tablename as table_name,
		obj_description(c.oid) AS table_comment,
		now() AS create_time,
		now() AS update_time
		FROM pg_tables t
		JOIN pg_class c ON c.relname = t.tablename
		WHERE t.schemaname = current_schema()
		AND t.tablename NOT LIKE 'qrtz\_%'
		AND t.tablename NOT LIKE 'gen\_%'
		AND t.tablename NOT IN (SELECT table_name FROM gen_table)
		<if test="tableName != null and tableName != ''">
			AND lower(t.tablename) like lower('%' || #{tableName} || '%')
		</if>
		<if test="tableComment != null and tableComment != ''">
			AND lower(obj_description(c.oid)) like lower('%' || #{tableComment} || '%')
		</if>
		ORDER BY t.tablename
	</select>

	<!-- 根据表名批量查询 -->
	<select id="selectDbTableListByNames" resultMap="GenTableResult">
		SELECT
		t.tablename AS table_name,
		obj_description(c.oid) AS table_comment,
		now() AS create_time,
		now() AS update_time
		FROM pg_tables t
		JOIN pg_class c ON c.relname = t.tablename
		WHERE t.schemaname = current_schema()
		AND t.tablename NOT LIKE 'qrtz\_%'
		AND t.tablename NOT LIKE 'gen\_%'
		AND t.tablename IN
		<foreach collection="array" item="name" open="(" separator="," close=")">
			#{name}
		</foreach>
	</select>

	<!-- 根据表名查单表(带注释) -->
	<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
		SELECT
			t.tablename AS table_name,
			obj_description(c.oid) AS table_comment,
			now() AS create_time,
			now() AS update_time
		FROM pg_tables t
				 JOIN pg_class c ON c.relname = t.tablename
		WHERE t.schemaname = current_schema()
		  AND obj_description(c.oid) IS NOT NULL
		  AND t.tablename = #{tableName}
	</select>

	<!-- 根据 ID 查询完整表信息(含列) -->
	<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
		SELECT
			t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name,
			t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name,
			t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path,
			t.options, t.remark,
			c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type,
			c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert,
			c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
		FROM gen_table t
				 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
		WHERE t.table_id = #{tableId}
		ORDER BY c.sort
	</select>

	<!-- 根据表名查询完整表信息(含列) -->
	<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
		SELECT
			t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name,
			t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name,
			t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path,
			t.options, t.remark,
			c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type,
			c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert,
			c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
		FROM gen_table t
				 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
		WHERE t.table_name = #{tableName}
		ORDER BY c.sort
	</select>

	<!-- 查询所有生成表 -->
	<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
		SELECT
			t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name,
			t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name,
			t.business_name, t.function_name, t.function_author, t.options, t.remark,
			c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type,
			c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert,
			c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
		FROM gen_table t
				 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
		ORDER BY c.sort
	</select>

	<!-- 插入生成表 -->
	<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
		INSERT INTO gen_table (
		<if test="tableName != null">table_name,</if>
		<if test="tableComment != null and tableComment != ''">table_comment,</if>
		<if test="className != null and className != ''">class_name,</if>
		<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
		<if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if>
		<if test="packageName != null and packageName != ''">package_name,</if>
		<if test="moduleName != null and moduleName != ''">module_name,</if>
		<if test="businessName != null and businessName != ''">business_name,</if>
		<if test="functionName != null and functionName != ''">function_name,</if>
		<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
		<if test="genType != null and genType != ''">gen_type,</if>
		<if test="genPath != null and genPath != ''">gen_path,</if>
		<if test="remark != null and remark != ''">remark,</if>
		<if test="createBy != null and createBy != ''">create_by,</if>
		create_time
		) VALUES (
		<if test="tableName != null">#{tableName},</if>
		<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
		<if test="className != null and className != ''">#{className},</if>
		<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
		<if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if>
		<if test="packageName != null and packageName != ''">#{packageName},</if>
		<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
		<if test="businessName != null and businessName != ''">#{businessName},</if>
		<if test="functionName != null and functionName != ''">#{functionName},</if>
		<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
		<if test="genType != null and genType != ''">#{genType},</if>
		<if test="genPath != null and genPath != ''">#{genPath},</if>
		<if test="remark != null and remark != ''">#{remark},</if>
		<if test="createBy != null and createBy != ''">#{createBy},</if>
		now()
		)
	</insert>

	<!-- 动态执行建表 SQL(注意:${sql} 有注入风险,确保来源可信) -->
	<update id="createTable">
		${sql}
	</update>

	<!-- 更新生成表 -->
	<update id="updateGenTable" parameterType="GenTable">
		UPDATE gen_table
		<set>
			<if test="tableName != null">table_name = #{tableName},</if>
			<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
			<if test="subTableName != null">sub_table_name = #{subTableName},</if>
			<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
			<if test="className != null and className != ''">class_name = #{className},</if>
			<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
			<if test="genType != null and genType != ''">gen_type = #{genType},</if>
			<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
			<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
			<if test="tplWebType != null and tplWebType != ''">tpl_web_type = #{tplWebType},</if>
			<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
			<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
			<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
			<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
			<if test="options != null and options != ''">options = #{options},</if>
			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
			<if test="remark != null">remark = #{remark},</if>
			update_time = now()
		</set>
		WHERE table_id = #{tableId}
	</update>

	<!-- 删除生成表 -->
	<delete id="deleteGenTableByIds" parameterType="Long">
		DELETE FROM gen_table
		WHERE table_id IN
		<foreach collection="array" item="tableId" open="(" separator="," close=")">
			#{tableId}
		</foreach>
	</delete>

</mapper>

GenTableColumnMapper.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper">

    <resultMap type="GenTableColumn" id="GenTableColumnResult">
        <id property="columnId" column="column_id"/>
        <result property="tableId" column="table_id"/>
        <result property="columnName" column="column_name"/>
        <result property="columnComment" column="column_comment"/>
        <result property="columnType" column="column_type"/>
        <result property="javaType" column="java_type"/>
        <result property="javaField" column="java_field"/>
        <result property="isPk" column="is_pk"/>
        <result property="isIncrement" column="is_increment"/>
        <result property="isRequired" column="is_required"/>
        <result property="isInsert" column="is_insert"/>
        <result property="isEdit" column="is_edit"/>
        <result property="isList" column="is_list"/>
        <result property="isQuery" column="is_query"/>
        <result property="queryType" column="query_type"/>
        <result property="htmlType" column="html_type"/>
        <result property="dictType" column="dict_type"/>
        <result property="sort" column="sort"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectGenTableColumnVo">
        SELECT column_id, table_id, column_name, column_comment, column_type,
               java_type, java_field, is_pk, is_increment, is_required,
               is_insert, is_edit, is_list, is_query, query_type,
               html_type, dict_type, sort, create_by, create_time,
               update_by, update_time
        FROM gen_table_column
    </sql>

    <select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult">
        <include refid="selectGenTableColumnVo"/>
        WHERE table_id = #{tableId}
        ORDER BY sort
    </select>

    <!-- 从数据库读取列元数据(PostgreSQL) -->
    <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
        SELECT
            a.attname AS column_name,
            CASE WHEN a.attnotnull AND con.contype IS NULL THEN '1' ELSE '0' END AS is_required,
            CASE WHEN con.contype = 'p' THEN '1' ELSE '0' END AS is_pk,
            a.attnum AS sort,
            col_description(a.attrelid, a.attnum) AS column_comment,
            CASE
                WHEN a.attidentity IN ('a', 'd') THEN '1'
                WHEN pg_get_serial_sequence(#{tableName}, a.attname) IS NOT NULL THEN '1'
                ELSE '0'
                END AS is_increment,
            format_type(a.atttypid, a.atttypmod) AS column_type
        FROM pg_attribute a
                 JOIN pg_class c ON a.attrelid = c.oid
                 JOIN pg_namespace n ON c.relnamespace = n.oid
                 LEFT JOIN pg_constraint con ON con.conrelid = c.oid AND a.attnum = ANY(con.conkey) AND con.contype = 'p'
        WHERE c.relname = #{tableName}
          AND n.nspname = current_schema()
          AND a.attnum > 0
          AND NOT a.attisdropped
        ORDER BY a.attnum
    </select>

    <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
        INSERT INTO gen_table_column (
        <if test="tableId != null and tableId != ''">table_id,</if>
        <if test="columnName != null and columnName != ''">column_name,</if>
        <if test="columnComment != null and columnComment != ''">column_comment,</if>
        <if test="columnType != null and columnType != ''">column_type,</if>
        <if test="javaType != null and javaType != ''">java_type,</if>
        <if test="javaField != null and javaField != ''">java_field,</if>
        <if test="isPk != null and isPk != ''">is_pk,</if>
        <if test="isIncrement != null and isIncrement != ''">is_increment,</if>
        <if test="isRequired != null and isRequired != ''">is_required,</if>
        <if test="isInsert != null and isInsert != ''">is_insert,</if>
        <if test="isEdit != null and isEdit != ''">is_edit,</if>
        <if test="isList != null and isList != ''">is_list,</if>
        <if test="isQuery != null and isQuery != ''">is_query,</if>
        <if test="queryType != null and queryType != ''">query_type,</if>
        <if test="htmlType != null and htmlType != ''">html_type,</if>
        <if test="dictType != null and dictType != ''">dict_type,</if>
        <if test="sort != null">sort,</if>
        <if test="createBy != null and createBy != ''">create_by,</if>
        create_time
        ) VALUES (
        <if test="tableId != null and tableId != ''">#{tableId},</if>
        <if test="columnName != null and columnName != ''">#{columnName},</if>
        <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
        <if test="columnType != null and columnType != ''">#{columnType},</if>
        <if test="javaType != null and javaType != ''">#{javaType},</if>
        <if test="javaField != null and javaField != ''">#{javaField},</if>
        <if test="isPk != null and isPk != ''">#{isPk},</if>
        <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
        <if test="isRequired != null and isRequired != ''">#{isRequired},</if>
        <if test="isInsert != null and isInsert != ''">#{isInsert},</if>
        <if test="isEdit != null and isEdit != ''">#{isEdit},</if>
        <if test="isList != null and isList != ''">#{isList},</if>
        <if test="isQuery != null and isQuery != ''">#{isQuery},</if>
        <if test="queryType != null and queryType != ''">#{queryType},</if>
        <if test="htmlType != null and htmlType != ''">#{htmlType},</if>
        <if test="dictType != null and dictType != ''">#{dictType},</if>
        <if test="sort != null">#{sort},</if>
        <if test="createBy != null and createBy != ''">#{createBy},</if>
        now()
        )
    </insert>

    <update id="updateGenTableColumn" parameterType="GenTableColumn">
        UPDATE gen_table_column
        <set>
            <if test="columnComment != null">column_comment = #{columnComment},</if>
            <if test="javaType != null">java_type = #{javaType},</if>
            <if test="javaField != null">java_field = #{javaField},</if>
            <if test="isInsert != null">is_insert = #{isInsert},</if>
            <if test="isEdit != null">is_edit = #{isEdit},</if>
            <if test="isList != null">is_list = #{isList},</if>
            <if test="isQuery != null">is_query = #{isQuery},</if>
            <if test="isRequired != null">is_required = #{isRequired},</if>
            <if test="queryType != null">query_type = #{queryType},</if>
            <if test="htmlType != null">html_type = #{htmlType},</if>
            <if test="dictType != null">dict_type = #{dictType},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = now()
        </set>
        WHERE column_id = #{columnId}
    </update>

    <delete id="deleteGenTableColumnByIds" parameterType="Long">
        DELETE FROM gen_table_column
        WHERE table_id IN
        <foreach collection="array" item="tableId" open="(" separator="," close=")">
            #{tableId}
        </foreach>
    </delete>

    <delete id="deleteGenTableColumns">
        DELETE FROM gen_table_column
        WHERE column_id IN
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item.columnId}
        </foreach>
    </delete>

</mapper>

需要在GenUtils.initTable方法里,添加这么一行:genTable.setFormColNum(1);

在这里插入图片描述

三 加自增序列

先创建mysql和postgres数据库,将脚本导入到mysql库里。再通过navicat,将mysql数据库导入到postgres数据库里

在这里插入图片描述

导入到postgres数据库里:

在这里插入图片描述

在pg库里,凡是有自增主键的表,都要加自增序列

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');
CREATE SEQUENCE sys_menu_id_seq
	START WITH 2000
	INCREMENT BY 1
	NO MINVALUE
	NO MAXVALUE 
	CACHE 1;
	
-- 设置表某个字段自增
alter table sys_menu alter column menu_id set default nextval('sys_menu_id_seq');

查询序列语法

SELECT 'CREATE SEQUENCE ' || sequence_name || ' START ' ||  start_value || ';' from information_schema.sequences;

删除序列语法

# 如果新建的序列有问题,可以使用下边这个语句删除后,再重新新建
DROP SEQUENCE sys_oper_log_id_seq;
# 或者级联删除
DROP SEQUENCE sys_menu_id_seq CASCADE;

qrtz开头的表,要全部删除,使用如下脚本再重新生成一遍。因为之前源脚本是大写,且双引号包裹,但 PostgreSQL 默认搜索小写表名,导致找不到表。如下脚本,表名不带双引号,则会自动创建为小写

-- ============================================
-- PostgreSQL Quartz 定时任务表
-- 包含删除脚本、建表脚本、索引、外键
-- ============================================

-- ================== 删除脚本 ==================
-- 步骤1:先删除外键约束(按依赖关系反向删除)
-- 使用双引号删除大写的表
DROP TABLE IF EXISTS "QRTZ_BLOB_TRIGGERS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_CRON_TRIGGERS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_SIMPLE_TRIGGERS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_SIMPROP_TRIGGERS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_FIRED_TRIGGERS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_TRIGGERS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_CALENDARS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_PAUSED_TRIGGER_GRPS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_SCHEDULER_STATE" CASCADE;
DROP TABLE IF EXISTS "QRTZ_LOCKS" CASCADE;
DROP TABLE IF EXISTS "QRTZ_JOB_DETAILS" CASCADE;

-- ================== 建表脚本 ==================

-- ----------------------------
-- Table structure for QRTZ_JOB_DETAILS (任务详细信息表)
-- ----------------------------
CREATE TABLE QRTZ_JOB_DETAILS (
    sched_name varchar(120) NOT NULL,
    job_name varchar(200) NOT NULL,
    job_group varchar(200) NOT NULL,
    description varchar(250),
    job_class_name varchar(250) NOT NULL,
    is_durable varchar(1) NOT NULL,
    is_nonconcurrent varchar(1) NOT NULL,
    is_update_data varchar(1) NOT NULL,
    requests_recovery varchar(1) NOT NULL,
    job_data bytea,
    CONSTRAINT QRTZ_JOB_DETAILS_pkey PRIMARY KEY (sched_name, job_name, job_group)
);
COMMENT ON TABLE QRTZ_JOB_DETAILS IS '任务详细信息表';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.job_name IS '任务名称';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.job_group IS '任务组名';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.description IS '相关介绍';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.job_class_name IS '执行任务类名称';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.is_durable IS '是否持久化';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.is_nonconcurrent IS '是否并发';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.is_update_data IS '是否更新数据';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.requests_recovery IS '是否接受恢复执行';
COMMENT ON COLUMN QRTZ_JOB_DETAILS.job_data IS '存放持久化job对象';

-- ----------------------------
-- Table structure for QRTZ_TRIGGERS (触发器详细信息表)
-- ----------------------------
CREATE TABLE QRTZ_TRIGGERS (
    sched_name varchar(120) NOT NULL,
    trigger_name varchar(200) NOT NULL,
    trigger_group varchar(200) NOT NULL,
    job_name varchar(200) NOT NULL,
    job_group varchar(200) NOT NULL,
    description varchar(250),
    next_fire_time bigint,
    prev_fire_time bigint,
    priority integer,
    trigger_state varchar(16) NOT NULL,
    trigger_type varchar(8) NOT NULL,
    start_time bigint NOT NULL,
    end_time bigint,
    calendar_name varchar(200),
    misfire_instr smallint,
    job_data bytea,
    CONSTRAINT QRTZ_TRIGGERS_pkey PRIMARY KEY (sched_name, trigger_name, trigger_group),
    CONSTRAINT QRTZ_TRIGGERS_ibfk_1 FOREIGN KEY (sched_name, job_name, job_group) 
        REFERENCES QRTZ_JOB_DETAILS(sched_name, job_name, job_group) ON DELETE NO ACTION ON UPDATE NO ACTION
);
COMMENT ON TABLE QRTZ_TRIGGERS IS '触发器详细信息表';
COMMENT ON COLUMN QRTZ_TRIGGERS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_TRIGGERS.trigger_name IS '触发器的名字';
COMMENT ON COLUMN QRTZ_TRIGGERS.trigger_group IS '触发器所属组的名字';
COMMENT ON COLUMN QRTZ_TRIGGERS.job_name IS 'qrtz_job_details表job_name的外键';
COMMENT ON COLUMN QRTZ_TRIGGERS.job_group IS 'qrtz_job_details表job_group的外键';
COMMENT ON COLUMN QRTZ_TRIGGERS.description IS '相关介绍';
COMMENT ON COLUMN QRTZ_TRIGGERS.next_fire_time IS '上一次触发时间(毫秒)';
COMMENT ON COLUMN QRTZ_TRIGGERS.prev_fire_time IS '下一次触发时间(默认为-1表示不触发)';
COMMENT ON COLUMN QRTZ_TRIGGERS.priority IS '优先级';
COMMENT ON COLUMN QRTZ_TRIGGERS.trigger_state IS '触发器状态';
COMMENT ON COLUMN QRTZ_TRIGGERS.trigger_type IS '触发器的类型';
COMMENT ON COLUMN QRTZ_TRIGGERS.start_time IS '开始时间';
COMMENT ON COLUMN QRTZ_TRIGGERS.end_time IS '结束时间';
COMMENT ON COLUMN QRTZ_TRIGGERS.calendar_name IS '日程表名称';
COMMENT ON COLUMN QRTZ_TRIGGERS.misfire_instr IS '补偿执行的策略';
COMMENT ON COLUMN QRTZ_TRIGGERS.job_data IS '存放持久化job对象';

-- ----------------------------
-- Table structure for QRTZ_SIMPLE_TRIGGERS (简单触发器的信息表)
-- ----------------------------
CREATE TABLE QRTZ_SIMPLE_TRIGGERS (
    sched_name varchar(120) NOT NULL,
    trigger_name varchar(200) NOT NULL,
    trigger_group varchar(200) NOT NULL,
    repeat_count bigint NOT NULL,
    repeat_interval bigint NOT NULL,
    times_triggered bigint NOT NULL,
    CONSTRAINT QRTZ_SIMPLE_TRIGGERS_pkey PRIMARY KEY (sched_name, trigger_name, trigger_group),
    CONSTRAINT QRTZ_SIMPLE_TRIGGERS_ibfk_1 FOREIGN KEY (sched_name, trigger_name, trigger_group) 
        REFERENCES QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group) ON DELETE NO ACTION ON UPDATE NO ACTION
);
COMMENT ON TABLE QRTZ_SIMPLE_TRIGGERS IS '简单触发器的信息表';
COMMENT ON COLUMN QRTZ_SIMPLE_TRIGGERS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_SIMPLE_TRIGGERS.trigger_name IS 'qrtz_triggers表trigger_name的外键';
COMMENT ON COLUMN QRTZ_SIMPLE_TRIGGERS.trigger_group IS 'qrtz_triggers表trigger_group的外键';
COMMENT ON COLUMN QRTZ_SIMPLE_TRIGGERS.repeat_count IS '重复的次数统计';
COMMENT ON COLUMN QRTZ_SIMPLE_TRIGGERS.repeat_interval IS '重复的间隔时间';
COMMENT ON COLUMN QRTZ_SIMPLE_TRIGGERS.times_triggered IS '已经触发的次数';

-- ----------------------------
-- Table structure for QRTZ_CRON_TRIGGERS (Cron类型的触发器表)
-- ----------------------------
CREATE TABLE QRTZ_CRON_TRIGGERS (
    sched_name varchar(120) NOT NULL,
    trigger_name varchar(200) NOT NULL,
    trigger_group varchar(200) NOT NULL,
    cron_expression varchar(200) NOT NULL,
    time_zone_id varchar(80),
    CONSTRAINT QRTZ_CRON_TRIGGERS_pkey PRIMARY KEY (sched_name, trigger_name, trigger_group),
    CONSTRAINT QRTZ_CRON_TRIGGERS_ibfk_1 FOREIGN KEY (sched_name, trigger_name, trigger_group) 
        REFERENCES QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group) ON DELETE NO ACTION ON UPDATE NO ACTION
);
COMMENT ON TABLE QRTZ_CRON_TRIGGERS IS 'Cron类型的触发器表';
COMMENT ON COLUMN QRTZ_CRON_TRIGGERS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_CRON_TRIGGERS.trigger_name IS 'qrtz_triggers表trigger_name的外键';
COMMENT ON COLUMN QRTZ_CRON_TRIGGERS.trigger_group IS 'qrtz_triggers表trigger_group的外键';
COMMENT ON COLUMN QRTZ_CRON_TRIGGERS.cron_expression IS 'cron表达式';
COMMENT ON COLUMN QRTZ_CRON_TRIGGERS.time_zone_id IS '时区';

-- ----------------------------
-- Table structure for QRTZ_SIMPROP_TRIGGERS (同步机制的行锁表)
-- ----------------------------
CREATE TABLE QRTZ_SIMPROP_TRIGGERS (
    sched_name varchar(120) NOT NULL,
    trigger_name varchar(200) NOT NULL,
    trigger_group varchar(200) NOT NULL,
    str_prop_1 varchar(512),
    str_prop_2 varchar(512),
    str_prop_3 varchar(512),
    int_prop_1 integer,
    int_prop_2 integer,
    long_prop_1 bigint,
    long_prop_2 bigint,
    dec_prop_1 numeric(13,4),
    dec_prop_2 numeric(13,4),
    bool_prop_1 varchar(1),
    bool_prop_2 varchar(1),
    CONSTRAINT QRTZ_SIMPROP_TRIGGERS_pkey PRIMARY KEY (sched_name, trigger_name, trigger_group),
    CONSTRAINT QRTZ_SIMPROP_TRIGGERS_ibfk_1 FOREIGN KEY (sched_name, trigger_name, trigger_group) 
        REFERENCES QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group) ON DELETE NO ACTION ON UPDATE NO ACTION
);
COMMENT ON TABLE QRTZ_SIMPROP_TRIGGERS IS '同步机制的行锁表';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.trigger_name IS 'qrtz_triggers表trigger_name的外键';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.trigger_group IS 'qrtz_triggers表trigger_group的外键';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.str_prop_1 IS 'String类型的trigger的第一个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.str_prop_2 IS 'String类型的trigger的第二个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.str_prop_3 IS 'String类型的trigger的第三个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.int_prop_1 IS 'int类型的trigger的第一个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.int_prop_2 IS 'int类型的trigger的第二个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.long_prop_1 IS 'long类型的trigger的第一个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.long_prop_2 IS 'long类型的trigger的第二个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.dec_prop_1 IS 'decimal类型的trigger的第一个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.dec_prop_2 IS 'decimal类型的trigger的第二个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.bool_prop_1 IS 'Boolean类型的trigger的第一个参数';
COMMENT ON COLUMN QRTZ_SIMPROP_TRIGGERS.bool_prop_2 IS 'Boolean类型的trigger的第二个参数';

-- ----------------------------
-- Table structure for QRTZ_BLOB_TRIGGERS (Blob类型的触发器表)
-- ----------------------------
CREATE TABLE QRTZ_BLOB_TRIGGERS (
    sched_name varchar(120) NOT NULL,
    trigger_name varchar(200) NOT NULL,
    trigger_group varchar(200) NOT NULL,
    blob_data bytea,
    CONSTRAINT QRTZ_BLOB_TRIGGERS_pkey PRIMARY KEY (sched_name, trigger_name, trigger_group),
    CONSTRAINT QRTZ_BLOB_TRIGGERS_ibfk_1 FOREIGN KEY (sched_name, trigger_name, trigger_group) 
        REFERENCES QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group) ON DELETE NO ACTION ON UPDATE NO ACTION
);
COMMENT ON TABLE QRTZ_BLOB_TRIGGERS IS 'Blob类型的触发器表';
COMMENT ON COLUMN QRTZ_BLOB_TRIGGERS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_BLOB_TRIGGERS.trigger_name IS 'qrtz_triggers表trigger_name的外键';
COMMENT ON COLUMN QRTZ_BLOB_TRIGGERS.trigger_group IS 'qrtz_triggers表trigger_group的外键';
COMMENT ON COLUMN QRTZ_BLOB_TRIGGERS.blob_data IS '存放持久化Trigger对象';

-- ----------------------------
-- Table structure for QRTZ_CALENDARS (日历信息表)
-- ----------------------------
CREATE TABLE QRTZ_CALENDARS (
    sched_name varchar(120) NOT NULL,
    calendar_name varchar(200) NOT NULL,
    calendar bytea NOT NULL,
    CONSTRAINT QRTZ_CALENDARS_pkey PRIMARY KEY (sched_name, calendar_name)
);
COMMENT ON TABLE QRTZ_CALENDARS IS '日历信息表';
COMMENT ON COLUMN QRTZ_CALENDARS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_CALENDARS.calendar_name IS '日历名称';
COMMENT ON COLUMN QRTZ_CALENDARS.calendar IS '存放持久化calendar对象';

-- ----------------------------
-- Table structure for QRTZ_PAUSED_TRIGGER_GRPS (暂停的触发器表)
-- ----------------------------
CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS (
    sched_name varchar(120) NOT NULL,
    trigger_group varchar(200) NOT NULL,
    CONSTRAINT QRTZ_PAUSED_TRIGGER_GRPS_pkey PRIMARY KEY (sched_name, trigger_group)
);
COMMENT ON TABLE QRTZ_PAUSED_TRIGGER_GRPS IS '暂停的触发器表';
COMMENT ON COLUMN QRTZ_PAUSED_TRIGGER_GRPS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_PAUSED_TRIGGER_GRPS.trigger_group IS 'qrtz_triggers表trigger_group的外键';

-- ----------------------------
-- Table structure for QRTZ_FIRED_TRIGGERS (已触发的触发器表)
-- ----------------------------
CREATE TABLE QRTZ_FIRED_TRIGGERS (
    sched_name varchar(120) NOT NULL,
    entry_id varchar(95) NOT NULL,
    trigger_name varchar(200) NOT NULL,
    trigger_group varchar(200) NOT NULL,
    instance_name varchar(200) NOT NULL,
    fired_time bigint NOT NULL,
    sched_time bigint NOT NULL,
    priority integer NOT NULL,
    state varchar(16) NOT NULL,
    job_name varchar(200),
    job_group varchar(200),
    is_nonconcurrent varchar(1),
    requests_recovery varchar(1),
    CONSTRAINT QRTZ_FIRED_TRIGGERS_pkey PRIMARY KEY (sched_name, entry_id)
);
COMMENT ON TABLE QRTZ_FIRED_TRIGGERS IS '已触发的触发器表';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.entry_id IS '调度器实例id';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.trigger_name IS 'qrtz_triggers表trigger_name的外键';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.trigger_group IS 'qrtz_triggers表trigger_group的外键';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.instance_name IS '调度器实例名';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.fired_time IS '触发的时间';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.sched_time IS '定时器制定的时间';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.priority IS '优先级';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.state IS '状态';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.job_name IS '任务名称';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.job_group IS '任务组名';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.is_nonconcurrent IS '是否并发';
COMMENT ON COLUMN QRTZ_FIRED_TRIGGERS.requests_recovery IS '是否接受恢复执行';

-- ----------------------------
-- Table structure for QRTZ_SCHEDULER_STATE (调度器状态表)
-- ----------------------------
CREATE TABLE QRTZ_SCHEDULER_STATE (
    sched_name varchar(120) NOT NULL,
    instance_name varchar(200) NOT NULL,
    last_checkin_time bigint NOT NULL,
    checkin_interval bigint NOT NULL,
    CONSTRAINT QRTZ_SCHEDULER_STATE_pkey PRIMARY KEY (sched_name, instance_name)
);
COMMENT ON TABLE QRTZ_SCHEDULER_STATE IS '调度器状态表';
COMMENT ON COLUMN QRTZ_SCHEDULER_STATE.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_SCHEDULER_STATE.instance_name IS '实例名称';
COMMENT ON COLUMN QRTZ_SCHEDULER_STATE.last_checkin_time IS '上次检查时间';
COMMENT ON COLUMN QRTZ_SCHEDULER_STATE.checkin_interval IS '检查间隔时间';

-- ----------------------------
-- Table structure for QRTZ_LOCKS (存储的悲观锁信息表)
-- ----------------------------
CREATE TABLE QRTZ_LOCKS (
    sched_name varchar(120) NOT NULL,
    lock_name varchar(40) NOT NULL,
    CONSTRAINT QRTZ_LOCKS_pkey PRIMARY KEY (sched_name, lock_name)
);
COMMENT ON TABLE QRTZ_LOCKS IS '存储的悲观锁信息表';
COMMENT ON COLUMN QRTZ_LOCKS.sched_name IS '调度名称';
COMMENT ON COLUMN QRTZ_LOCKS.lock_name IS '悲观锁名称';

-- ================== 索引脚本 ==================

-- QRTZ_JOB_DETAILS 索引
CREATE INDEX idx_qrtz_j_req_recovery ON QRTZ_JOB_DETAILS(sched_name, requests_recovery);
CREATE INDEX idx_qrtz_j_grp ON QRTZ_JOB_DETAILS(sched_name, job_group);

-- QRTZ_TRIGGERS 索引
CREATE INDEX idx_qrtz_t_j ON QRTZ_TRIGGERS(sched_name, job_name, job_group);
CREATE INDEX idx_qrtz_t_jg ON QRTZ_TRIGGERS(sched_name, job_group);
CREATE INDEX idx_qrtz_t_c ON QRTZ_TRIGGERS(sched_name, calendar_name);
CREATE INDEX idx_qrtz_t_g ON QRTZ_TRIGGERS(sched_name, trigger_group);
CREATE INDEX idx_qrtz_t_state ON QRTZ_TRIGGERS(sched_name, trigger_state);
CREATE INDEX idx_qrtz_t_n_state ON QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group, trigger_state);
CREATE INDEX idx_qrtz_t_n_g_state ON QRTZ_TRIGGERS(sched_name, trigger_group, trigger_state);
CREATE INDEX idx_qrtz_t_next_fire_time ON QRTZ_TRIGGERS(sched_name, next_fire_time);
CREATE INDEX idx_qrtz_t_nft_state ON QRTZ_TRIGGERS(sched_name, trigger_state, next_fire_time);
CREATE INDEX idx_qrtz_t_nft_misfire ON QRTZ_TRIGGERS(sched_name, misfire_instr, next_fire_time);
CREATE INDEX idx_qrtz_t_nft_state_misfire ON QRTZ_TRIGGERS(sched_name, trigger_state, misfire_instr, next_fire_time, trigger_group);
CREATE INDEX idx_qrtz_t_nft_state_misfire_g ON QRTZ_TRIGGERS(sched_name, next_fire_time, trigger_group, misfire_instr, trigger_state);

-- QRTZ_FIRED_TRIGGERS 索引
CREATE INDEX idx_qrtz_ft_trig_grp ON QRTZ_FIRED_TRIGGERS(sched_name, trigger_group);
CREATE INDEX idx_qrtz_ft_trig_name ON QRTZ_FIRED_TRIGGERS(sched_name, trigger_name);
CREATE INDEX idx_qrtz_ft_trig_nm_gp ON QRTZ_FIRED_TRIGGERS(sched_name, trigger_name, trigger_group);
CREATE INDEX idx_qrtz_ft_inst_job_req_recovery ON QRTZ_FIRED_TRIGGERS(sched_name, instance_name, requests_recovery);
CREATE INDEX idx_qrtz_ft_job_grp ON QRTZ_FIRED_TRIGGERS(sched_name, job_name, job_group);

四 加默认值、加引号

凡是之前是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,加引号。

在这里插入图片描述

GenUtils.initTable()方法,这里需加一行

在这里插入图片描述

genTable.setFormColNum(1);

五 改代码

由于mysql会自动把前端传来的String类型的0、1转为int类型的值,插入数据库不会报错(数据库是int类型),但是pg库不会自动转类型,会报错, 所以需要做如下修改

在这里插入图片描述

<if test="isFrame != null and isFrame != ''">CAST(#{isFrame} AS INTEGER),</if>
<if test="isCache != null and isCache != ''">CAST(#{isCache} AS INTEGER),</if>

六 去掉数据库的校验

如果我们不想使用数据库,只使用若依提供的封装工具类,那么把下边这三个类的init构造函数去掉即可:
SysConfigServiceImpl:
在这里插入图片描述
SysDictTypeServiceImpl:
在这里插入图片描述
SysJobServiceImpl:
在这里插入图片描述

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐