Skip to content

Commit f0ba5ee

Browse files
authored
docs: template new format (#76)
1 parent bf9d372 commit f0ba5ee

File tree

7 files changed

+82
-60
lines changed

7 files changed

+82
-60
lines changed

docs/change-units/introduction.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ id: add_status_column
5656
order: "0002"
5757
author: "db-team"
5858
templateName: sql-template
59-
templateConfiguration:
60-
executionSql: "ALTER TABLE orders ADD COLUMN status VARCHAR(20);"
61-
rollbackSql: "ALTER TABLE orders DROP COLUMN status;"
59+
execution: "ALTER TABLE orders ADD COLUMN status VARCHAR(20);"
60+
rollback: "ALTER TABLE orders DROP COLUMN status;"
6261
```
6362
6463
## Safety and recovery

docs/change-units/types-and-implementation.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,20 @@ id: add_user_index
4949
order: "0001"
5050
author: "database-team"
5151
description: "Add index on user email field for faster lookups"
52+
targetSystem: "user-database"
5253
templateName: mongodb-index
53-
templateConfiguration:
54+
execution:
55+
type: createIndex
5456
collection: users
5557
indexSpec:
5658
email: 1
5759
options:
5860
unique: true
5961
name: "idx_user_email"
62+
rollback:
63+
type: removeIndex
64+
collection: users
65+
indexName: "idx_user_email"
6066
```
6167
6268
For more details about available templates and creating custom templates, see [Templates](../templates/introduction).

docs/getting-started/get-started.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ author: team
102102
order: "001"
103103
targetSystem: mysql-inventory
104104
template: sql-template
105-
templateConfiguration:
106-
executionSql: |
107-
ALTER TABLE products ADD COLUMN category VARCHAR(255)
108-
rollbackSql: |
109-
ALTER TABLE products DROP COLUMN category
105+
execution: |
106+
ALTER TABLE products ADD COLUMN category VARCHAR(255)
107+
rollback: |
108+
ALTER TABLE products DROP COLUMN category
110109
```
111110
112111
</TabItem>

docs/overview/Change-as-Code.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,11 @@ order: 0001
213213
author: "team-a"
214214
transactional: false
215215
templateName: aws-s3-template
216-
templateConfiguration:
216+
execution:
217217
bucketName: "flamingock-app-bucket"
218218
region: "us-east-1"
219-
rollbackBucketName: "flamingock-app-bucket"
219+
rollback:
220+
bucketName: "flamingock-app-bucket"
220221

221222
---
222223

@@ -226,7 +227,7 @@ order: 0002
226227
author: "devops"
227228
transactional: false
228229
templateName: kafka-template
229-
templateConfiguration:
230+
execution:
230231
topics:
231232
- "app-events"
232233
- "user-notifications"
@@ -237,6 +238,10 @@ templateConfiguration:
237238
user-notifications:
238239
partitions: 2
239240
replicationFactor: 1
241+
rollback:
242+
topics:
243+
- "app-events"
244+
- "user-notifications"
240245
rollbackTopics:
241246
- "app-events"
242247
- "user-notifications"
@@ -249,7 +254,7 @@ order: 0003
249254
author: "devops"
250255
transactional: false
251256
templateName: aws-iam-template
252-
templateConfiguration:
257+
execution:
253258
roleName: "flamingock-app-role"
254259
assumeRolePolicy: |
255260
{
@@ -262,6 +267,8 @@ templateConfiguration:
262267
}
263268
]
264269
}
270+
rollback:
271+
roleName: "flamingock-app-role"
265272
rollbackRoleName: "flamingock-app-role"
266273

267274
---
@@ -272,12 +279,11 @@ order: 0004
272279
author: "devops"
273280
transactional: true
274281
templateName: sql-template
275-
templateConfiguration:
276-
executionSql: |
277-
INSERT INTO tenants (id, name, created_at)
278-
VALUES (1, 'TenantA', NOW()), (2, 'TenantB', NOW());
279-
rollbackSql: |
280-
DELETE FROM tenants WHERE id IN (1, 2);
282+
execution: |
283+
INSERT INTO tenants (id, name, created_at)
284+
VALUES (1, 'TenantA', NOW()), (2, 'TenantB', NOW());
285+
rollback: |
286+
DELETE FROM tenants WHERE id IN (1, 2);
281287
282288
---
283289

@@ -287,12 +293,16 @@ order: 0005
287293
author: "team-a"
288294
transactional: false
289295
templateName: aws-s3-template
290-
templateConfiguration:
296+
execution:
291297
# Enable versioning on an existing bucket
292298
bucketName: "flamingock-app-bucket"
293299
versioningConfiguration:
294300
status: "Enabled"
301+
rollback:
295302
# Rollback: suspend versioning
303+
bucketName: "flamingock-app-bucket"
304+
versioningConfiguration:
305+
status: "Suspended"
296306
rollbackVersioningConfiguration:
297307
bucketName: "flamingock-app-bucket"
298308
versioningConfiguration:

docs/templates/template-mapping-section.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@ In a template-based change unit (declarative format), Flamingock uses the `execu
1818
- The method annotated with `@RollbackExecution` is **mandatory** for the template developer.
1919
- The `rollback` section in the declarative change unit is **optional** for the user.
2020

21-
The behavior of rollback varies depending on context:
21+
The behavior of rollback varies depending on the target system capabilities and the `transactional` flag:
22+
23+
> For detailed information on transaction behavior, see [Transactions](../flamingock-library-config/transactions.md).
2224
2325
**Rollback during execution failure**
2426

25-
- If the system is **transactional** (e.g., MySQL), Flamingock relies on the system’s native transaction handling. It will not call the rollback method.
26-
- If the system is **non-transactional**, Flamingock will:
27-
- Attempt to call the `@RollbackExecution` method only if the user provides a `rollback` section in the declarative file.
28-
- If no rollback config is provided, Flamingock skips the method call and logs the change as **FAILED**.
27+
**For transactional target systems** (e.g., MySQL, PostgreSQL, MongoDB):
28+
- **With `transactional = true` (default)**: Flamingock relies on the system's native transaction handling for automatic rollback. The `@RollbackExecution` method is NOT called.
29+
- **With `transactional = false`**: Flamingock will call the `@RollbackExecution` method if the user provides a `rollback` section in the declarative file.
30+
31+
**For non-transactional target systems** (e.g., Kafka, S3, REST APIs):
32+
- **The `transactional` flag is ignored** - behavior is always the same:
33+
- Flamingock will call the `@RollbackExecution` method if the user provides a `rollback` section in the declarative file.
34+
- If no rollback config is provided, Flamingock skips the method call and logs the change as **FAILED**.
2935

30-
**Rollback during Undo operations (manual reversion)**
36+
**Rollback during Undo operations (manual reversion via CLI)**
3137

32-
- If a `rollback` section is present in the declarative file, Flamingock will call the `@RollbackExecution` method — even if the change was previously applied successfully.
38+
- If a `rollback` section is present in the declarative file, Flamingock will call the `@RollbackExecution` method regardless of target system type.
3339
- If no `rollback` is provided, Flamingock skips the rollback logic, but still marks the change as **ROLLED_BACK** in the audit.
3440

3541
:::note

docs/templates/templates-how-to-use.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ Ensure your **Flamingock Template** dependency is included in your project. Exam
1717
<Tabs groupId="gradle_maven">
1818
<TabItem value="gradle" label="Gradle">
1919
```kotlin
20-
implementation(platform("io.flamingock:flamingock-ce-bom:$flamingockVersion"))
21-
implementation("io.flamingock:flamingock-ce-sql-template")
20+
implementation(platform("io.flamingock:flamingock-community-bom:$flamingockVersion"))
21+
implementation("io.flamingock:flamingock-community-sql-template")
2222
```
2323
</TabItem>
2424
<TabItem value="maven" label="Maven">
2525
```xml
2626
<dependency>
27-
<groupId>io.flamingock.template</groupId>
28-
<artifactId>sql-template</artifactId>
29-
<version>1.0.0</version>
27+
<groupId>io.flamingock</groupId>
28+
<artifactId>flamingock-community-sql-template</artifactId>
3029
</dependency>
3130
```
3231
</TabItem>
@@ -43,16 +42,17 @@ Create a **YAML file** (e.g., `_0001_create_persons_table.yaml`) inside your app
4342
```yaml
4443
id: create-persons-table-from-template
4544
order: 1
45+
targetSystem: "database-system"
4646
templateName: sql-template
47-
templateConfiguration:
48-
executionSql: |
49-
CREATE TABLE Persons (
50-
PersonID int,
51-
LastName varchar(255),
52-
FirstName varchar(255),
53-
Address varchar(255),
54-
City varchar(255)
55-
)
47+
execution: |
48+
CREATE TABLE Persons (
49+
PersonID int,
50+
LastName varchar(255),
51+
FirstName varchar(255),
52+
Address varchar(255),
53+
City varchar(255)
54+
)
55+
rollback: "DROP TABLE Persons;"
5656
```
5757
5858
:::info
@@ -63,12 +63,13 @@ Note that your application must provide a `java.sql.Connection` instance as a de
6363

6464
- **`id`**: Unique identifier for the change, used for tracking (same as in code-based changes).
6565
- **`order`**: Execution order relative to other changes (also shared with code-based).
66+
- **`targetSystem`**: Specifies which target system this change applies to - **required** for all template-based changes, just like code-based ChangeUnits.
6667
- **`templateName`**: Indicates which template should be used to handle the change logic. This is **required** for all template-based changes.
67-
- **`templateConfiguration`**: Section where you define the input parameters for the selected template. These parameters vary depending on the template.
68-
- In this example, the template expects an `executionSql` field.
69-
- **Other fields**: Some templates may define additional, custom configuration fields (e.g., `rollbackSql` for SQL template).
68+
- **`execution`**: Direct execution logic for the change. The format depends on the template type (string for SQL, map for MongoDB, etc.).
69+
- **`rollback`**: Direct rollback logic for the change. The format depends on the template type (string for SQL, map for MongoDB, etc.).
70+
- **Other fields**: Templates may define additional configuration fields as needed.
7071

71-
Template-based changes provide both **structure and flexibility**. They share the core concepts of change tracking with code-based ChangeUnits, but introduce a flexible configuration model where each template defines its own behavior through external parameters.
72+
Template-based changes provide both **structure and flexibility**. They share the core concepts of change tracking with code-based ChangeUnits, but use a standardized format with `execution` and `rollback` sections that each template interprets according to its specific requirements.
7273

7374
### Step 3: Configure Flamingock to use the template file
7475

@@ -136,16 +137,17 @@ With the **SQL Template**, users define the same migration in **YAML** instead o
136137
```yaml
137138
id: create-persons-table-from-template
138139
order: 1
140+
targetSystem: "database-system"
139141
templateName: sql-template
140-
templateConfiguration:
141-
executionSql: |
142-
CREATE TABLE Persons (
143-
PersonID int,
144-
LastName varchar(255),
145-
FirstName varchar(255),
146-
Address varchar(255),
147-
City varchar(255)
148-
)
142+
execution: |
143+
CREATE TABLE Persons (
144+
PersonID int,
145+
LastName varchar(255),
146+
FirstName varchar(255),
147+
Address varchar(255),
148+
City varchar(255)
149+
)
150+
rollback: "DROP TABLE Persons;"
149151
```
150152

151153
### Key Benefits of Using a Template Instead of Code-Based ChangeUnits:

docs/templates/templates-introduction.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ Instead of repeating the same boilerplate code over and over, templates let you
6060

6161
## List of current Flamingock templates
6262

63-
| Template Name | Description |
64-
|--------------|-------------|
65-
| **SQL Template** | Enables SQL-based migrations using YAML-defined ChangeUnits. |
66-
| **Kafka Template** (Upcoming) | Manages Kafka topics and configurations using YAML definitions. |
67-
| **Twilio Template** (Upcoming) | Simplifies Twilio messaging configurations via YAML. |
68-
| **Redis Template** (Upcoming) | Allows structured updates to Redis configurations. |
63+
| Template Name | Description | Status |
64+
|--------------|-------------|---------|
65+
| **SQL Template** | Enables SQL-based migrations using YAML-defined ChangeUnits | In Development |
66+
| **MongoDB Template** | Manages MongoDB operations and schema changes using YAML definitions | In Development |
67+
| **Kafka Template** | Manages Kafka topics and configurations using YAML definitions | In Development |
68+
| **S3 Template** | Manages S3 bucket operations and object configurations via YAML | In Development |
6969

7070
---
7171

0 commit comments

Comments
 (0)