diff --git a/build.gradle b/build.gradle index 022161a..243d358 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,8 @@ dependencies { annotationProcessor "jakarta.persistence:jakarta.persistence-api" testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' + + implementation 'org.flywaydb:flyway-mysql' } tasks.named('test') { diff --git a/src/main/resources/db/migration/R__init.sql b/src/main/resources/db/migration/R__init.sql new file mode 100644 index 0000000..542ec37 --- /dev/null +++ b/src/main/resources/db/migration/R__init.sql @@ -0,0 +1,25 @@ +-- -- `member` 테이블에 대한 더미 데이터 +INSERT INTO member (id, `name`, member_type, phone, birthday, profile, email, simple_password, `state`, inactive_date, card_state, bank_member_id, created_at, updated_at, `role`, social) +VALUES + (1, '강현우', 'PARENT', '010-1234-5678', '1985-01-05', 'DADAPING', 'wekids1@naver.com', '{bcrypt}$2a$10$H4hK3cIdFrHEk7dSiLF/KeBZcp99zsX2qCb6PlfupNcxZUPh3Ev7O', 'ACTIVE', null, 'NONE', 1, '2024-01-01 00:00:00', '2024-01-01 00:00:00', 'ROLE_PARENT', 'naver'), + (2, '구자빈', 'CHILD', '010-2345-6789', '2018-03-03', 'CHACHAPING', 'wekids2@naver.com', '{bcrypt}$2a$10$A.yrgthceIagp5pCoPNbvug3sSpLBBBZWGZk/A8Wr4EpSO4JDvOr6', 'ACTIVE', null, 'CREATED', 2, '2024-01-01 00:00:00', '2024-01-01 00:00:00', 'ROLE_CHILD', 'naver'), + (3, '최윤정', 'CHILD', '010-3456-6789', '2019-05-02', 'DADAPING', 'wekids3@naver.com', '{bcrypt}$2a$10$oVd5oA3bSa4zh8JSiCLyeeVaRId17Lm.ay5ALzu9kGJD8wpNtlody', 'ACTIVE', null, 'NONE', null, '2024-01-01 00:00:00', '2024-01-01 00:00:00', 'ROLE_CHILD', 'naver'); + +INSERT INTO account (id, account_number, balance, password, `state`, inactive_date, member_id, created_at, updated_at) +VALUES + (1, '1002-913-023908', 2800000, NULL, 'ACTIVE', NULL, 1, '2024-01-01 00:00:00', '2024-12-09 00:00:00'), -- 강현우 + (2, '1002-913-023909', 400000, '5678', 'ACTIVE', NULL, 2, '2024-01-01 00:00:00', '2024-12-09 00:00:00'); -- 구자빈 + +INSERT INTO card (id, card_number, valid_thru, cvc, member_name, password, card_name, `state`, inactive_date, new_date, account_id, created_at, updated_at) +VALUES + (1, '5159-5432-1098-7654', '2026-12-31', '456', '구자빈', '5678', '자빈핑', 'ACTIVE', NULL, '2024-01-01 00:00:00', 2, '2024-01-01 00:00:00', '2024-01-01 00:00:00'); + +INSERT INTO design (member_id, color, `character`, account_id, card_id) +VALUES + (1, 'BLUE', 'DADAPING', 1, NULL), -- 강현우 + (2, 'GREEN', 'CHACHAPING', 2, 1); -- 구자빈 + +INSERT INTO parent_child (`parent_id`, `child_id`, created_at, updated_at) +VALUES + (1, 2, '2024-01-01 00:00:00', '2024-01-01 00:00:00'), + (1, 3, '2024-01-01 00:00:00', '2024-01-01 00:00:00'); \ No newline at end of file diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql new file mode 100644 index 0000000..6ad8dd2 --- /dev/null +++ b/src/main/resources/db/migration/V1__init.sql @@ -0,0 +1,146 @@ +CREATE TABLE IF NOT EXISTS `member` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `birthday` DATE NOT NULL, + `bank_member_id` BIGINT, + `created_at` DATETIME(6) NOT NULL, + `inactive_date` DATETIME(6), + `updated_at` DATETIME(6) NOT NULL, + `name` VARCHAR(20) NOT NULL, + `phone` VARCHAR(20) NOT NULL, + `member_type` VARCHAR(31) NOT NULL, + `email` VARCHAR(255) NOT NULL, + `role` VARCHAR(255), + `simple_password` VARCHAR(255), + `social` VARCHAR(255) NOT NULL, + `card_state` ENUM('CREATED', 'NONE', 'READY') NOT NULL, + `profile` ENUM('CHACHAPING', 'DADAPING', 'GOGOPING', 'HAPPYING', 'HEARTSPRING', 'LALAPING'), + `state` ENUM('ACTIVE', 'LEAVE', 'SLEEP') NOT NULL, + PRIMARY KEY (`id`) +) +ENGINE=InnoDB +AUTO_INCREMENT=1 +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `mission` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `amount` DECIMAL(38,2) NOT NULL, + `deadline` DATE NOT NULL, + `child_id` BIGINT NOT NULL, + `created_at` DATETIME(6) NOT NULL, + `parent_id` BIGINT NOT NULL, + `updated_at` DATETIME(6) NOT NULL, + `image` VARCHAR(255), + `memo` VARCHAR(255), + `title` VARCHAR(255) NOT NULL, + `category` ENUM ('ETC','HOUSE_WORK','LIFESTYLE_HABITS','SELF_DEVELOPMENT') NOT NULL, + `content` TEXT, + `state` ENUM ('ACCEPT','CANCEL','NEW','OUTDATED','SUBMIT') NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `FK_mission_child` FOREIGN KEY (`child_id`) REFERENCES `member` (`id`), + CONSTRAINT `FK_mission_parent` FOREIGN KEY (`parent_id`) REFERENCES `member` (`id`) +) ENGINE=InnoDB +AUTO_INCREMENT=1 +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `parent_child` ( + `child_id` BIGINT NOT NULL, + `created_at` DATETIME(6) NOT NULL, + `parent_id` BIGINT NOT NULL, + `updated_at` DATETIME(6) NOT NULL, + PRIMARY KEY (`child_id`, `parent_id`), + CONSTRAINT `FK_parent_child_child` FOREIGN KEY (`child_id`) REFERENCES `member` (`id`), + CONSTRAINT `FK_parent_child_parent` FOREIGN KEY (`parent_id`) REFERENCES `member` (`id`) +) ENGINE=InnoDB +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `account` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `balance` DECIMAL(20,2) NOT NULL, + `created_at` DATETIME(6) NOT NULL, + `inactive_date` DATETIME(6), + `member_id` BIGINT NOT NULL, + `updated_at` DATETIME(6) NOT NULL, + `account_number` VARCHAR(50) NOT NULL, + `password` VARCHAR(255), + `state` ENUM ('ACTIVE','INACTIVE') NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `FK_account_member` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`) +) ENGINE=InnoDB +AUTO_INCREMENT=1 +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `account_transaction` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `amount` DECIMAL(20,2) NOT NULL, + `balance` DECIMAL(20,2) NOT NULL, + `account_id` BIGINT NOT NULL, + `created_at` DATETIME(6) NOT NULL, + `memo` VARCHAR(255), + `receiver` VARCHAR(255) NOT NULL, + `sender` VARCHAR(255) NOT NULL, + `title` VARCHAR(255) NOT NULL, + `type` ENUM ('DEPOSIT','WITHDRAWAL') NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `FK_transaction_account` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`) +) ENGINE=InnoDB +AUTO_INCREMENT=1 +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `alarm` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `is_checked` BIT NOT NULL, + `created_at` DATETIME(6) NOT NULL, + `member_id` BIGINT NOT NULL, + `target_id` BIGINT, + `updated_at` DATETIME(6) NOT NULL, + `target_state` VARCHAR(255), + `type` ENUM ('CARD','MISSION') NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `FK_alarm_member` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`) +) ENGINE=InnoDB +AUTO_INCREMENT=1 +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `card` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `valid_thru` DATE NOT NULL, + `account_id` BIGINT NOT NULL, + `created_at` DATETIME(6) NOT NULL, + `inactive_date` DATETIME(6), + `new_date` DATETIME(6) NOT NULL, + `updated_at` DATETIME(6) NOT NULL, + `card_name` VARCHAR(255) NOT NULL, + `card_number` VARCHAR(255) NOT NULL, + `cvc` VARCHAR(255) NOT NULL, + `member_name` VARCHAR(255) NOT NULL, + `password` VARCHAR(255) NOT NULL, + `state` ENUM ('ACTIVE','INACTIVE') NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `FK_card_account` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`), + CONSTRAINT `UK_card_account` UNIQUE (`account_id`) +) ENGINE=InnoDB +AUTO_INCREMENT=1 +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE IF NOT EXISTS `design` ( + `account_id` BIGINT, + `card_id` BIGINT, + `member_id` BIGINT NOT NULL, + `character` ENUM ('CHACHAPING','DADAPING','GOGOPING','HAPPYING','HEARTSPRING','LALAPING') NOT NULL, + `color` ENUM ('BLUE','GREEN','PINK1','PINK2','PURPLE','YELLOW') NOT NULL, + PRIMARY KEY (`member_id`), + CONSTRAINT `FK_design_account` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`), + CONSTRAINT `FK_design_card` FOREIGN KEY (`card_id`) REFERENCES `card` (`id`), + CONSTRAINT `FK_design_member` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`), + CONSTRAINT `UK_design_account` UNIQUE (`account_id`), + CONSTRAINT `UK_design_card` UNIQUE (`card_id`) +) ENGINE=InnoDB +DEFAULT CHARSET=utf8mb4 +COLLATE=utf8mb4_0900_ai_ci;