- parent_id 추가(CREATE + ALTER IF NOT EXISTS 멱등 마이그레이션) - 도메인/DTO/매퍼에 parentId 노출, 2단계 검증(대분류 아래만 소분류) - 자식 있는 대분류는 소분류화·삭제 차단(countChildren) - 통계/예산/내역은 소분류 이름 기준 그대로(무변경) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -104,12 +104,16 @@ CREATE TABLE IF NOT EXISTS account_category (
|
||||
member_id BIGINT NOT NULL COMMENT '소유자 member.id',
|
||||
type VARCHAR(10) NOT NULL COMMENT 'INCOME / EXPENSE',
|
||||
name VARCHAR(50) NOT NULL,
|
||||
parent_id BIGINT NULL COMMENT '대분류 id(account_category.id). NULL=대분류, 값=소분류',
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_category_member_type_name (member_id, type, name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 대/소분류 계층 추가(기존 DB 마이그레이션) — 소분류 이름은 그대로, parent_id 만 부여
|
||||
ALTER TABLE account_category ADD COLUMN IF NOT EXISTS parent_id BIGINT NULL COMMENT '대분류 id. NULL=대분류, 값=소분류';
|
||||
|
||||
-- 예산 (사용자별, 카테고리별)
|
||||
-- fixed=1(고정): base_unit/base_amount 로 일수기준 환산 / fixed=0(비고정): daily/weekly/monthly/yearly 직접
|
||||
CREATE TABLE IF NOT EXISTS budget (
|
||||
|
||||
@@ -8,23 +8,29 @@
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="parentId" column="parent_id"/>
|
||||
<result property="sortOrder" column="sort_order"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findByMember" parameterType="long" resultMap="categoryResultMap">
|
||||
SELECT id, member_id, type, name, sort_order, created_at
|
||||
SELECT id, member_id, type, name, parent_id, sort_order, created_at
|
||||
FROM account_category
|
||||
WHERE member_id = #{memberId}
|
||||
ORDER BY type, sort_order, name
|
||||
</select>
|
||||
|
||||
<select id="findByIdAndMember" resultMap="categoryResultMap">
|
||||
SELECT id, member_id, type, name, sort_order, created_at
|
||||
SELECT id, member_id, type, name, parent_id, sort_order, created_at
|
||||
FROM account_category
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</select>
|
||||
|
||||
<select id="countChildren" resultType="int">
|
||||
SELECT COUNT(*) FROM account_category
|
||||
WHERE member_id = #{memberId} AND parent_id = #{parentId}
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*) FROM account_category
|
||||
WHERE member_id = #{memberId} AND type = #{type} AND name = #{name}
|
||||
@@ -33,17 +39,17 @@
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.account.domain.AccountCategory"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO account_category (member_id, type, name, sort_order, created_at)
|
||||
VALUES (#{memberId}, #{type}, #{name}, #{sortOrder}, NOW())
|
||||
INSERT INTO account_category (member_id, type, name, parent_id, sort_order, created_at)
|
||||
VALUES (#{memberId}, #{type}, #{name}, #{parentId}, #{sortOrder}, NOW())
|
||||
</insert>
|
||||
|
||||
<insert id="insertIgnore" parameterType="com.sb.web.account.domain.AccountCategory">
|
||||
INSERT IGNORE INTO account_category (member_id, type, name, sort_order, created_at)
|
||||
VALUES (#{memberId}, #{type}, #{name}, 0, NOW())
|
||||
INSERT IGNORE INTO account_category (member_id, type, name, parent_id, sort_order, created_at)
|
||||
VALUES (#{memberId}, #{type}, #{name}, #{parentId}, 0, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.sb.web.account.domain.AccountCategory">
|
||||
UPDATE account_category SET name = #{name}
|
||||
UPDATE account_category SET name = #{name}, parent_id = #{parentId}
|
||||
WHERE id = #{id} AND member_id = #{memberId}
|
||||
</update>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user