feat: 프로젝트 골격과 organization 스키마 추가
@7257a6c0cf578ffd329a3513ade423511ce35b90
+++ pom.xml
... | ... | @@ -0,0 +1,104 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | |
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 5 | + <modelVersion>4.0.0</modelVersion> | |
| 6 | + | |
| 7 | + <parent> | |
| 8 | + <groupId>org.springframework.boot</groupId> | |
| 9 | + <artifactId>spring-boot-starter-parent</artifactId> | |
| 10 | + <version>3.3.5</version> | |
| 11 | + <relativePath/> | |
| 12 | + </parent> | |
| 13 | + | |
| 14 | + <groupId>kr.itn</groupId> | |
| 15 | + <artifactId>itnhub</artifactId> | |
| 16 | + <version>0.1.0</version> | |
| 17 | + <name>itnhub</name> | |
| 18 | + | |
| 19 | + <properties> | |
| 20 | + <java.version>21</java.version> | |
| 21 | + <mybatis.version>3.0.3</mybatis.version> | |
| 22 | + <poi.version>5.3.0</poi.version> | |
| 23 | + <wiremock.version>3.9.1</wiremock.version> | |
| 24 | + </properties> | |
| 25 | + | |
| 26 | + <dependencies> | |
| 27 | + <dependency> | |
| 28 | + <groupId>org.springframework.boot</groupId> | |
| 29 | + <artifactId>spring-boot-starter-web</artifactId> | |
| 30 | + </dependency> | |
| 31 | + <dependency> | |
| 32 | + <groupId>org.springframework.boot</groupId> | |
| 33 | + <artifactId>spring-boot-starter-security</artifactId> | |
| 34 | + </dependency> | |
| 35 | + <dependency> | |
| 36 | + <groupId>org.springframework.boot</groupId> | |
| 37 | + <artifactId>spring-boot-starter-validation</artifactId> | |
| 38 | + </dependency> | |
| 39 | + <dependency> | |
| 40 | + <groupId>org.mybatis.spring.boot</groupId> | |
| 41 | + <artifactId>mybatis-spring-boot-starter</artifactId> | |
| 42 | + <version>${mybatis.version}</version> | |
| 43 | + </dependency> | |
| 44 | + <dependency> | |
| 45 | + <groupId>org.postgresql</groupId> | |
| 46 | + <artifactId>postgresql</artifactId> | |
| 47 | + <scope>runtime</scope> | |
| 48 | + </dependency> | |
| 49 | + <dependency> | |
| 50 | + <groupId>org.flywaydb</groupId> | |
| 51 | + <artifactId>flyway-core</artifactId> | |
| 52 | + </dependency> | |
| 53 | + <dependency> | |
| 54 | + <groupId>org.flywaydb</groupId> | |
| 55 | + <artifactId>flyway-database-postgresql</artifactId> | |
| 56 | + </dependency> | |
| 57 | + <dependency> | |
| 58 | + <groupId>org.apache.poi</groupId> | |
| 59 | + <artifactId>poi-ooxml</artifactId> | |
| 60 | + <version>${poi.version}</version> | |
| 61 | + </dependency> | |
| 62 | + | |
| 63 | + <dependency> | |
| 64 | + <groupId>org.springframework.boot</groupId> | |
| 65 | + <artifactId>spring-boot-starter-test</artifactId> | |
| 66 | + <scope>test</scope> | |
| 67 | + </dependency> | |
| 68 | + <dependency> | |
| 69 | + <groupId>org.springframework.security</groupId> | |
| 70 | + <artifactId>spring-security-test</artifactId> | |
| 71 | + <scope>test</scope> | |
| 72 | + </dependency> | |
| 73 | + <dependency> | |
| 74 | + <groupId>org.springframework.boot</groupId> | |
| 75 | + <artifactId>spring-boot-testcontainers</artifactId> | |
| 76 | + <scope>test</scope> | |
| 77 | + </dependency> | |
| 78 | + <dependency> | |
| 79 | + <groupId>org.testcontainers</groupId> | |
| 80 | + <artifactId>junit-jupiter</artifactId> | |
| 81 | + <scope>test</scope> | |
| 82 | + </dependency> | |
| 83 | + <dependency> | |
| 84 | + <groupId>org.testcontainers</groupId> | |
| 85 | + <artifactId>postgresql</artifactId> | |
| 86 | + <scope>test</scope> | |
| 87 | + </dependency> | |
| 88 | + <dependency> | |
| 89 | + <groupId>org.wiremock</groupId> | |
| 90 | + <artifactId>wiremock-standalone</artifactId> | |
| 91 | + <version>${wiremock.version}</version> | |
| 92 | + <scope>test</scope> | |
| 93 | + </dependency> | |
| 94 | + </dependencies> | |
| 95 | + | |
| 96 | + <build> | |
| 97 | + <plugins> | |
| 98 | + <plugin> | |
| 99 | + <groupId>org.springframework.boot</groupId> | |
| 100 | + <artifactId>spring-boot-maven-plugin</artifactId> | |
| 101 | + </plugin> | |
| 102 | + </plugins> | |
| 103 | + </build> | |
| 104 | +</project> |
+++ src/main/java/kr/itn/itnhub/ItnHubApplication.java
... | ... | @@ -0,0 +1,11 @@ |
| 1 | +package kr.itn.itnhub; | |
| 2 | + | |
| 3 | +import org.springframework.boot.SpringApplication; | |
| 4 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| 5 | + | |
| 6 | +@SpringBootApplication | |
| 7 | +public class ItnHubApplication { | |
| 8 | + public static void main(String[] args) { | |
| 9 | + SpringApplication.run(ItnHubApplication.class, args); | |
| 10 | + } | |
| 11 | +} |
+++ src/main/resources/application.yml
... | ... | @@ -0,0 +1,27 @@ |
| 1 | +spring: | |
| 2 | + application: | |
| 3 | + name: itnhub | |
| 4 | + datasource: | |
| 5 | + url: ${DB_URL} | |
| 6 | + username: ${DB_USERNAME} | |
| 7 | + password: ${DB_PASSWORD} | |
| 8 | + hikari: | |
| 9 | + schema: itnhub | |
| 10 | + flyway: | |
| 11 | + enabled: true | |
| 12 | + schemas: itnhub | |
| 13 | + default-schema: itnhub | |
| 14 | + create-schemas: true | |
| 15 | + servlet: | |
| 16 | + multipart: | |
| 17 | + max-file-size: 20MB | |
| 18 | + max-request-size: 20MB | |
| 19 | + | |
| 20 | +mybatis: | |
| 21 | + mapper-locations: classpath:mapper/*.xml | |
| 22 | + configuration: | |
| 23 | + map-underscore-to-camel-case: true | |
| 24 | + | |
| 25 | +logging: | |
| 26 | + level: | |
| 27 | + kr.itn.itnhub: INFO |
+++ src/main/resources/db/migration/V1__init.sql
... | ... | @@ -0,0 +1,18 @@ |
| 1 | +create table organization ( | |
| 2 | + id bigserial primary key, | |
| 3 | + org_no varchar(10) not null, | |
| 4 | + org_name varchar(200) not null, | |
| 5 | + channel_slug varchar(40) not null, | |
| 6 | + dept_name varchar(200), | |
| 7 | + manager_name varchar(100), | |
| 8 | + manager_title varchar(100), | |
| 9 | + manager_phone varchar(50), | |
| 10 | + manager_email varchar(200), | |
| 11 | + channel_id_mj varchar(40), | |
| 12 | + channel_id_law varchar(40), | |
| 13 | + created_at timestamptz not null default now(), | |
| 14 | + updated_at timestamptz not null default now(), | |
| 15 | + constraint uq_organization_no_name unique (org_no, org_name) | |
| 16 | +); | |
| 17 | + | |
| 18 | +create index ix_organization_org_no on organization (org_no); |
+++ src/test/java/kr/itn/itnhub/SchemaMigrationTest.java
... | ... | @@ -0,0 +1,55 @@ |
| 1 | +package kr.itn.itnhub; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Test; | |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | +import org.springframework.boot.test.context.SpringBootTest; | |
| 6 | +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | |
| 7 | +import org.springframework.jdbc.core.JdbcTemplate; | |
| 8 | +import org.springframework.test.context.DynamicPropertyRegistry; | |
| 9 | +import org.springframework.test.context.DynamicPropertySource; | |
| 10 | +import org.testcontainers.containers.PostgreSQLContainer; | |
| 11 | +import org.testcontainers.junit.jupiter.Container; | |
| 12 | +import org.testcontainers.junit.jupiter.Testcontainers; | |
| 13 | + | |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 15 | + | |
| 16 | +@SpringBootTest | |
| 17 | +@Testcontainers | |
| 18 | +class SchemaMigrationTest { | |
| 19 | + | |
| 20 | + @Container | |
| 21 | + @ServiceConnection | |
| 22 | + static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16"); | |
| 23 | + | |
| 24 | + @DynamicPropertySource | |
| 25 | + static void secrets(DynamicPropertyRegistry registry) { | |
| 26 | + registry.add("app.admin.username", () -> "admin"); | |
| 27 | + registry.add("app.admin.password", () -> "test-password"); | |
| 28 | + registry.add("mattermost.base-url", () -> "http://localhost:1"); | |
| 29 | + registry.add("mattermost.token", () -> "test-token"); | |
| 30 | + registry.add("mattermost.team-id", () -> "test-team"); | |
| 31 | + } | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + JdbcTemplate jdbc; | |
| 35 | + | |
| 36 | + @Test | |
| 37 | + void organization_테이블이_생성된다() { | |
| 38 | + Integer count = jdbc.queryForObject( | |
| 39 | + "select count(*) from information_schema.tables " | |
| 40 | + + "where table_schema = 'itnhub' and table_name = 'organization'", | |
| 41 | + Integer.class); | |
| 42 | + | |
| 43 | + assertThat(count).isEqualTo(1); | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Test | |
| 47 | + void 연번과_기관명_조합에_유니크_제약이_있다() { | |
| 48 | + jdbc.update("insert into organization (org_no, org_name, channel_slug) " | |
| 49 | + + "values ('008', '경찰청', '008')"); | |
| 50 | + | |
| 51 | + assertThat(jdbc.queryForObject( | |
| 52 | + "select count(*) from organization where org_no = '008'", Integer.class)) | |
| 53 | + .isEqualTo(1); | |
| 54 | + } | |
| 55 | +} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?