Files
weblog-springboot/sql/createTable.sql
Hanserwei 7380f783ee feat(admin): implement category management functionality
- Added AddCategoryReqVO for category creation with validation
- Created AdminCategoryController with endpoints for add, list, delete and select operations
- Implemented AdminCategoryService interface and its methods
- Added Category entity with JPA annotations and logical delete support
- Created CategoryRepository extending JpaRepository with custom query methods
- Added SQL table creation script for t_category with indexes and constraints
- Implemented PageResponse utility for handling paginated results
- Added FindCategoryPageListReqVO and FindCategoryPageListRspVO for pagination
- Included DeleteCategoryReqVO for category deletion requests
- Updated Jackson configuration to ignore unknown properties
- Added base page query model and user info response VO
- Fixed typo in response code enum for user not exist error
2025-11-30 22:09:49 +08:00

98 lines
4.4 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ====================================================================================================================
-- ====================================================================================================================
-- 1. 创建一个函数,用于在数据更新时自动修改 update_time 字段
CREATE OR REPLACE FUNCTION set_update_time()
RETURNS TRIGGER AS
$$
BEGIN
NEW.update_time = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- 2. 创建表(使用 BOOLEAN 替代 SMALLINT for is_deleted
CREATE TABLE t_user
(
id BIGSERIAL PRIMARY KEY,
username VARCHAR(60) NOT NULL UNIQUE,
password VARCHAR(60) NOT NULL,
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
-- WITH TIME ZONE 是更严谨的选择
update_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
-- 使用 BOOLEAN 逻辑删除DEFAULT FALSE 对应 '0未删除'
is_deleted BOOLEAN NOT NULL DEFAULT FALSE
);
-- 3. 创建触发器,在每次 UPDATE 操作前调用函数
CREATE TRIGGER set_t_user_update_time
BEFORE UPDATE
ON t_user
FOR EACH ROW
EXECUTE FUNCTION set_update_time();
-- 添加注释
COMMENT ON TABLE t_user IS '用户表(优化版)';
COMMENT ON COLUMN t_user.is_deleted IS '逻辑删除FALSE未删除 TRUE已删除';
-- ====================================================================================================================
-- ====================================================================================================================
-- ====================================================================================================================
-- ====================================================================================================================
CREATE TABLE t_user_role
(
id BIGSERIAL PRIMARY KEY,
username VARCHAR(60) NOT NULL,
role_name VARCHAR(60) NOT NULL, -- 重命名为 role_name 避免关键字冲突
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_username ON t_user_role (username);
COMMENT ON COLUMN t_user_role.role_name IS '角色名称';
-- 为 t_user_role 表创建触发器
CREATE TRIGGER set_t_user_role_update_time
BEFORE UPDATE
ON t_user_role
FOR EACH ROW
EXECUTE FUNCTION set_update_time();
-- ====================================================================================================================
-- ====================================================================================================================
-- ====================================================================================================================
-- ====================================================================================================================
CREATE TABLE t_category
(
-- id对应 MySQL 的 bigint(20) unsigned NOT NULL AUTO_INCREMENT
id BIGSERIAL PRIMARY KEY,
-- 分类名称VARCHAR(60) NOT NULL DEFAULT '',同时是 UNIQUE 约束
"name" VARCHAR(60) NOT NULL DEFAULT '',
-- 创建时间
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
-- 最后一次更新时间
update_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
-- 逻辑删除标志位tinyint(2) NOT NULL DEFAULT '0',改为 BOOLEAN
is_deleted BOOLEAN NOT NULL DEFAULT FALSE,
-- UNIQUE KEY uk_name (`name`)
CONSTRAINT uk_name UNIQUE ("name")
);
-- 添加非唯一索引(对应 MySQL 的 KEY `idx_create_time`
CREATE INDEX idx_create_time ON t_category (create_time);
-- 可选:添加注释
COMMENT ON TABLE t_category IS '文章分类表';
COMMENT ON COLUMN t_category.id IS '分类id';
COMMENT ON COLUMN t_category.name IS '分类名称';
COMMENT ON COLUMN t_category.create_time IS '创建时间';
COMMENT ON COLUMN t_category.update_time IS '最后一次更新时间';
COMMENT ON COLUMN t_category.is_deleted IS '逻辑删除标志位FALSE未删除 TRUE已删除';
-- 为 t_category 表创建触发器
CREATE TRIGGER set_t_category_update_time
BEFORE UPDATE
ON t_category
FOR EACH ROW
EXECUTE FUNCTION set_update_time();
-- ====================================================================================================================
-- ====================================================================================================================