-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/migrate db to neon #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eb1dbe0
0716413
5e05f6e
4548b3d
8e8f7ad
df16625
7d7bf82
8bc1259
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,8 @@ | |||||
| This project runs as a WAR on Tomcat 9 (Jakarta Servlet API). The persistence layer uses Hibernate directly (no Spring). For MVP, schema is managed by Hibernate auto‑DDL; Flyway is a post‑MVP task. | ||||||
|
|
||||||
| ## Environments | ||||||
| - Dev/Test: H2 in‑memory DB via `src/main/resources/hibernate.cfg.xml` | ||||||
| - Prod (Week 8): AWS RDS (PostgreSQL or MySQL) | ||||||
| - Dev/Test: PostgreSQL (local or Docker) | ||||||
| - Prod: Neon (serverless PostgreSQL) | ||||||
|
|
||||||
| ## Required runtime configuration | ||||||
| - Cognito secret: provided by environment or JVM property | ||||||
|
|
@@ -18,23 +18,18 @@ This project runs as a WAR on Tomcat 9 (Jakarta Servlet API). The persistence la | |||||
| ### Dev/Test (default) | ||||||
| - `src/main/resources/hibernate.cfg.xml` points to H2 and sets `hbm2ddl.auto=update`. | ||||||
|
||||||
| - `src/main/resources/hibernate.cfg.xml` points to H2 and sets `hbm2ddl.auto=update`. | |
| - `src/main/resources/hibernate.cfg.xml` is configured for a local PostgreSQL instance (or Docker) and sets `hbm2ddl.auto=update`. |
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section references "Spring" properties and "application.yml", but this project uses Hibernate directly without Spring (as documented at the top of the file). Remove or update this section to reflect Hibernate-specific configuration instead of Spring configuration.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,11 +60,11 @@ private static SessionFactory buildSessionFactory() { | |||||||||||
| url = explicitUrl; | ||||||||||||
| } else { | ||||||||||||
| String host = resolve("DB_HOST", "localhost"); | ||||||||||||
| String port = resolve("DB_PORT", "3306"); | ||||||||||||
| String port = resolve("DB_PORT", "5432"); | ||||||||||||
| String db = resolve("DB_NAME", "cf_test_db"); | ||||||||||||
|
|
||||||||||||
| url = "jdbc:mysql://" + host + ":" + port + "/" + db | ||||||||||||
| + "?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; | ||||||||||||
| url = "jdbc:postgresql://" + host + ":" + port + "/" + db | ||||||||||||
| + "?ssl=true&sslmode=require"; | ||||||||||||
|
Comment on lines
+66
to
+67
|
||||||||||||
| url = "jdbc:postgresql://" + host + ":" + port + "/" + db | |
| + "?ssl=true&sslmode=require"; | |
| boolean isLocalhost = "localhost".equalsIgnoreCase(host) || "127.0.0.1".equals(host); | |
| String sslParams = isLocalhost ? "?ssl=false" : "?ssl=true&sslmode=require"; | |
| url = "jdbc:postgresql://" + host + ":" + port + "/" + db + sslParams; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,25 +4,21 @@ | |||||||||
| "https://hibernate.org/dtd/hibernate-configuration-3.0.dtd"> | ||||||||||
| <hibernate-configuration> | ||||||||||
| <session-factory> | ||||||||||
| <!-- JDBC connection (values resolved from System properties for CI; MySQL only) --> | ||||||||||
| <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property> | ||||||||||
| <!-- Use system property hibernate.connection.url or default to local MySQL cf_test_db --> | ||||||||||
| <!-- JDBC connection (values resolved from System properties for CI; PostgreSQL) --> | ||||||||||
| <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> | ||||||||||
| <!-- Use system property hibernate.connection.url or default to local PostgreSQL cf_test_db --> | ||||||||||
| <property name="hibernate.connection.url"> | ||||||||||
| jdbc:mysql://${DB_HOST}:3306/${DB_NAME} | ||||||||||
| ?useSSL=false | ||||||||||
| &allowPublicKeyRetrieval=true | ||||||||||
| &serverTimezone=UTC | ||||||||||
| &useUnicode=true | ||||||||||
| &characterEncoding=utf8mb4 | ||||||||||
| &connectionCollation=utf8mb4_unicode_ci | ||||||||||
| jdbc:postgresql://${DB_HOST}:5432/${DB_NAME} | ||||||||||
| ?ssl=true | ||||||||||
| &sslmode=require | ||||||||||
|
Comment on lines
+11
to
+13
|
||||||||||
| jdbc:postgresql://${DB_HOST}:5432/${DB_NAME} | |
| ?ssl=true | |
| &sslmode=require | |
| jdbc:postgresql://${DB_HOST}:5432/${DB_NAME}${DB_SSL_OPTIONS} |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,42 +1,38 @@ | ||||||
| -- Purpose: Reset schema and seed sample data for local/dev testing | ||||||
| -- MySQL version | ||||||
| -- PostgreSQL version | ||||||
|
|
||||||
| -- Disable FK checks for dropping | ||||||
| SET FOREIGN_KEY_CHECKS = 0; | ||||||
|
|
||||||
| DROP TABLE IF EXISTS submissions; | ||||||
| DROP TABLE IF EXISTS drill_items; | ||||||
| DROP TABLE IF EXISTS challenges; | ||||||
|
|
||||||
| SET FOREIGN_KEY_CHECKS = 1; | ||||||
| -- Drop tables (CASCADE handles foreign keys automatically) | ||||||
| DROP TABLE IF EXISTS submissions CASCADE; | ||||||
| DROP TABLE IF EXISTS drill_items CASCADE; | ||||||
| DROP TABLE IF EXISTS challenges CASCADE; | ||||||
|
|
||||||
| -- ------------------------------------------ | ||||||
| -- Recreate tables | ||||||
| -- ------------------------------------------ | ||||||
|
|
||||||
| CREATE TABLE challenges ( | ||||||
| id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||||||
| id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | ||||||
| title VARCHAR(255) NOT NULL, | ||||||
| blurb TEXT, | ||||||
| prompt_md TEXT, | ||||||
| expected_answer TEXT, | ||||||
| difficulty ENUM('EASY', 'MEDIUM', 'HARD') NOT NULL, | ||||||
| difficulty VARCHAR(20) NOT NULL CHECK (difficulty IN ('EASY', 'MEDIUM', 'HARD')), | ||||||
| created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||||||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||||||
| UNIQUE KEY uk_challenges_title (title) | ||||||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||||||
| CONSTRAINT uk_challenges_title UNIQUE (title) | ||||||
| ); | ||||||
|
|
||||||
| CREATE TABLE drill_items ( | ||||||
| id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||||||
| id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | ||||||
| challenge_id BIGINT NOT NULL, | ||||||
| user_id VARCHAR(64) NOT NULL, -- MVP: string-based user identifier (e.g., 'demo' or Cognito sub) | ||||||
| times_seen INT NOT NULL DEFAULT 0, | ||||||
| streak INT NOT NULL DEFAULT 0, | ||||||
| created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||||||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||||||
| updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||||||
| next_due_at TIMESTAMP NULL DEFAULT NULL, | ||||||
| version BIGINT NOT NULL DEFAULT 0, | ||||||
| UNIQUE KEY uk_drill_items_user_challenge (user_id, challenge_id), | ||||||
| CONSTRAINT uk_drill_items_user_challenge UNIQUE (user_id, challenge_id), | ||||||
| CONSTRAINT fk_drill_items_challenge | ||||||
| FOREIGN KEY (challenge_id) | ||||||
| REFERENCES challenges(id) | ||||||
|
|
@@ -45,13 +41,13 @@ CREATE TABLE drill_items ( | |||||
| ); | ||||||
|
|
||||||
| CREATE TABLE submissions ( | ||||||
| id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||||||
| id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | ||||||
|
||||||
| id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # PostgreSQL connection settings for local testing | ||
| # Copy this file to test-db.properties and update with your local PostgreSQL credentials | ||
| # test-db.properties is git-ignored to prevent committing secrets | ||
|
|
||
| hibernate.connection.driver_class=org.postgresql.Driver | ||
| hibernate.connection.url=jdbc:postgresql://localhost:5432/cf_test_db?ssl=false | ||
| hibernate.connection.username=postgres | ||
| hibernate.connection.password=your_password_here | ||
| hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README still contains multiple references to MySQL that need to be updated to PostgreSQL, including:
These sections should be updated to reflect the PostgreSQL migration.