Skip to content

Refactor: UUID migration for database schema #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 21 (only for Java)
if: matrix.language == 'java'
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '21'

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand All @@ -57,6 +64,9 @@ jobs:

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Build with Maven (only for Java)
if: matrix.language =='java'

- name: Autobuild for JavaScript
if: matrix.language == 'javascript'
uses: github/codeql-action/autobuild@v3
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pull_request_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
types: [opened, edited]

permissions:
contents: write
pull-requests: write

jobs:
autofill_pr:
runs-on: ubuntu-latest
Expand Down
22 changes: 10 additions & 12 deletions cart-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,8 @@
</dependency>
<dependency>
<groupId>com.blubin</groupId>
<artifactId>user-service</artifactId>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.blubin</groupId>
<artifactId>product-service</artifactId>
<version>${revision}</version>
<artifactId>common-service</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand All @@ -65,10 +59,14 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3.5</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;

@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.blubin.commonservice",
"com.blubin.cartservice"})
public class CartServiceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.blubin.cartservice.model;

import com.blubin.userservice.model.SiteUser;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.util.UUID;

@Getter
@Setter
@Entity
@Table(name = "shopping_cart")
public class ShoppingCart {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cart_id", nullable = false)
private Integer id;
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "cart_id",updatable = false, nullable = false)
private UUID id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private SiteUser user;
@NotNull
@Column(name = "user_id")
private UUID user;

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.blubin.cartservice.model;

import com.blubin.productservice.model.ProductItem;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.util.UUID;

@Getter
@Setter
Expand All @@ -15,14 +18,10 @@ public class ShoppingCartItem {

@MapsId("cartId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "cart_id", nullable = false)
private ShoppingCart cart;

@MapsId("productItemId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "product_item_id", nullable = false)
private ProductItem productItem;

@Column(name = "quantity")
private Integer quantity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.hibernate.Hibernate;

import java.util.Objects;
import java.util.UUID;

@Getter
@Setter
Expand All @@ -16,11 +17,11 @@ public class ShoppingCartItemId implements java.io.Serializable {
private static final long serialVersionUID = -1478894238683425865L;
@NotNull
@Column(name = "cart_id", nullable = false)
private Integer cartId;
private UUID cartId;

@NotNull
@Column(name = "product_item_id", nullable = false)
private Integer productItemId;
private UUID productItemId;

@Override
public boolean equals(Object o) {
Expand Down
1 change: 0 additions & 1 deletion cart-service/src/main/resources/application.properties

This file was deleted.

5 changes: 4 additions & 1 deletion cart-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
server:
port: 8085

spring:
application:
name: user_service
name: cart_service
datasource:
url: jdbc:postgresql://localhost:5432/ecommerce
username: postgres
Expand Down
11 changes: 6 additions & 5 deletions common-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>common-service</artifactId>
<name>common-service</name>
<description>common-service</description>
<properties>
<java.version>21</java.version>
<revision>1.0-SNAPSHOT</revision>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -41,13 +41,14 @@

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.blubin.commonservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CommonServiceApplication {

public static void main(String[] args) {
SpringApplication.run(CommonServiceApplication.class, args);
}

}
//package com.blubin.commonservice;
//
//import org.springframework.boot.SpringApplication;
//import org.springframework.boot.autoconfigure.SpringBootApplication;
//
//@SpringBootApplication
//public class CommonServiceApplication {
//
// public static void main(String[] args) {
// SpringApplication.run(CommonServiceApplication.class, args);
// }
//
//}

This file was deleted.

53 changes: 42 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
version: "3.8"

services:
postgres:
image: postgres:15
container_name: postgres
hostname: ${POSTGRES_HOST}
restart: always
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
ports:
- "${POSTGRES_PORT}:${POSTGRES_PORT}"
networks:
- spring-cloud-network

pyadmin:
image: dpage/pgadmin4:2024-10-19-2
container_name: pyadmin
hostname: pyadmin
restart: always
environment:
- PGADMIN_DEFAULT_EMAIL
- PGADMIN_DEFAULT_PASSWORD
volumes:
- pgadmin:/var/lib/pgadmin
networks:
- spring-cloud-network

identity-service:
build:
context: .
dockerfile: ./identity-service/Dockerfile
build: ./identity-service
container_name: identity-service
image: identity-service:latest
ports:
- "8081:8080"
- "8080:8080"
restart: always
environment:
- SPRING_PROFILES_ACTIVE=prod
- SPRING_DATASOURCE_URL
depends_on:
- postgres
networks:
- spring-cloud-network

common-service:
build:
context: .
dockerfile: ./common-service/Dockerfile
build: ./common-service
container_name: common-service
image: common-service:latest
ports:
- "8082:8080"
- "8081:8081"
restart: always
environment:
- SPRING_PROFILES_ACTIVE=prod
- SPRING_DATASOURCE_URL
depends_on:
- postgres
networks:
- spring-cloud-network

networks:
spring-cloud-network:
driver: bridge
driver: bridge

volumes:
postgres:
pgadmin:
Loading