Skip to content
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
7 changes: 7 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ quarkus.datasource.jdbc.url=jdbc:h2:mem:thrillhouse;DB_CLOSE_DELAY=-1
%prod.quarkus.datasource.db-kind=${DATASOURCE_DB_KIND:postgresql}
%prod.quarkus.datasource.jdbc.url=${DATABASE_URL:jdbc:postgresql://localhost:5432/thrillhouse}
%prod.quarkus.hibernate-orm.schema-management.strategy=update
# Dev mode points at an explicit H2 URL, so no Dev Services database is started and nothing creates
# the schema for it; Hibernate's default strategy is `none`. Without the line below `quarkus:dev`
# came up against an empty database β€” the app started and /q/health returned 200, then post-boot
# validation logged "missing table [finding_feedback]" and every DB-backed feature failed at
# runtime with Table "REVIEWSESSION" not found. The dev database is in-memory and discarded when
# the JVM exits, so recreate it on each boot exactly as the test profile does.
%dev.quarkus.hibernate-orm.schema-management.strategy=drop-and-create

# Dashboard public base URL (session deep-links posted to GitHub) and OAuth login
thrillhousebot.dashboard.url=${DASHBOARD_URL:http://localhost:8080}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2026 Thiago Gonzaga
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.thiagogonzaga.thrillhousebot.config;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;

/**
* Schema management per profile, bound straight from {@code
* src/main/resources/application.properties} β€” the dev profile is never exercised by the test suite
* (tests run under {@code %test}, whose own {@code src/test/resources/application.properties} sets
* the strategy), so nothing else here notices when the shipped file leaves {@code quarkus:dev}
* without one.
*
* <p>#565: the strategy was set only under {@code %prod}, and dev mode points at an explicit H2 URL
* so no Dev Services database creates the schema for it. Hibernate's default is {@code none}, so a
* fresh clone booted against an empty database β€” the app started and {@code /q/health} answered 200
* while post-boot validation logged {@code missing table [finding_feedback]} and every DB-backed
* request failed with {@code Table "REVIEWSESSION" not found}.
*/
class DevSchemaManagementTest {

private static final String STRATEGY = "quarkus.hibernate-orm.schema-management.strategy";
private static final String JDBC_URL = "quarkus.datasource.jdbc.url";

@Test
void devModeCreatesTheSchemaItStartsAgainst() throws Exception {
assertEquals("drop-and-create", shipped("dev").getValue(STRATEGY, String.class));
}

@Test
void devModeRecreatesOnlyAnInMemoryDatabase() throws Exception {
// drop-and-create is safe precisely because the dev URL is a throwaway in-memory H2 instance:
// if this ever becomes a file or a server URL, the strategy above has to be revisited first.
assertTrue(
shipped("dev").getValue(JDBC_URL, String.class).startsWith("jdbc:h2:mem:"),
"dev must stay on in-memory H2 while it recreates the schema on every boot");
}

@Test
void prodStillMigratesRatherThanRecreating() throws Exception {
// Guards the blast radius of the dev line: production data must never be dropped at boot.
assertEquals("update", shipped("prod").getValue(STRATEGY, String.class));
}

private static SmallRyeConfig shipped(String profile) throws Exception {
return new SmallRyeConfigBuilder()
.addDefaultInterceptors() // profile selection and ${VAR:default} expansion, as at runtime
.withValidateUnknown(false)
.withProfile(profile)
.withSources(
new PropertiesConfigSource(
Paths.get("src/main/resources/application.properties").toUri().toURL()))
.build();
}
}
Loading