From c567cf766d34e163b75e66ab1686aaaeb299911e Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 21:59:55 +0530 Subject: [PATCH 1/4] Postgres integration --- build.gradle | 4 ++ docker-compose.yaml | 21 ++++++++++- .../resources/application-local.properties | 9 ++++- src/main/resources/application.properties | 13 ++++++- src/main/resources/schema.sql | 37 +++++++++++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/schema.sql diff --git a/build.gradle b/build.gradle index bfc0540..2c09e0d 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,10 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + runtimeOnly 'org.postgresql:postgresql' + implementation 'org.hibernate.validator:hibernate-validator' } tasks.named('test') { diff --git a/docker-compose.yaml b/docker-compose.yaml index b014137..772008b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,6 +12,23 @@ services: - OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} - OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} - HOST_PORT=${HOST_PORT} + - POSTGRES_USER=${POSTGRES_USERNAME} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} env_file: - - stack.env - restart: unless-stopped \ No newline at end of file + - .env + restart: unless-stopped + postgres: + image: postgres:15 + container_name: cftunnel-db + environment: + POSTGRES_DB: cftunnel + POSTGRES_USER: ${POSTGRES_USERNAME} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + restart: unless-stopped + ports: + - "5432:5432" + volumes: + - pgdata:/var/lib/postgresql/data + +volumes: + pgdata: {} \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 9001ed2..556b2d1 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1 +1,8 @@ -api.corsResolveUrl=http://localhost:8080 \ No newline at end of file +api.corsResolveUrl=http://localhost:8080 + +management.health.db.enabled=true +management.endpoints.web.exposure.include=health +management.endpoint.health.show-details=always + +logging.level.org.hibernate.SQL=DEBUG +debug=true diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4774989..e6d31e7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -16,4 +16,15 @@ spring.security.oauth2.client.provider.cftunnels.authorization-uri=https://auth. spring.security.oauth2.client.provider.cftunnels.token-uri=https://auth.hithomelabs.com/application/o/token/ spring.security.oauth2.client.provider.cftunnels.user-info-uri=https://auth.hithomelabs.com/application/o/userinfo/ spring.security.oauth2.client.provider.cftunnels.jwk-set-uri=https://auth.hithomelabs.com/application/o/cftunnels/jwks/ -spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ \ No newline at end of file +spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ + +spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel +spring.datasource.username=${POSTGRES_USERNAME} +spring.datasource.password=${POSTGRES_PASSWORD} +spring.datasource.driver-class-name=org.postgresql.Driver +spring.sql.init.mode=always + +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 0000000..1fa876d --- /dev/null +++ b/src/main/resources/schema.sql @@ -0,0 +1,37 @@ +-- schema.sql + +-- Roles table +CREATE TABLE IF NOT EXISTS roles ( + role_id SERIAL PRIMARY KEY, + role_name VARCHAR(50) UNIQUE NOT NULL +); + +-- Users table +CREATE TABLE IF NOT EXISTS users ( + user_id SERIAL PRIMARY KEY, + user_name VARCHAR(100) NOT NULL, + password VARCHAR(255) NOT NULL +); + +-- User-Role Mapping table (many-to-many relationship) +CREATE TABLE IF NOT EXISTS user_role_mapping ( + mapping_id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE, + role_id INTEGER NOT NULL REFERENCES roles(role_id) ON DELETE CASCADE +); + +-- Tunnels table +CREATE TABLE IF NOT EXISTS tunnels ( + tunnel_id SERIAL PRIMARY KEY, + tunnel_name VARCHAR(100) NOT NULL, + tunnel_type VARCHAR(50) NOT NULL +); + +-- Mapping Requests table +CREATE TABLE IF NOT EXISTS mapping_requests ( + request_id SERIAL PRIMARY KEY, + request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + status VARCHAR(20) NOT NULL, + user_id INTEGER REFERENCES users(user_id) ON DELETE SET NULL, + tunnel_id INTEGER REFERENCES tunnels(tunnel_id) ON DELETE SET NULL +); -- 2.45.2 From bbadd41ec482aa2bdff2ee4f8d48d97e4d1e7fd9 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 22:55:05 +0530 Subject: [PATCH 2/4] bug fixes --- build.gradle | 1 - docker-compose.yaml | 9 +++------ src/main/resources/application-local.properties | 2 ++ src/main/resources/application.properties | 5 +++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 2c09e0d..4340fce 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,6 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'org.postgresql:postgresql' implementation 'org.hibernate.validator:hibernate-validator' diff --git a/docker-compose.yaml b/docker-compose.yaml index 772008b..f33b9fe 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,10 +15,10 @@ services: - POSTGRES_USER=${POSTGRES_USERNAME} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} env_file: - - .env + - stack.env restart: unless-stopped postgres: - image: postgres:15 + image: postgres:15-alpine container_name: cftunnel-db environment: POSTGRES_DB: cftunnel @@ -28,7 +28,4 @@ services: ports: - "5432:5432" volumes: - - pgdata:/var/lib/postgresql/data - -volumes: - pgdata: {} \ No newline at end of file + - ${DB_PATH}:/var/lib/postgresql/data \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 556b2d1..c355d6f 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -6,3 +6,5 @@ management.endpoint.health.show-details=always logging.level.org.hibernate.SQL=DEBUG debug=true + +spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e6d31e7..c241382 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,7 +18,7 @@ spring.security.oauth2.client.provider.cftunnels.user-info-uri=https://auth.hith spring.security.oauth2.client.provider.cftunnels.jwk-set-uri=https://auth.hithomelabs.com/application/o/cftunnels/jwks/ spring.security.oauth2.client.provider.cftunnels.issuer-uri=https://auth.hithomelabs.com/application/o/cftunnels/ -spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel +spring.datasource.url=jdbc:postgresql://192.168.0.100:5432/cftunnel spring.datasource.username=${POSTGRES_USERNAME} spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver @@ -26,5 +26,6 @@ spring.sql.init.mode=always spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + +spring.jpa.open-in-view=false \ No newline at end of file -- 2.45.2 From 729d0ddcfc366a2c931a55bf2a4fd7ce85e8b924 Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 23:28:24 +0530 Subject: [PATCH 3/4] sql init set to never --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c241382..72edec8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,7 +22,7 @@ spring.datasource.url=jdbc:postgresql://192.168.0.100:5432/cftunnel spring.datasource.username=${POSTGRES_USERNAME} spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.driver-class-name=org.postgresql.Driver -spring.sql.init.mode=always +spring.sql.init.mode=never spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true -- 2.45.2 From b804cc978fc428dec16c089e547f36ed62201beb Mon Sep 17 00:00:00 2001 From: Kruti Shah Date: Sun, 12 Oct 2025 23:38:40 +0530 Subject: [PATCH 4/4] dialect readded --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 72edec8..a0264d2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -26,6 +26,6 @@ spring.sql.init.mode=never spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true - +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.open-in-view=false \ No newline at end of file -- 2.45.2