Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
pull_request:
branches: [ "develop", "main" ]
types: [ opened, synchronize, reopened, ready_for_review ]
workflow_dispatch: {}

permissions:
contents: read
checks: write
pull-requests: write
issues: write

concurrency:
group: pr-ci-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with: { distribution: temurin, java-version: 17 }
- uses: gradle/actions/setup-gradle@v3
if: ${{ !env.ACT }}
with:
cache-read-only: ${{ github.event_name == 'pull_request' }}
gradle-home-cache-cleanup: true

- name: Create dummy .env for CI
working-directory: gdgoc
run: echo "# ci dummy" > .env

- name: Gradle build (skip tests)
id: assemble
working-directory: gdgoc
env: { GRADLE_OPTS: "-Dorg.gradle.vfs.watch=false" }
run: |
chmod +x ./gradlew
./gradlew build -x test --no-daemon --stacktrace --info --no-watch-fs | tee ../build.log
- name: Gradle test (H2 in-memory)
id: test
working-directory: gdgoc
continue-on-error: true
env:
GRADLE_OPTS: "-Dorg.gradle.vfs.watch=false"
SPRING_PROFILES_ACTIVE: test
SPRING_DATASOURCE_URL: jdbc:h2:mem:ci;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=TRUE
SPRING_DATASOURCE_USERNAME: sa
SPRING_DATASOURCE_PASSWORD: ""
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.h2.Driver
SPRING_JPA_DATABASE_PLATFORM: org.hibernate.dialect.H2Dialect
SPRING_JPA_HIBERNATE_DDL_AUTO: create-drop
run: ./gradlew test --no-daemon --stacktrace --info --no-watch-fs | tee ../test.log
5 changes: 5 additions & 0 deletions gdgoc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ configurations {
}
}

tasks.test {
systemProperty "spring.profiles.active", "test"
}


repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DO $$
DECLARE r record;
BEGIN
FOR r IN
SELECT conname
FROM pg_constraint c
JOIN pg_class t ON t.oid = c.conrelid
JOIN pg_namespace n ON n.oid = t.relnamespace
WHERE t.relname = 'users'
AND n.nspname = 'public'
AND c.contype = 'c'
AND pg_get_constraintdef(c.oid) ILIKE '%user_role%' -- user_role 관련 CHECK
LOOP
EXECUTE format('ALTER TABLE public.users DROP CONSTRAINT %I', r.conname);
END LOOP;
END $$;

ALTER TABLE public.users ALTER COLUMN user_role DROP DEFAULT;

ALTER TABLE public.users
ALTER COLUMN user_role TYPE varchar(32)
USING user_role::text;


UPDATE public.users
SET user_role = CASE user_role
WHEN '0' THEN 'GUEST'
WHEN '1' THEN 'MEMBER'
WHEN '2' THEN 'ADMIN'
ELSE user_role
END;

-- 5) 새 디폴트/체크 제약조건 설정
ALTER TABLE public.users ALTER COLUMN user_role SET DEFAULT 'GUEST';

ALTER TABLE public.users
ADD CONSTRAINT users_user_role_check
CHECK (user_role IN ('GUEST','MEMBER','ADMIN'));
2 changes: 2 additions & 0 deletions gdgoc/src/main/java/inha/gdgoc/config/DotenvLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import io.github.cdimascio.dotenv.Dotenv;
import jakarta.annotation.PostConstruct;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Profile("!test")
@Component
public class DotenvLoader {

Expand Down
3 changes: 3 additions & 0 deletions gdgoc/src/main/java/inha/gdgoc/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand Down Expand Up @@ -58,6 +60,7 @@ public class User extends BaseEntity {
@Column(name = "password", nullable = false)
private String password;

@Enumerated(EnumType.STRING)
@Column(name = "user_role", nullable = false)
private UserRole userRole;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

@Getter
public enum UserRole {
GUEST("Guest"),
MEMBER("Member"),
GUEST("GUEST"),
MEMBER("MEMBER"),
ADMIN("ADMIN");

private final String role;
Expand Down
4 changes: 3 additions & 1 deletion gdgoc/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ spring:
jpa:
database: postgresql
hibernate:
ddl-auto: update
ddl-auto: none
properties:
hibernate:
default_batch_fetch_size: 100
jdbc:
time_zone: Asia/Seoul
flyway:
enabled: true
mail:
host: smtp.gmail.com
port: 587
Expand Down
4 changes: 3 additions & 1 deletion gdgoc/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ spring:
time_zone: Asia/Seoul
show-sql: true
database-platform: org.hibernate.dialect.PostgreSQLDialect
flyway:
enabled: true
mail:
host: smtp.gmail.com
port: 587
Expand All @@ -38,7 +40,7 @@ spring:
logging:
level:
org.hibernate.SQL: debug
org.hibername.type: trace
org.hibernate.type: trace


google:
Expand Down
2 changes: 2 additions & 0 deletions gdgoc/src/test/java/inha/gdgoc/GdgocApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles("test")
@SpringBootTest
class GdgocApplicationTests {

Expand Down
69 changes: 69 additions & 0 deletions gdgoc/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
server:
forward-headers-strategy: none

spring:
jackson:
time-zone: Asia/Seoul

datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:gdgoc-test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=TRUE
username: sa
password:

servlet:
multipart:
max-file-size: 10MB
max-request-size: 12MB

jpa:
database: h2
hibernate:
ddl-auto: create-drop
properties:
hibernate:
default_batch_fetch_size: 100
format_sql: true
show_sql: false
time_zone: Asia/Seoul
database-platform: org.hibernate.dialect.H2Dialect
show-sql: false

mail:
host: localhost
port: 2525
username: test
password: test
properties:
mail:
smtp:
auth: false
starttls:
enable: false
main:
allow-bean-definition-overriding: true

logging:
level:
org.hibernate.SQL: warn
org.hibernate.type: warn

google:
client-id: test-client-id
client-secret: test-client-secret
redirect-uri: http://localhost/redirect

jwt:
googleIssuer: test-google-issuer
selfIssuer: test-self-issuer
secretKey: MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=

cloud:
aws:
credentials:
access-key: test
secret-key: test
region:
static: ap-northeast-2
s3:
bucket: test-bucket
Loading