Skip to content

Commit 3073f1d

Browse files
committed
Flyway migration to separate module, it's huge
1 parent 43ce2b4 commit 3073f1d

10 files changed

Lines changed: 53 additions & 42 deletions

File tree

Answer.class

-173 Bytes
Binary file not shown.

Answer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ public void createFrame() {
3131
setContentPane(content);
3232

3333
// User content goes into CENTER by default (BorderLayout.CENTER)
34-
JButton button = new JButton();
35-
button.setIcon(new ImageIcon("icon.png"));
36-
button.setText("Text");
37-
button.setIconTextGap(5);
38-
add(button);
34+
JTextField field = new JTextField();
35+
add(field);
3936

4037
setTitle(headerText);
4138
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

README.md

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ results of their code in a visual, interactive environment.
3838
The project follows a multi-module Maven architecture:
3939

4040
- **`domain`**: Shared DTOs, request/response models, and domain entities used across modules
41+
- **`flyway`**: Database migrations (SQL only); consumed by the service classpath and by the Flyway Docker image / K8s
42+
Job
4143
- **`service`**: Spring Boot REST API backend providing:
4244
- User authentication and management
4345
- Lesson and task management
@@ -99,14 +101,15 @@ mvn clean package -pl desktop-client -am
99101
```
100102

101103
This produces a runnable JAR file:
102-
- `desktop-client/target/desktop-client-1.0-SNAPSHOT.jar`
104+
105+
- `desktop-client/target/desktop-client-<version>.jar`
103106

104107
### Step 3: Run Desktop Client
105108

106109
Launch the desktop application:
107110

108111
```bash
109-
java -jar desktop-client/target/desktop-client-1.0-SNAPSHOT.jar
112+
java -jar desktop-client/target/desktop-client-<version>.jar
110113
```
111114

112115
The client automatically connects to the backend service at `http://localhost:8080`.
@@ -138,13 +141,13 @@ The client automatically connects to the backend service at `http://localhost:80
138141

139142
#### Backend Service
140143

141-
| Variable | Description | Default |
142-
|-------------------------------------|-----------------------------|-----------------------------------------------------------|
143-
| `JAVA_SWING_TUTOR_DB_URL` | PostgreSQL connection URL | `jdbc:postgresql://localhost:5450/java_swing_tutor` |
144-
| `JAVA_SWING_TUTOR_DB_USER` | Database username | `java_swing_tutor` |
145-
| `JAVA_SWING_TUTOR_DB_PASSWORD` | Database password | `java_swing_tutor` |
146-
| `JAVA_SWING_TUTOR_SERVICE_PORT` | Service port | `8080` |
147-
| `SPRING_PROFILES_ACTIVE` | Spring profile (dev/docker) | `dev` |
144+
| Variable | Description | Default |
145+
|--------------------------------------|-----------------------------|-----------------------------------------------------|
146+
| `JAVA_SWING_TUTOR_DATABASE_URL` | PostgreSQL connection URL | `jdbc:postgresql://localhost:5450/java_swing_tutor` |
147+
| `JAVA_SWING_TUTOR_DATABASE_USER` | Database username | `java_swing_tutor` |
148+
| `JAVA_SWING_TUTOR_DATABASE_PASSWORD` | Database password | `java_swing_tutor` |
149+
| `JAVA_SWING_TUTOR_SERVICE_PORT` | Service port | `8080` |
150+
| `SPRING_PROFILES_ACTIVE` | Spring profile (dev/docker) | `dev` |
148151

149152
### Docker Compose Configuration
150153

@@ -185,7 +188,7 @@ This allows for faster iteration during development with hot-reload capabilities
185188
mvn clean package -pl desktop-client -am
186189

187190
# Run the client (connects to backend at http://localhost:8080)
188-
java -jar desktop-client/target/desktop-client-1.0-SNAPSHOT.jar
191+
java -jar desktop-client/target/desktop-client-<version>.jar
189192
```
190193

191194
## 📁 Project Structure
@@ -207,14 +210,16 @@ java-swing-tutor/
207210
│ ├── infrastructure/ # JPA repositories and external clients
208211
│ └── web/ # REST controllers
209212
│ └── src/main/resources/
210-
│ ├── application.yml # Spring Boot configuration
211-
│ └── db/migration/ # Flyway database migrations
212-
│ ├── common/ # Schema and common data
213-
│ ├── lesson/ # Base lesson data
214-
│ ├── lesson_en/ # English translations
215-
│ ├── lesson_ru/ # Russian translations
216-
│ ├── lesson_es/ # Spanish translations
217-
│ └── lesson_it/ # Italian translations
213+
│ └── application.yml # Spring Boot configuration
214+
215+
├── flyway/ # Database migrations (separate from service)
216+
│ └── src/main/resources/db/migration/
217+
│ ├── common/ # Schema and common data
218+
│ ├── lesson/ # Base lesson data
219+
│ ├── lesson_en/ # English translations
220+
│ ├── lesson_ru/ # Russian translations
221+
│ ├── lesson_es/ # Spanish translations
222+
│ └── lesson_it/ # Italian translations
218223
219224
├── desktop-client/ # Swing desktop UI client
220225
│ └── src/main/java/
@@ -228,9 +233,10 @@ java-swing-tutor/
228233
│ └── i18n/ # Internationalization files
229234
230235
├── deployment/ # Shared cluster config and scripts (see deployment/README.md)
236+
├── flyway/ # Migrations module + Flyway image and K8s Job (flyway/deployment/)
231237
├── website/ # Next.js website (and website/deployment/ for deploy)
232238
├── docker-compose.yml # Docker services configuration
233-
├── service/Dockerfile # Service container image (build context: repo root)
239+
├── service/Dockerfile # Service container image (build context: repo root)
234240
└── pom.xml # Root Maven POM
235241
```
236242

@@ -266,8 +272,9 @@ The backend service exposes REST APIs at `http://localhost:8080/api`:
266272

267273
## 🗄️ Database
268274

269-
The application uses PostgreSQL with Flyway for database migrations. All migrations are located in:
270-
- `service/src/main/resources/db/migration/`
275+
The application uses PostgreSQL with Flyway for database migrations. All migrations are in the **`flyway`** module:
276+
277+
- `flyway/src/main/resources/db/migration/`
271278

272279
The database schema includes:
273280

@@ -326,17 +333,24 @@ docker compose logs -f service
326333

327334
## ☸️ Kubernetes deployment
328335

329-
**Flow:** deploy common cluster config from the **parent** `deployment/`, then **build images and deploy from each module** (website, service). There is no central “build and push all”; each module builds and pushes its own image, then deploys. See **[deployment/README.md](deployment/README.md)** for layout and backend prerequisites.
336+
**Flow:** deploy common cluster config from the **parent** `deployment/`, then **build images and deploy from each
337+
module** (website, flyway, service). Flyway and service are separate: deploy Flyway first (migrations), then the backend
338+
service. There is no central “build and push all”; each module builds and pushes its own image, then deploys. See *
339+
*[deployment/README.md](deployment/README.md)** for layout and prerequisites.
330340

331-
**Step 1** applies: namespace, Docker Hub secret, ConfigMap, Secrets, Traefik Let's Encrypt, Traefik middleware, and Traefik IngressRoute (routing for java-swing.com and api.java-swing.com). Step 2 deploys the website and backend so traffic can reach them.
332341

333342
```bash
334343
# 1. Deploy common cluster config from parent (namespace, secret, ConfigMap, Secrets, Traefik IngressRoute + middleware)
335344
./deployment/scripts/k3s/deploy-to-k3s.sh
336345

337-
# 2. Build, push, and deploy each module from its own folder
346+
# 2. Website (from website/)
338347
cd website && ./deployment/scripts/build-and-push.sh <version> && ./deployment/scripts/deploy.sh <version>
339-
cd ../service && ./deployment/scripts/build-and-push.sh <version> && ./deployment/scripts/deploy.sh <version>
348+
349+
# 3. Flyway migrations (from flyway/) — run before the backend service
350+
cd flyway && ./deployment/scripts/build-and-push.sh <version> && ./deployment/scripts/deploy.sh <version>
351+
352+
# 4. Backend service (from service/)
353+
cd service && ./deployment/scripts/build-and-push.sh <version> && ./deployment/scripts/deploy.sh <version>
340354
```
341355

342356
## 📚 Learning Path

deployment/configmap.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ metadata:
44
name: java-swing-tutor-config
55
namespace: java-swing-tutor
66
data:
7-
db.url: "jdbc:postgresql://postgres-service:5432/java_swing_tutor"
7+
db.url: "jdbc:postgresql://shared-posadskiy.e.aivencloud.com:25370/java_swing_tutor_db?sslmode=require"
8+
db.user: "avnadmin"

deployment/scripts/k3s/deploy-to-k3s.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
# Deploy backend: ./service/deployment/scripts/deploy.sh <version>
88
#
99
# Required env: DOCKERHUB_USERNAME, DOCKERHUB_TOKEN; K3S_SERVER_IP, K3S_SSH_USER (see setup-env.sh).
10-
# For backend secrets: JAVA_SWING_TUTOR_DB_PASSWORD etc. (see secrets.yaml).
10+
# For backend secrets: JAVA_SWING_TUTOR_DATABASE_PASSWORD etc. (see secrets.yaml).
1111

1212
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1313
DEPLOYMENT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"

deployment/scripts/k3s/setup-env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ REQUIRED_VARS=(
2222

2323
# Optional for full deployment (backend + DB secrets)
2424
OPTIONAL_VARS=(
25-
"JAVA_SWING_TUTOR_DB_PASSWORD"
25+
"JAVA_SWING_TUTOR_DATABASE_PASSWORD"
2626
)
2727

2828
MISSING_VARS=()

deployment/secrets.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ metadata:
55
namespace: java-swing-tutor
66
type: Opaque
77
stringData:
8-
db.user: "${JAVA_SWING_TUTOR_DB_USER:-java_swing_tutor}"
9-
# Set JAVA_SWING_TUTOR_DB_PASSWORD (or leave placeholder and apply secret manually)
10-
db.password: "${JAVA_SWING_TUTOR_DB_PASSWORD:-change-me}"
8+
db.password: "${JAVA_SWING_TUTOR_DATABASE_PASSWORD_PROD}"

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ services:
2525
FLYWAY_PASSWORD: java_swing_tutor
2626
FLYWAY_LOCATIONS: filesystem:/flyway/sql
2727
volumes:
28-
- ./service/src/main/resources/db/migration:/flyway/sql:ro
28+
- ./flyway/src/main/resources/db/migration:/flyway/sql:ro
2929

3030
service:
3131
build:
@@ -37,9 +37,9 @@ services:
3737
ports:
3838
- "8080:8080"
3939
environment:
40-
JAVA_SWING_TUTOR_DB_URL: jdbc:postgresql://db:5432/java_swing_tutor
41-
JAVA_SWING_TUTOR_DB_USER: java_swing_tutor
42-
JAVA_SWING_TUTOR_DB_PASSWORD: java_swing_tutor
40+
JAVA_SWING_TUTOR_DATABASE_URL: jdbc:postgresql://db:5432/java_swing_tutor
41+
JAVA_SWING_TUTOR_DATABASE_USER: java_swing_tutor
42+
JAVA_SWING_TUTOR_DATABASE_PASSWORD: java_swing_tutor
4343
JAVA_SWING_TUTOR_SERVICE_PORT: 8080
4444
SPRING_PROFILES_ACTIVE: docker
4545
AUTH_SERVICE_BASE_URL: http://auth-service:8100

domain/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.posadskiy</groupId>
99
<artifactId>java-swing-tutor</artifactId>
10-
<version>1.0-SNAPSHOT</version>
10+
<version>1.0.0</version>
1111
</parent>
1212

1313
<artifactId>domain</artifactId>

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
<groupId>com.posadskiy</groupId>
66
<artifactId>java-swing-tutor</artifactId>
7-
<version>1.0-SNAPSHOT</version>
7+
<version>1.0.0</version>
88
<packaging>pom</packaging>
99
<name>java-swing-tutor</name>
1010

1111
<modules>
1212
<module>domain</module>
13+
<module>flyway</module>
1314
<module>service</module>
1415
<module>desktop-client</module>
1516
</modules>

0 commit comments

Comments
 (0)