You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/templates/template-mapping-section.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,18 +18,24 @@ In a template-based change unit (declarative format), Flamingock uses the `execu
18
18
- The method annotated with `@RollbackExecution` is **mandatory** for the template developer.
19
19
- The `rollback` section in the declarative change unit is **optional** for the user.
20
20
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).
22
24
23
25
**Rollback during execution failure**
24
26
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**.
-**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.
-**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**.
29
35
30
-
**Rollback during Undo operations (manual reversion)**
36
+
**Rollback during Undo operations (manual reversion via CLI)**
31
37
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.
33
39
- If no `rollback` is provided, Flamingock skips the rollback logic, but still marks the change as **ROLLED_BACK** in the audit.
@@ -43,16 +42,17 @@ Create a **YAML file** (e.g., `_0001_create_persons_table.yaml`) inside your app
43
42
```yaml
44
43
id: create-persons-table-from-template
45
44
order: 1
45
+
targetSystem: "database-system"
46
46
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;"
56
56
```
57
57
58
58
:::info
@@ -63,12 +63,13 @@ Note that your application must provide a `java.sql.Connection` instance as a de
63
63
64
64
- **`id`**: Unique identifier for the change, used for tracking (same as in code-based changes).
65
65
- **`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.
66
67
- **`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 additionalconfiguration fields as needed.
70
71
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.
72
73
73
74
### Step 3: Configure Flamingock to use the template file
74
75
@@ -136,16 +137,17 @@ With the **SQL Template**, users define the same migration in **YAML** instead o
136
137
```yaml
137
138
id: create-persons-table-from-template
138
139
order: 1
140
+
targetSystem: "database-system"
139
141
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;"
149
151
```
150
152
151
153
### Key Benefits of Using a Template Instead of Code-Based ChangeUnits:
0 commit comments