'create-drop' borra las tablas en cada shutdown, perdiendo todos los usuarios (y el cambio de password). Aunque el bind mount persiste el archivo H2 en /root/docker/manual/lineage2/data/, las tablas se recreaban vacias en cada restart del container. Solucion: Flyway para manejar el schema, Hibernate solo valida. - pom.xml: + quarkus-flyway - src/main/resources/db/migration/V1__init.sql: schema de users, user_state, production_runs + index idx_runs_user_created - application.properties: database.generation=create-drop -> validate + quarkus.flyway.migrate-at-start=true + baseline-on-migrate=true BootstrapAdmin queda igual: chequea User.count() y crea admin si 0. Flyway corre antes de Hibernate, asi que las tablas existen cuando StartupEvent dispara.
This commit is contained in:
@@ -60,6 +60,10 @@
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jdbc-h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-flyway</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-smallrye-jwt</artifactId>
|
||||
|
||||
@@ -8,8 +8,12 @@ quarkus.datasource.db-kind=h2
|
||||
quarkus.datasource.jdbc.url=jdbc:h2:file:./data/shots;DB_CLOSE_DELAY=-1
|
||||
quarkus.datasource.username=sa
|
||||
quarkus.datasource.password=
|
||||
quarkus.hibernate-orm.database.generation=create-drop
|
||||
quarkus.hibernate-orm.database.generation=validate
|
||||
quarkus.hibernate-orm.log.sql=false
|
||||
# Flyway maneja el schema. validate hace que Hibernate solo valide
|
||||
# que el schema en DB coincide con las entities, sin tocarlo.
|
||||
quarkus.flyway.migrate-at-start=true
|
||||
quarkus.flyway.baseline-on-migrate=true
|
||||
|
||||
# JWT
|
||||
mp.jwt.verify.issuer=shot-crafter-calculator
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY,
|
||||
username VARCHAR(30) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(100) NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
must_change_password BOOLEAN NOT NULL,
|
||||
is_admin BOOLEAN NOT NULL,
|
||||
last_login_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE user_state (
|
||||
user_id UUID PRIMARY KEY,
|
||||
state_json TEXT NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE production_runs (
|
||||
id UUID PRIMARY KEY,
|
||||
user_id UUID NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
label VARCHAR(100),
|
||||
total_cost BIGINT NOT NULL,
|
||||
total_sale BIGINT NOT NULL,
|
||||
total_profit BIGINT NOT NULL,
|
||||
total_shots BIGINT NOT NULL,
|
||||
total_cristales_used BIGINT NOT NULL,
|
||||
total_ore_used BIGINT NOT NULL,
|
||||
items_json TEXT NOT NULL,
|
||||
snapshot_json TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_runs_user_created ON production_runs (user_id, created_at);
|
||||
Reference in New Issue
Block a user