|
5 | 5 |
|
6 | 6 | --- |
7 | 7 |
|
| 8 | +## 0. Short Answer for the Most Common Question |
| 9 | + |
| 10 | +**Question:** Does FluentMigrator only work with a remote SharpCoreDB server because the built-in `ISharpCoreDbMigrationSqlExecutor` implementation is the gRPC one? |
| 11 | + |
| 12 | +**Answer:** **No. Embedded mode is fully supported.** |
| 13 | + |
| 14 | +The gRPC executor is only the built-in implementation of the **optional custom executor extension point**. It is used for **remote** execution scenarios. |
| 15 | + |
| 16 | +For **embedded/in-process** execution, FluentMigrator does **not** require any `ISharpCoreDbMigrationSqlExecutor` registration. The migration pipeline runs directly against: |
| 17 | + |
| 18 | +1. `IDatabase` (preferred embedded path) |
| 19 | +2. `DbConnection` (fallback path) |
| 20 | + |
| 21 | +If your application registers SharpCoreDB locally and calls `AddSharpCoreDBFluentMigrator(...)`, migrations execute locally in-process without gRPC. |
| 22 | + |
| 23 | +--- |
| 24 | + |
8 | 25 | ## 1. What Embedded Mode Means |
9 | 26 |
|
10 | 27 | Embedded mode runs migrations directly against a local SharpCoreDB engine instance in the same process. |
@@ -37,6 +54,43 @@ builder.Services.AddSharpCoreDBFluentMigrator(runner => |
37 | 54 | }); |
38 | 55 | ``` |
39 | 56 |
|
| 57 | +### What must be registered for embedded execution |
| 58 | + |
| 59 | +`AddSharpCoreDBFluentMigrator(...)` registers the FluentMigrator processor integration, but it does **not** force a remote client path. |
| 60 | + |
| 61 | +Embedded execution works when the DI container can resolve one of these local execution sources: |
| 62 | + |
| 63 | +- `IDatabase` |
| 64 | +- `DbConnection` |
| 65 | + |
| 66 | +That means this is valid embedded usage: |
| 67 | + |
| 68 | +```csharp |
| 69 | +using FluentMigrator.Runner; |
| 70 | +using SharpCoreDB.Extensions.Extensions; |
| 71 | +using SharpCoreDB.Interfaces; |
| 72 | + |
| 73 | +builder.Services.AddSingleton<IDatabase>(database); |
| 74 | +builder.Services.AddSharpCoreDBFluentMigrator(runner => |
| 75 | +{ |
| 76 | + runner.ScanIn(typeof(Program).Assembly).For.Migrations(); |
| 77 | +}); |
| 78 | +``` |
| 79 | + |
| 80 | +A custom `ISharpCoreDbMigrationSqlExecutor` is optional and should only be added when you intentionally want to override SQL execution behavior. |
| 81 | + |
| 82 | +### Why the API can look misleading at first |
| 83 | + |
| 84 | +Users often inspect the package and notice that the only built-in `ISharpCoreDbMigrationSqlExecutor` implementation is the gRPC one. |
| 85 | + |
| 86 | +That does **not** mean FluentMigrator is remote-only. |
| 87 | + |
| 88 | +It means: |
| 89 | + |
| 90 | +- the custom executor interface is an extension point |
| 91 | +- the current built-in custom executor implementation targets remote gRPC execution |
| 92 | +- embedded execution uses `IDatabase` or `DbConnection` directly instead of going through that custom interface |
| 93 | + |
40 | 94 | ### Recommended startup execution |
41 | 95 |
|
42 | 96 | ```csharp |
@@ -119,11 +173,21 @@ public sealed class CreateUsersTableMigration : Migration |
119 | 173 |
|
120 | 174 | ### Resolution order in `SharpCoreDbMigrationExecutor` |
121 | 175 |
|
| 176 | +`SharpCoreDbMigrationExecutor` resolves the execution target in this order: |
| 177 | + |
122 | 178 | 1. `ISharpCoreDbMigrationSqlExecutor` (custom override, if registered) |
123 | | -2. `IDatabase` (embedded engine path) |
| 179 | +2. `IDatabase` (normal embedded engine path) |
124 | 180 | 3. `DbConnection` fallback |
125 | 181 |
|
126 | | -If you only use `AddSharpCoreDBFluentMigrator(...)` and embedded database DI, path (2) is used. |
| 182 | +This design allows one integration pipeline to support both local and remote execution models. |
| 183 | + |
| 184 | +### What happens when no custom executor is registered |
| 185 | + |
| 186 | +If you only use `AddSharpCoreDBFluentMigrator(...)` and register an embedded SharpCoreDB `IDatabase`, the executor uses the `IDatabase` path directly. |
| 187 | + |
| 188 | +No gRPC client is created. |
| 189 | +No network hop is required. |
| 190 | +No remote server dependency is introduced. |
127 | 191 |
|
128 | 192 | ### Transaction model |
129 | 193 |
|
@@ -151,8 +215,19 @@ Cause: |
151 | 215 |
|
152 | 216 | Fix: |
153 | 217 | - Register SharpCoreDB database services before `AddSharpCoreDBFluentMigrator(...)`. |
| 218 | +- For embedded scenarios, prefer registering `IDatabase`. |
| 219 | + |
| 220 | +### B) "I do not see an embedded migration SQL executor implementation" |
| 221 | + |
| 222 | +Cause: |
| 223 | +- You are looking at the custom executor extension point and assuming every execution mode must implement it. |
| 224 | + |
| 225 | +Fix: |
| 226 | +- Use `AddSharpCoreDBFluentMigrator(...)` for embedded mode. |
| 227 | +- Ensure `IDatabase` or `DbConnection` is registered. |
| 228 | +- Only use `AddSharpCoreDBFluentMigratorGrpc(...)` when you explicitly want remote execution over gRPC. |
154 | 229 |
|
155 | | -### B) Migration expression not supported |
| 230 | +### C) Migration expression not supported |
156 | 231 |
|
157 | 232 | Cause: |
158 | 233 | - Expression translates to SQL not supported by the current engine behavior. |
|
161 | 236 | - Rewrite migration to equivalent supported SQL operations. |
162 | 237 | - For advanced custom behavior, use explicit SQL in migration steps. |
163 | 238 |
|
164 | | -### C) Version table missing |
| 239 | +### D) Version table missing |
165 | 240 |
|
166 | 241 | Cause: |
167 | 242 | - Processor not initialized in the migration pipeline. |
|
174 | 249 | ## 8. Production Checklist (Embedded) |
175 | 250 |
|
176 | 251 | - [ ] `AddSharpCoreDBFluentMigrator(...)` is registered. |
| 252 | +- [ ] Embedded `IDatabase` or `DbConnection` is registered in DI. |
| 253 | +- [ ] No remote gRPC executor is registered unless intentionally overriding execution behavior. |
177 | 254 | - [ ] Migrations are scanned from correct assembly. |
178 | 255 | - [ ] Startup path executes `MigrateUp()` exactly once. |
179 | 256 | - [ ] Backup/restore strategy exists before schema upgrades. |
|
0 commit comments