Skip to content

Commit

Permalink
🌱 implement initial data seeding with SQL scripts instead of DbSeeder…
Browse files Browse the repository at this point in the history
… classes
  • Loading branch information
Adnane Miliari committed Nov 27, 2024
1 parent bb3f9d3 commit 1127bed
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 331 deletions.
6 changes: 6 additions & 0 deletions common/src/main/resources/shared-application-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ spring:
format_sql: true
show-sql: true
open-in-view: false
defer-datasource-initialization: true
sql:
init:
mode: always
data-locations: classpath*:db/data.sql
platform: postgresql
rabbitmq:
addresses: localhost:5672

Expand Down
5 changes: 5 additions & 0 deletions common/src/main/resources/shared-application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ spring:
password: password
rabbitmq:
addresses: rabbitmq:5672
sql:
init:
mode: always
data-locations: classpath*:db/data.sql
platform: postgresql

eureka:
client:
Expand Down
19 changes: 13 additions & 6 deletions common/src/main/resources/shared-application-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ management:

spring:
datasource:
url: jdbc:postgresql://demo-microservices.csetxdk14qax.us-east-1.rds.amazonaws.com:5432/${spring.application.name}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
url: jdbc:postgresql://postgres:5432/${spring.application.name}
username: miliariadnane
password: password
rabbitmq:
addresses: rabbitmq:5672
jpa:
hibernate:
ddl-auto: update
sql:
init:
mode: always
data-locations: classpath*:db/data.sql
platform: postgresql

eureka:
client:
service-url:
defaultZone: http://eureka-server:8761/eureka
enabled: false
18 changes: 9 additions & 9 deletions common/src/main/resources/shared-application-kube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ management:

spring:
datasource:
url: jdbc:postgresql://postgres:5432/${spring.application.name}
username: miliariadnane
password: password
url: jdbc:postgresql://demo-microservices.csetxdk14qax.us-east-1.rds.amazonaws.com:5432/${spring.application.name}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
rabbitmq:
addresses: rabbitmq:5672

eureka:
client:
service-url:
defaultZone: http://eureka-server:8761/eureka
enabled: false
jpa:
hibernate:
ddl-auto: update
sql:
init:
mode: never
22 changes: 0 additions & 22 deletions customer/src/main/java/dev/nano/customer/CustomerDbSeeder.java

This file was deleted.

8 changes: 8 additions & 0 deletions customer/src/main/resources/db/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INSERT INTO customer (id, name, email, phone, address)
VALUES (nextval('customer_sequence'), 'John Smith', '[email protected]', '+1234567890', '123 Main St, New York, NY'),
(nextval('customer_sequence'), 'Emma Wilson', '[email protected]', '+1987654321',
'456 Park Ave, London, UK'),
(nextval('customer_sequence'), 'Mohammed Ali', '[email protected]', '+212661234567',
'Marina Street, Casablanca, Morocco'),
(nextval('customer_sequence'), 'Sarah Chen', '[email protected]', '+8613912345678',
'789 Nanjing Road, Shanghai, China');

This file was deleted.

63 changes: 0 additions & 63 deletions notification/src/main/resources/application-docker.yml

This file was deleted.

55 changes: 0 additions & 55 deletions notification/src/main/resources/application-eks.yml

This file was deleted.

66 changes: 0 additions & 66 deletions notification/src/main/resources/application-kube.yml

This file was deleted.

11 changes: 11 additions & 0 deletions notification/src/main/resources/db/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
INSERT INTO notification (id, customer_id, customer_name, customer_email, sender, message, sent_at)
VALUES (nextval('notification_sequence'), 1, 'John Smith', '[email protected]', 'NanoShop',
'Your order #1 has been confirmed', CURRENT_TIMESTAMP),
(nextval('notification_sequence'), 1, 'John Smith', '[email protected]', 'NanoShop',
'Your payment for order #1 has been processed', CURRENT_TIMESTAMP),
(nextval('notification_sequence'), 2, 'Emma Wilson', '[email protected]', 'NanoShop',
'Your order #3 has been shipped', CURRENT_TIMESTAMP),
(nextval('notification_sequence'), 3, 'Mohammed Ali', '[email protected]', 'NanoShop',
'Payment reminder for order #4', CURRENT_TIMESTAMP),
(nextval('notification_sequence'), 4, 'Sarah Chen', '[email protected]', 'NanoShop',
'Thank you for your purchase! Order #5 confirmed', CURRENT_TIMESTAMP);
23 changes: 0 additions & 23 deletions order/src/main/java/dev/nano/order/OrderDbSeeder.java

This file was deleted.

5 changes: 4 additions & 1 deletion order/src/main/java/dev/nano/order/OrderEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
@AllArgsConstructor @NoArgsConstructor
@ToString @SuperBuilder
@Entity(name = "Order")
@Table(name = "orders")
@Table(
name = "\"order\"",
schema = "public"
)
public class OrderEntity {

@Id
Expand Down
6 changes: 6 additions & 0 deletions order/src/main/resources/db/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INSERT INTO "order" (id, customer_id, product_id, amount, create_at)
VALUES (nextval('order_sequence'), 1, 1, 2, CURRENT_TIMESTAMP),
(nextval('order_sequence'), 1, 3, 1, CURRENT_TIMESTAMP),
(nextval('order_sequence'), 2, 2, 3, CURRENT_TIMESTAMP),
(nextval('order_sequence'), 3, 4, 1, CURRENT_TIMESTAMP),
(nextval('order_sequence'), 4, 1, 2, CURRENT_TIMESTAMP);
Loading

0 comments on commit 1127bed

Please sign in to comment.