#24 simple sns: db settings(postgresql)

This commit is contained in:
haerong22
2022-10-19 00:37:06 +09:00
parent f86f895fea
commit b7aee85b9b
7 changed files with 81 additions and 10 deletions

View File

@@ -53,8 +53,8 @@ task cleanFrontEnd(type: Delete) {
delete "$projectDir/front-end/static", "$projectDir/front-end/node_modules"
}
npmBuild.dependsOn npmInstall
copyFrontEnd.dependsOn npmBuild
compileJava.dependsOn copyFrontEnd
clean.dependsOn cleanFrontEnd
//npmBuild.dependsOn npmInstall
//copyFrontEnd.dependsOn npmBuild
//compileJava.dependsOn copyFrontEnd
//
//clean.dependsOn cleanFrontEnd

View File

@@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@SpringBootApplication
public class SnsApplication {
public static void main(String[] args) {

View File

@@ -0,0 +1,45 @@
package com.example.sns.config;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.springframework.util.StringUtils;
public class ImprovedNamingStrategy implements PhysicalNamingStrategy {
@Override
public Identifier toPhysicalCatalogName(Identifier identifier, JdbcEnvironment jdbcEnv) {
return convert(identifier);
}
@Override
public Identifier toPhysicalColumnName(Identifier identifier, JdbcEnvironment jdbcEnv) {
return convert(identifier);
}
@Override
public Identifier toPhysicalSchemaName(Identifier identifier, JdbcEnvironment jdbcEnv) {
return convert(identifier);
}
@Override
public Identifier toPhysicalSequenceName(Identifier identifier, JdbcEnvironment jdbcEnv) {
return convert(identifier);
}
@Override
public Identifier toPhysicalTableName(Identifier identifier, JdbcEnvironment jdbcEnv) {
return convert(identifier);
}
private Identifier convert(Identifier identifier) {
if (identifier == null || StringUtils.isEmpty(identifier.getText())) {
return identifier;
}
String regex = "([a-z])([A-Z])";
String replacement = "$1_$2";
String newName = identifier.getText().replaceAll(regex, replacement).toLowerCase();
return Identifier.toIdentifier(newName);
}
}

View File

@@ -3,7 +3,9 @@ package com.example.sns.controller.response;
import com.example.sns.model.User;
import com.example.sns.model.UserRole;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class UserJoinResponse {

View File

@@ -11,9 +11,9 @@ import java.sql.Timestamp;
import java.time.Instant;
@Entity
@Table(name = "\"user\"")
@Table(name = "users")
@Getter @Setter
@SQLDelete(sql = "UPDATE \"user\" SET deleted_at = NOW() where id=?")
@SQLDelete(sql = "UPDATE users SET deleted_at = NOW() where id=?")
@Where(clause = "deleted_at IS NULL")
public class UserEntity {
@@ -25,10 +25,12 @@ public class UserEntity {
private String password;
@Enumerated(EnumType.STRING)
private UserRole role;
private UserRole role = UserRole.USER;
private Timestamp registeredAt;
private Timestamp updatedAt;
@Column(name = "deleted_at")
private Timestamp deletedAt;
@PrePersist

View File

@@ -0,0 +1,23 @@
spring:
jpa:
database: postgresql
hibernate:
naming:
physical-strategy: com.example.sns.config.ImprovedNamingStrategy
dialect: org.hibernate.dialect.PostgreSQLDialect
ddl-auto: update
properties:
hibernate:
format_sql: true
show-sql: true
datasource:
hikari:
maximum-pool-size: 4
url: jdbc:postgresql://ec2-44-209-24-62.compute-1.amazonaws.com/daipn3u0kdtqj
username: xckqpuxwsicvud
password: bc61f9c95d489227fe1a29eba14d2547c7185d449f081ef49f964b9d6bd1f110
platform: postgres
driver-class-name: org.postgresql.Driver