From 02a27624c2fc84264806ba4de8ca6d26781869d7 Mon Sep 17 00:00:00 2001 From: didar-bhuiyan Date: Thu, 7 Aug 2025 00:42:51 +0600 Subject: [PATCH 1/6] configure SQL-based DB initialization: disable ddl-auto and load schema/data scripts --- src/main/resources/application-local.properties | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index f770834..b55a6ae 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -4,7 +4,7 @@ logging.pattern.dateformat=yyyy-MM-dd'T'HH:mm:ss.SSSXXX logging.level.root=INFO ## custom logging.level.com.pondit.portfolio=debug - +server.address=0.0.0.0 # Database spring.h2.console.enabled=true @@ -13,8 +13,10 @@ spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password=password spring.jpa.database-platform=org.hibernate.dialect.H2Dialect -spring.jpa.hibernate.ddl-auto=update - +spring.jpa.hibernate.ddl-auto=none +spring.sql.init.mode=always +spring.sql.init.schema-locations=classpath:schema.sql +spring.sql.init.data-locations=classpath:data.sql spring.jpa.show-sql=false # Security From 4cb0752120d1a6f21dcf8fa91244f40da20c8f48 Mon Sep 17 00:00:00 2001 From: didar-bhuiyan Date: Thu, 7 Aug 2025 00:44:16 +0600 Subject: [PATCH 2/6] refine ID generation: specify GenerationType.IDENTITY in PostEntity --- .../com/pondit/portfolio/persistence/entity/PostEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java b/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java index b86cfc6..1a3c16f 100644 --- a/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java +++ b/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java @@ -12,7 +12,7 @@ }) public class PostEntity { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) @Setter private Long id; From e57734c91d151fe3ccadc933c552b02cf84c3a87 Mon Sep 17 00:00:00 2001 From: didar-bhuiyan Date: Thu, 7 Aug 2025 00:45:32 +0600 Subject: [PATCH 3/6] add schema.sql and data.sql to initialize post table and seed sample posts --- src/main/resources/data.sql | 10 ++++++++++ src/main/resources/schema.sql | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/resources/data.sql create mode 100644 src/main/resources/schema.sql diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 0000000..7407e8f --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,10 @@ +INSERT INTO post (title, content, slug, is_published, published_at, intro) VALUES + ('The Impact of Climate Change on Wildlife', + 'Climate change is profoundly affecting wildlife across the globe. Rising temperatures, shifting weather patterns, and altered habitats are forcing many species to adapt, migrate, or face the risk of extinction. Polar bears, coral reefs, and migratory birds are just a few examples of wildlife impacted by these environmental changes. Conservation efforts are increasingly focusing on mitigating these effects through habitat protection, climate action, and raising awareness about the interconnectedness of ecosystems. The survival of countless species depends on how effectively humanity addresses climate change in the coming decades.', + 'impact-of-climate-change-on-wildlife', TRUE, CURRENT_TIMESTAMP, + 'Examining how climate change is threatening wildlife and what can be done to protect vulnerable species.'), + + ('The Evolution of Digital Communication', + 'Digital communication has transformed how people connect, share ideas, and conduct business worldwide. From the invention of email and instant messaging to the rise of social media platforms, the way we communicate has become faster, more accessible, and often more visual. This evolution has bridged distances, enabling global collaboration and real-time interaction. However, it also presents challenges such as information overload, privacy concerns, and the spread of misinformation. Understanding the history and impact of digital communication is essential as society continues to navigate its benefits and pitfalls.', + 'the-evolution-of-digital-communication', TRUE, CURRENT_TIMESTAMP, + 'A comprehensive look at how digital communication has changed our world and the challenges it presents.'); diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 0000000..22e014e --- /dev/null +++ b/src/main/resources/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS post ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + title VARCHAR(255), + content CLOB, + slug VARCHAR(255) NOT NULL UNIQUE, + is_published BOOLEAN, + published_at TIMESTAMP, + intro VARCHAR(400) +); From a8157baeec7597691c2d5ec9797f19aba4720ffa Mon Sep 17 00:00:00 2001 From: didar-bhuiyan Date: Mon, 11 Aug 2025 23:59:21 +0600 Subject: [PATCH 4/6] remove unnecessary server address --- src/main/resources/application-local.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index b55a6ae..c153c0c 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -4,7 +4,7 @@ logging.pattern.dateformat=yyyy-MM-dd'T'HH:mm:ss.SSSXXX logging.level.root=INFO ## custom logging.level.com.pondit.portfolio=debug -server.address=0.0.0.0 + # Database spring.h2.console.enabled=true From 23628d86e7def028e4b0228c19a1fe002a0159a0 Mon Sep 17 00:00:00 2001 From: didar-bhuiyan Date: Tue, 12 Aug 2025 00:02:40 +0600 Subject: [PATCH 5/6] remove GenerationType.IDENTITY and revert to default @GeneratedValue --- .../com/pondit/portfolio/persistence/entity/PostEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java b/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java index 1a3c16f..b86cfc6 100644 --- a/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java +++ b/src/main/java/com/pondit/portfolio/persistence/entity/PostEntity.java @@ -12,7 +12,7 @@ }) public class PostEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue @Setter private Long id; From 028933953dbe870abf98aa207b34375d0e1151f7 Mon Sep 17 00:00:00 2001 From: didar-bhuiyan Date: Tue, 12 Aug 2025 00:05:51 +0600 Subject: [PATCH 6/6] add project and users tables to schema.sql alongside post table --- src/main/resources/schema.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 22e014e..efdd938 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -7,3 +7,15 @@ CREATE TABLE IF NOT EXISTS post ( published_at TIMESTAMP, intro VARCHAR(400) ); +CREATE TABLE IF NOT EXISTS project ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name VARCHAR(255), + description VARCHAR(255) +); +CREATE TABLE IF NOT EXISTS users ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + username VARCHAR(255), + password VARCHAR(255), + firstName VARCHAR(255), + lastName VARCHAR(255) +);