start using jooq
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 1m46s
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 1m46s
This commit is contained in:
parent
9cc8ad3873
commit
e19a55e8d3
60
Makefile
Normal file
60
Makefile
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# Makefile for rhythm-backend
|
||||||
|
# Uses Maven wrapper (./mvnw)
|
||||||
|
|
||||||
|
# Load .env if exists (for DB credentials, etc.)
|
||||||
|
ifneq ($(wildcard .env),)
|
||||||
|
include .env
|
||||||
|
export
|
||||||
|
endif
|
||||||
|
|
||||||
|
DB_HOST ?= localhost
|
||||||
|
DB_PORT ?= 5432
|
||||||
|
DB_NAME ?= rhythm
|
||||||
|
DB_USERNAME ?= postgres
|
||||||
|
DB_PASSWORD ?= postgres
|
||||||
|
|
||||||
|
.PHONY: help install migrate codegen setup build run clean test
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo "Available commands:"
|
||||||
|
@echo " make install - Install Maven wrapper"
|
||||||
|
@echo " make migrate - Run Flyway migrations"
|
||||||
|
@echo " make codegen - Generate jOOQ classes from DB schema"
|
||||||
|
@echo " make setup - Install wrapper + migrate + codegen (combined)"
|
||||||
|
@echo " make build - Compile the project"
|
||||||
|
@echo " make run - Run the application"
|
||||||
|
@echo " make clean - Clean build artifacts"
|
||||||
|
@echo " make test - Run tests"
|
||||||
|
|
||||||
|
install:
|
||||||
|
./mvnw -v || mvn -v wrapper:wrapper -Dmaven=${MAVEN_VERSION:-3.9.9}
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
./mvnw flyway:migrate \
|
||||||
|
-DDB_HOST=$(DB_HOST) \
|
||||||
|
-DDB_PORT=$(DB_PORT) \
|
||||||
|
-DDB_NAME=$(DB_NAME) \
|
||||||
|
-DDB_USERNAME=$(DB_USERNAME) \
|
||||||
|
-DDB_PASSWORD=$(DB_PASSWORD)
|
||||||
|
|
||||||
|
codegen:
|
||||||
|
./mvnw jooq-codegen:generate \
|
||||||
|
-DDB_HOST=$(DB_HOST) \
|
||||||
|
-DDB_PORT=$(DB_PORT) \
|
||||||
|
-DDB_NAME=$(DB_NAME) \
|
||||||
|
-DDB_USERNAME=$(DB_USERNAME) \
|
||||||
|
-DDB_PASSWORD=$(DB_PASSWORD)
|
||||||
|
|
||||||
|
setup: install migrate codegen
|
||||||
|
|
||||||
|
build:
|
||||||
|
./mvnw compile
|
||||||
|
|
||||||
|
run:
|
||||||
|
./mvnw spring-boot:run
|
||||||
|
|
||||||
|
clean:
|
||||||
|
./mvnw clean
|
||||||
|
|
||||||
|
test:
|
||||||
|
./mvnw test
|
||||||
79
pom.xml
79
pom.xml
@ -10,7 +10,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>dev.kanopo</groupId>
|
<groupId>dev.kanopo</groupId>
|
||||||
<artifactId>rhythm</artifactId>
|
<artifactId>rhythm</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.0-SNAPSHOT</version>
|
||||||
<name/>
|
<name/>
|
||||||
<description/>
|
<description/>
|
||||||
<url/>
|
<url/>
|
||||||
@ -36,16 +36,12 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-jooq</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-flyway</artifactId>
|
<artifactId>spring-boot-starter-flyway</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
@ -83,11 +79,7 @@
|
|||||||
<artifactId>spring-boot-starter-actuator-test</artifactId>
|
<artifactId>spring-boot-starter-actuator-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-flyway-test</artifactId>
|
<artifactId>spring-boot-starter-flyway-test</artifactId>
|
||||||
@ -95,7 +87,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-mail-test</artifactId>
|
<artifactId>spring-boot-starter-jooq-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -151,6 +143,25 @@
|
|||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>add-source</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>add-source</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<sources>
|
||||||
|
<source>${project.build.directory}/generated-sources/jooq</source>
|
||||||
|
</sources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
@ -163,6 +174,50 @@
|
|||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.flywaydb</groupId>
|
||||||
|
<artifactId>flyway-maven-plugin</artifactId>
|
||||||
|
<version>11.20.2</version>
|
||||||
|
<configuration>
|
||||||
|
<url>jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}</url>
|
||||||
|
<user>${DB_USERNAME}</user>
|
||||||
|
<password>${DB_PASSWORD}</password>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jooq</groupId>
|
||||||
|
<artifactId>jooq-codegen-maven</artifactId>
|
||||||
|
<version>${jooq.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>generate-jooq</id>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>generate</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<jdbc>
|
||||||
|
<driver>org.postgresql.Driver</driver>
|
||||||
|
<url>jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}</url>
|
||||||
|
<user>${DB_USERNAME}</user>
|
||||||
|
<password>${DB_PASSWORD}</password>
|
||||||
|
</jdbc>
|
||||||
|
<generator>
|
||||||
|
<database>
|
||||||
|
<name>org.jooq.meta.postgres.PostgresDatabase</name>
|
||||||
|
<inputSchema>public</inputSchema>
|
||||||
|
<includes>.*</includes>
|
||||||
|
<excludes>flyway_schema_history</excludes>
|
||||||
|
</database>
|
||||||
|
<target>
|
||||||
|
<packageName>dev.kanopo.rhythm.jooq</packageName>
|
||||||
|
<directory>${project.build.directory}/generated-sources/jooq</directory>
|
||||||
|
</target>
|
||||||
|
</generator>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -2,14 +2,12 @@ package dev.kanopo.rhythm;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableJpaAuditing
|
|
||||||
public class RhythmApplication {
|
public class RhythmApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(RhythmApplication.class, args);
|
SpringApplication.run(RhythmApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,38 +3,13 @@ package dev.kanopo.rhythm.db.model;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.PreUpdate;
|
|
||||||
import jakarta.persistence.Table;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "users")
|
|
||||||
public class User {
|
public class User {
|
||||||
@Id
|
private UUID id;
|
||||||
@GeneratedValue
|
private String email;
|
||||||
@Column(name = "id", updatable = false, nullable = false)
|
private String password;
|
||||||
private UUID id;
|
private Instant createdAt;
|
||||||
|
private Instant updatedAt;
|
||||||
@Column(nullable = false)
|
}
|
||||||
private String email;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Column(name = "created_at", nullable = false, updatable = false)
|
|
||||||
private Instant createdAt;
|
|
||||||
|
|
||||||
@Column(name = "updated_at", nullable = false)
|
|
||||||
private Instant updatedAt;
|
|
||||||
|
|
||||||
@PreUpdate
|
|
||||||
void onUpdate() {
|
|
||||||
this.updatedAt = Instant.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,11 +1,28 @@
|
|||||||
package dev.kanopo.rhythm.db.repository;
|
package dev.kanopo.rhythm.db.repository;
|
||||||
|
|
||||||
|
import static dev.kanopo.rhythm.jooq.tables.Users.USERS;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.springframework.data.repository.Repository;
|
import org.jooq.DSLContext;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import dev.kanopo.rhythm.db.model.User;
|
import dev.kanopo.rhythm.db.model.User;
|
||||||
|
|
||||||
public interface UserRepository extends Repository<User, UUID> {
|
@Repository
|
||||||
|
public class UserRepository {
|
||||||
|
|
||||||
|
private final DSLContext dsl;
|
||||||
|
|
||||||
|
public UserRepository(DSLContext dsl) {
|
||||||
|
this.dsl = dsl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<User> findById(UUID id) {
|
||||||
|
return dsl.selectFrom(USERS)
|
||||||
|
.where(USERS.ID.eq(id))
|
||||||
|
.fetchOptional()
|
||||||
|
.map(r -> r.into(User.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,18 +10,14 @@ spring:
|
|||||||
username: ${DB_USERNAME}
|
username: ${DB_USERNAME}
|
||||||
password: ${DB_PASSWORD}
|
password: ${DB_PASSWORD}
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
jpa:
|
|
||||||
hibernate:
|
|
||||||
ddl-auto: validate
|
|
||||||
open-in-view: false
|
|
||||||
properties:
|
|
||||||
hibernate:
|
|
||||||
dialect: org.hibernate.dialect.PostgreSQLDialect
|
|
||||||
|
|
||||||
flyway:
|
flyway:
|
||||||
enabled: true
|
enabled: true
|
||||||
baseline-on-migrate: true
|
baseline-on-migrate: true
|
||||||
|
|
||||||
|
jooq:
|
||||||
|
sql-dialect: POSTGRES
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: ${APP_PORT:8080}
|
port: ${APP_PORT:8080}
|
||||||
error:
|
error:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user