Skip to content

Commit e2d9f32

Browse files
committed
docs: change anatomy and structure
1 parent 93ce930 commit e2d9f32

File tree

7 files changed

+139
-59
lines changed

7 files changed

+139
-59
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"Bash(npm run build:*)",
1717
"Bash(yarn build)",
1818
"Read(//Users/dieppa/workspace/flamingock/**)",
19-
"Bash(./gradlew:*)"
19+
"Bash(./gradlew:*)",
20+
"Bash(sort:*)"
2021
],
2122
"deny": []
2223
}

docs/changes/anatomy-and-structure.md

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,16 @@ public class _0001__AddUserFields {
132132

133133
## Apply and rollback methods
134134

135-
Both methods implement your change logic and use dependency injection to access the systems they need to modify.
135+
Both methods implement your change logic and automatically receive the dependencies they need through parameters.
136136

137137
### `@Apply` - Change logic
138138
Contains the actual change implementation.
139139

140140
```java
141141
@Apply
142-
public void apply(MongoDatabase database, ClientSession session) {
142+
public void apply(S3Client s3) {
143143
// Your change logic here
144-
database.getCollection("users")
145-
.updateMany(
146-
new Document("status", new Document("$exists", false)),
147-
new Document("$set", new Document("status", "active"))
148-
);
144+
s3.putBucketPolicy(/* configure bucket */);
149145
}
150146
```
151147

@@ -154,59 +150,18 @@ Provides logic to reverse the change, essential for safety and CLI undo operatio
154150

155151
```java
156152
@Rollback
157-
public void rollback(MongoDatabase database, ClientSession session) {
153+
public void rollback(S3Client s3) {
158154
// Undo the change
159-
database.getCollection("users")
160-
.updateMany(
161-
new Document(),
162-
new Document("$unset", new Document("status", ""))
163-
);
155+
s3.deleteBucketPolicy(/* remove configuration */);
164156
}
165157
```
166158

167-
### Method implementation guide
168-
169-
**Method characteristics:**
170-
- Must be public
171-
- Can have any name (`execute`, `run`, `apply`, etc.)
172-
- Should contain idempotent operations when possible
173-
174-
**Parameters you can expect:**
175-
- **Target system dependencies**: `MongoDatabase`, `DataSource`, `S3Client`, `KafkaTemplate`, etc.
176-
- **Transaction context**: `ClientSession` (MongoDB), `Connection` (SQL), transaction builders (DynamoDB)
177-
- **Custom dependencies**: Any beans or objects you've configured in your target system
178-
179-
**Method parameters are automatically injected** by Flamingock based on your target system configuration and global dependencies.
180-
181159
**Why rollback is required:**
182-
- **Non-transactional systems**: Used automatically if execution fails
183-
- **All systems**: Required for CLI/UI undo operations
184-
- **Safety**: Ensures every change can be reversed
185-
- **Governance**: Demonstrates you've thought through the change impact
186-
187-
For detailed information about dependency injection and parameter configuration, see [Method Parameters and Dependency Injection](./dependency-injection.md).
188-
189-
## Method parameters and dependency injection
190-
191-
Changes receive dependencies through method parameters, automatically injected by Flamingock using a **flexible, multi-source approach** with fallback hierarchy.
192-
193-
### Change Execution Dependency Resolution
194-
195-
Change execution uses a flexible dependency resolution flow(in this priority order):
196-
197-
1. **Target system context** - dependencies from **constructor** + `.withXXX()` methods
198-
2. **Target system additional dependencies** - added via `.addDependency()` or `.setProperty()`
199-
3. **Global context** (fallback) - shared dependencies available to all target systems
200-
201-
202-
### Key Benefits of This Architecture
203-
204-
- **Target system isolation**: Each target system has its own dependency context
205-
- **Flexible fallback**: Changes can access both system-specific and shared dependencies
206-
- **Clear precedence**: Target system dependencies always override global ones
207-
- **Type safety**: Strongly typed dependency injection with compile-time checking
160+
- Executed automatically on failure for non-transactional systems
161+
- Required for CLI/UI undo operations
162+
- Ensures every change can be reversed
208163

209-
For complete details on target system configuration vs change execution dependencies, see [Target Systems Introduction](../target-systems/introduction.md#dependency-injection).
164+
For detailed information about method parameters, dependency injection, and advanced parameter features, see [Apply and rollback methods](./apply-and-rollback-methods.md).
210165

211166

212167

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
title: Apply and rollback methods
3+
sidebar_position: 3
4+
---
5+
6+
# Apply and rollback methods
7+
8+
## Quick start
9+
10+
Your Change methods receive the dependencies they need as parameters - Flamingock automatically provides them.
11+
12+
### Basic examples
13+
14+
```java
15+
@Apply
16+
public void configureBucket(S3Client s3Client, AdminClient adminClient, FeatureFlagService flags) {
17+
18+
}
19+
20+
@Rollback
21+
public void configureBucket(S3Client s3Client, AdminClient adminClient, FeatureFlagService flags) {
22+
23+
}
24+
```
25+
26+
**Why rollback is required:**
27+
- Executed automatically on failure for non-transactional systems
28+
- Required for undo operations
29+
- Ensures every change can be reversed
30+
31+
## Where parameters come from
32+
33+
Flamingock resolves method parameters from three sources (in priority order):
34+
35+
1. **Target system context** - System-specific dependencies
36+
2. **Global context** - Shared application dependencies
37+
3. **Framework context** - e.g., Spring beans
38+
39+
The exact dependencies available depend on your target system and configuration.
40+
41+
See [Context and Dependencies](../flamingock-library-config/context-and-dependencies.md) for complete details on configuring and understanding available dependencies.
42+
43+
## Method rules
44+
45+
- **Must be public** - Flamingock needs to invoke them
46+
- **Any name works** - `apply`, `execute`, `migrate`, your choice
47+
- **Return type ignored** - Can be void or return a value
48+
- **All parameters injected** - No manual parameters
49+
50+
---
51+
52+
## Advanced topics
53+
54+
### Type-based injection
55+
56+
Parameters are injected based on their type:
57+
58+
```java
59+
@Apply
60+
public void apply(KafkaTemplate kafka, ConfigService config) {
61+
// Flamingock looks for matching types in the context
62+
}
63+
```
64+
65+
### Named parameters
66+
67+
Use `@Named` when multiple beans of the same type exist:
68+
69+
```java
70+
@Apply
71+
public void apply(
72+
@Named("orders") KafkaTemplate ordersKafka,
73+
@Named("notifications") KafkaTemplate notificationsKafka
74+
) {
75+
// Specific instances by name
76+
}
77+
```
78+
79+
### Optional parameters
80+
81+
By default, all parameters are required. Missing dependencies throw exceptions.
82+
83+
Use `@Nullable` for optional dependencies:
84+
85+
```java
86+
@Apply
87+
public void apply(
88+
S3Client s3, // Required
89+
@Nullable CacheService cache // Optional - null if not available
90+
) {
91+
if (cache != null) {
92+
cache.invalidate();
93+
}
94+
// proceed with S3 operation
95+
}
96+
```
97+
98+
### Lock-guarded dependencies
99+
100+
Flamingock uses a background daemon to automatically refresh the distributed lock, ensuring your Changes maintain exclusive access during execution. As an additional safety layer, Flamingock wraps injected dependencies with proxies that verify the lock is still valid before each method call.
101+
102+
This proxy mechanism provides extra robustness - ensuring that operations don't even start if the lock is lost for any reason (though this is very unlikely given the background refresh daemon).
103+
104+
For non-critical or local components, use `@NonLockGuarded` to skip the proxy:
105+
106+
```java
107+
@Apply
108+
public void apply(
109+
ElasticsearchClient elastic, // Lock-guarded (default)
110+
@NonLockGuarded List<String> localData // Not guarded - no proxy overhead
111+
) {
112+
// elastic calls are protected by lock validation
113+
// localData is used directly without checks
114+
}
115+
```
116+
117+
See [Lock documentation](../flamingock-library-config/lock.md) for more details on lock protection.
118+
119+
### Dependency resolution details
120+
121+
When Flamingock looks for a dependency to inject, it follows a specific hierarchy. This ensures system-specific dependencies take precedence over general ones.
122+
123+
For complete understanding of dependency resolution, see [Dependency Resolution Hierarchy](../flamingock-library-config/context-and-dependencies.md#dependency-resolution-hierarchy).
124+

docs/changes/best-practices.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Best Practices
3-
sidebar_position: 4
3+
sidebar_position: 6
44
---
55

66
# Change Best Practices

docs/changes/domain-coupling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Domain Coupling
3-
sidebar_position: 5
3+
sidebar_position: 7
44
---
55

66
# Domain Coupling and Historical Immutability

docs/changes/transactions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Transactions
3-
sidebar_position: 3
3+
sidebar_position: 4
44
---
55

66
# Transactions

docs/changes/types-and-implementation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Types & Implementation
3-
sidebar_position: 3
3+
sidebar_position: 5
44
---
55

66

0 commit comments

Comments
 (0)