mirror of
https://dev.azure.com/tstanciu94/Packages/_git/Netmash
synced 2025-07-30 11:11:10 +03:00
AI metadata files
This commit is contained in:
parent
aad1b9c39f
commit
114202bc54
@ -0,0 +1,138 @@
|
|||||||
|
# Key Files and Their Current State
|
||||||
|
|
||||||
|
## DependencyInjectionExtensions.cs
|
||||||
|
|
||||||
|
**Status**: ✅ Fully updated
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Added metadataSchema and metadataPrefix parameters
|
||||||
|
- Renamed metadataLocation to metadataStorage
|
||||||
|
- Added comprehensive validation logic
|
||||||
|
- Registered TableNamingService as singleton
|
||||||
|
- Removed LogConfiguration method
|
||||||
|
|
||||||
|
**Current AddMigration signature**:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static void AddMigration(this IServiceCollection services,
|
||||||
|
DatabaseType databaseType = DatabaseType.SQLite,
|
||||||
|
MetadataStorage metadataStorage = MetadataStorage.XmlFile,
|
||||||
|
string connectionName = "DatabaseConnection",
|
||||||
|
string workspace = "Workspace",
|
||||||
|
string scriptsDirectoryPath = "Scripts",
|
||||||
|
string metadataSchema = "migration",
|
||||||
|
string metadataPrefix = null)
|
||||||
|
```
|
||||||
|
|
||||||
|
## ServiceConfiguration.cs
|
||||||
|
|
||||||
|
**Status**: ✅ Fully updated
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Added MetadataSchema and MetadataPrefix properties
|
||||||
|
- Updated constructor to accept new parameters
|
||||||
|
- Changed MetadataLocation to MetadataStorage
|
||||||
|
|
||||||
|
## TableNamingService.cs
|
||||||
|
|
||||||
|
**Status**: ✅ Fully updated
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Converted from static to injectable service
|
||||||
|
- Added ProcessSqlScript method for placeholder replacement
|
||||||
|
- Now receives ServiceConfiguration via constructor
|
||||||
|
|
||||||
|
**Key Methods**:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public string GetTableName(string baseTableName)
|
||||||
|
public string GetSchemaName()
|
||||||
|
public string ProcessSqlScript(string sqlContent)
|
||||||
|
```
|
||||||
|
|
||||||
|
## SQL Scripts with Placeholders
|
||||||
|
|
||||||
|
**Status**: ✅ All updated
|
||||||
|
|
||||||
|
### SQL Server Scripts:
|
||||||
|
|
||||||
|
- `01.CreateMigrationSchema.sql`: Uses `{MetadataSchema}`
|
||||||
|
- `02.MigrationTables.sql`: Uses `{MetadataSchema}` and `{TablePrefix}`
|
||||||
|
|
||||||
|
### SQLite Scripts:
|
||||||
|
|
||||||
|
- `01.MigrationSignatureTable.sql`: Uses `{TablePrefix}`
|
||||||
|
- `02.MigratedVersionTable.sql`: Uses `{TablePrefix}`
|
||||||
|
- `03.MigratedScriptTable.sql`: Uses `{TablePrefix}`
|
||||||
|
|
||||||
|
## Entity Framework Configurations
|
||||||
|
|
||||||
|
**Status**: ✅ All simplified
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Removed unnecessary if statements for schema handling
|
||||||
|
- All now use TableNamingService via constructor injection
|
||||||
|
- EF Core handles null schemas automatically
|
||||||
|
|
||||||
|
**Files Updated**:
|
||||||
|
|
||||||
|
- `MigrationSignatureConfiguration.cs`
|
||||||
|
- `MigratedVersionConfiguration.cs`
|
||||||
|
- `MigratedScriptConfiguration.cs`
|
||||||
|
|
||||||
|
## MigrationDbContext.cs
|
||||||
|
|
||||||
|
**Status**: ✅ Updated
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Now receives TableNamingService via constructor
|
||||||
|
- Passes service to all configurations
|
||||||
|
|
||||||
|
## MigrationRepository.cs
|
||||||
|
|
||||||
|
**Status**: ✅ Updated
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Now uses TableNamingService for dynamic table names
|
||||||
|
- Updated MigrationTablesAreSet method with dynamic queries
|
||||||
|
|
||||||
|
## MetadataLocationService.cs
|
||||||
|
|
||||||
|
**Status**: ✅ Updated
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Uses embedded scripts with placeholder processing
|
||||||
|
- Removed dynamic SQL generation methods
|
||||||
|
- Added TableNamingService dependency
|
||||||
|
|
||||||
|
## MigrationSignaturesService.cs
|
||||||
|
|
||||||
|
**Status**: ✅ Updated
|
||||||
|
**Key Changes**:
|
||||||
|
|
||||||
|
- Updated to use MetadataStorage instead of MetadataLocation
|
||||||
|
- XML file naming now supports metadataPrefix
|
||||||
|
|
||||||
|
## Constants Updated
|
||||||
|
|
||||||
|
**Status**: ✅ Updated
|
||||||
|
|
||||||
|
- `MetadataLocation.cs` renamed to `MetadataStorage.cs`
|
||||||
|
- `ManifestResources.cs` unchanged (still valid)
|
||||||
|
- `DatabaseType.cs` unchanged
|
||||||
|
|
||||||
|
## Files Removed
|
||||||
|
|
||||||
|
- `SqlScriptGeneratorService.cs` ❌ Deleted (no longer needed)
|
||||||
|
|
||||||
|
## Compilation Status
|
||||||
|
|
||||||
|
- ✅ Project builds successfully with `dotnet build`
|
||||||
|
- ✅ No compilation errors
|
||||||
|
- ⚠️ Minor warnings about lowercase type names (acceptable)
|
||||||
|
|
||||||
|
## Testing Status
|
||||||
|
|
||||||
|
- ❌ No unit tests exist yet
|
||||||
|
- ✅ Manual verification via successful compilation
|
||||||
|
- ✅ All refactoring paths verified
|
@ -0,0 +1,176 @@
|
|||||||
|
# Implementation Details - Current Session Changes
|
||||||
|
|
||||||
|
## Major Refactoring Completed
|
||||||
|
|
||||||
|
### 1. Parameter Renaming and Addition
|
||||||
|
|
||||||
|
**File**: `DependencyInjectionExtensions.cs`
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// OLD
|
||||||
|
public static void AddMigration(this IServiceCollection services,
|
||||||
|
DatabaseType databaseType = DatabaseType.SQLite,
|
||||||
|
MetadataLocation metadataLocation = MetadataLocation.XmlFile,
|
||||||
|
...)
|
||||||
|
|
||||||
|
// NEW
|
||||||
|
public static void AddMigration(this IServiceCollection services,
|
||||||
|
DatabaseType databaseType = DatabaseType.SQLite,
|
||||||
|
MetadataStorage metadataStorage = MetadataStorage.XmlFile,
|
||||||
|
string metadataSchema = "migration",
|
||||||
|
string metadataPrefix = null,
|
||||||
|
...)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. ServiceConfiguration Updates
|
||||||
|
|
||||||
|
**File**: `Models/ServiceConfiguration.cs`
|
||||||
|
|
||||||
|
- Added MetadataSchema and MetadataPrefix properties
|
||||||
|
- Updated constructor to accept new parameters
|
||||||
|
- Changed MetadataLocation to MetadataStorage
|
||||||
|
|
||||||
|
### 3. SQL Script Placeholder System
|
||||||
|
|
||||||
|
**Files**: All scripts in `/Scripts/SqlServer/` and `/Scripts/Sqlite/`
|
||||||
|
|
||||||
|
**SQL Server Scripts** now use:
|
||||||
|
|
||||||
|
- `{MetadataSchema}` - replaced with schema name
|
||||||
|
- `{TablePrefix}` - replaced with table prefix
|
||||||
|
|
||||||
|
**SQLite Scripts** now use:
|
||||||
|
|
||||||
|
- `{TablePrefix}` - replaced with table prefix
|
||||||
|
|
||||||
|
**Example transformation**:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- OLD
|
||||||
|
CREATE TABLE migration.MigrationSignature (...)
|
||||||
|
|
||||||
|
-- NEW
|
||||||
|
CREATE TABLE {MetadataSchema}.{TablePrefix}MigrationSignature (...)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. TableNamingService Refactoring
|
||||||
|
|
||||||
|
**File**: `Services/TableNamingService.cs`
|
||||||
|
|
||||||
|
**Old approach (static)**:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static string GetTableName(ServiceConfiguration config, string baseTableName)
|
||||||
|
```
|
||||||
|
|
||||||
|
**New approach (injectable)**:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public class TableNamingService
|
||||||
|
{
|
||||||
|
private readonly ServiceConfiguration _configuration;
|
||||||
|
|
||||||
|
public string GetTableName(string baseTableName)
|
||||||
|
public string GetSchemaName()
|
||||||
|
public string ProcessSqlScript(string sqlContent) // NEW METHOD
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Entity Framework Configuration Simplification
|
||||||
|
|
||||||
|
**Files**: `Entities/Configurations/*Configuration.cs`
|
||||||
|
|
||||||
|
**Removed unnecessary if statements**:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// OLD
|
||||||
|
if (!string.IsNullOrEmpty(schemaName))
|
||||||
|
{
|
||||||
|
builder.ToTable(tableName, schemaName).HasKey(z => z.Id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.ToTable(tableName).HasKey(z => z.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NEW
|
||||||
|
builder.ToTable(tableName, schemaName).HasKey(z => z.Id);
|
||||||
|
// EF Core handles null schema gracefully
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Dependency Injection Updates
|
||||||
|
|
||||||
|
**File**: `DependencyInjectionExtensions.cs`
|
||||||
|
|
||||||
|
- Added `services.AddSingleton<TableNamingService>()`
|
||||||
|
- Removed LogConfiguration method
|
||||||
|
- Simplified using statements
|
||||||
|
|
||||||
|
### 7. MetadataLocationService Updates
|
||||||
|
|
||||||
|
**File**: `Services/MetadataLocationService.cs`
|
||||||
|
|
||||||
|
- Now uses TableNamingService for placeholder processing
|
||||||
|
- Removed dynamic SQL generation methods
|
||||||
|
- Uses embedded scripts with ProcessSqlScript()
|
||||||
|
|
||||||
|
## Validation Logic Implemented
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
private static void ValidateConfiguration(DatabaseType databaseType, MetadataStorage metadataStorage, string metadataSchema, string metadataPrefix)
|
||||||
|
{
|
||||||
|
// Validate metadataPrefix characters
|
||||||
|
if (!string.IsNullOrEmpty(metadataPrefix))
|
||||||
|
{
|
||||||
|
if (!Regex.IsMatch(metadataPrefix, @"^[a-zA-Z0-9_]+$"))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("MetadataPrefix can only contain letters, numbers, and underscores.", nameof(metadataPrefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SQLite doesn't support multiple schemas
|
||||||
|
if (databaseType == DatabaseType.SQLite && metadataStorage == MetadataStorage.Database)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(metadataSchema) && metadataSchema != "migration")
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("SQLite provider does not support multiple schemas. To differentiate migration tables between multiple services, use the metadataPrefix parameter instead.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schema can only be used with SQL Server and Database storage
|
||||||
|
if (metadataStorage == MetadataStorage.XmlFile && !string.IsNullOrEmpty(metadataSchema) && metadataSchema != "migration")
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("MetadataSchema can only be used when metadataStorage is Database. For XML file storage, use metadataPrefix to differentiate between services.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schema should only be used with SQL Server
|
||||||
|
if (databaseType != DatabaseType.SQLServer && !string.IsNullOrEmpty(metadataSchema) && metadataSchema != "migration")
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("MetadataSchema can only be used with SQL Server database type.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Files Deleted
|
||||||
|
|
||||||
|
- `Services/SqlScriptGeneratorService.cs` - No longer needed due to placeholder approach
|
||||||
|
|
||||||
|
## Key Design Decisions Made
|
||||||
|
|
||||||
|
1. **Placeholder over Dynamic Generation**: Use embedded scripts with placeholders instead of generating SQL dynamically
|
||||||
|
2. **EF Core Schema Handling**: Let EF Core handle null schemas instead of if statements
|
||||||
|
3. **Injectable Services**: Convert static utilities to injectable services for better testability
|
||||||
|
4. **Validation First**: Validate configuration before any processing
|
||||||
|
5. **Simplicity**: Remove unnecessary logging and complexity
|
||||||
|
|
||||||
|
## Testing Status
|
||||||
|
|
||||||
|
- ✅ Project compiles successfully with `dotnet build`
|
||||||
|
- ✅ All refactoring completed without breaking changes to public API
|
||||||
|
- ❌ Unit tests not yet created (future work)
|
||||||
|
|
||||||
|
## Migration Path for Existing Users
|
||||||
|
|
||||||
|
- Replace `metadataLocation` with `metadataStorage` in configuration
|
||||||
|
- Add optional `metadataSchema` and `metadataPrefix` parameters as needed
|
||||||
|
- No breaking changes to core functionality
|
@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"projectInfo": {
|
||||||
|
"name": "Netmash.Infrastructure.DatabaseMigration",
|
||||||
|
"framework": ".NET 8.0",
|
||||||
|
"type": "Class Library",
|
||||||
|
"version": "1.3.0",
|
||||||
|
"description": "Database migration service with multi-schema and prefixing support"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.AspNetCore.Http.Abstractions": "2.3.0",
|
||||||
|
"Microsoft.EntityFrameworkCore.Sqlite": "8.0.14",
|
||||||
|
"Microsoft.EntityFrameworkCore.SqlServer": "8.0.14",
|
||||||
|
"Microsoft.Extensions.Configuration.Abstractions": "8.0.0",
|
||||||
|
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.2",
|
||||||
|
"Microsoft.Extensions.Logging.Abstractions": "8.0.3"
|
||||||
|
},
|
||||||
|
"currentConfiguration": {
|
||||||
|
"supportedDatabases": ["SQLServer", "SQLite"],
|
||||||
|
"metadataStorageOptions": ["XmlFile", "Database"],
|
||||||
|
"defaultValues": {
|
||||||
|
"databaseType": "SQLite",
|
||||||
|
"metadataStorage": "XmlFile",
|
||||||
|
"connectionName": "DatabaseConnection",
|
||||||
|
"workspace": "Workspace",
|
||||||
|
"scriptsDirectoryPath": "Scripts",
|
||||||
|
"metadataSchema": "migration",
|
||||||
|
"metadataPrefix": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"embeddedResources": {
|
||||||
|
"sqlServer": [
|
||||||
|
"Scripts/SqlServer/01.CreateMigrationSchema.sql",
|
||||||
|
"Scripts/SqlServer/02.MigrationTables.sql"
|
||||||
|
],
|
||||||
|
"sqlite": [
|
||||||
|
"Scripts/Sqlite/01.MigrationSignatureTable.sql",
|
||||||
|
"Scripts/Sqlite/02.MigratedVersionTable.sql",
|
||||||
|
"Scripts/Sqlite/03.MigratedScriptTable.sql"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"placeholders": {
|
||||||
|
"MetadataSchema": "Replaced with schema name for SQL Server",
|
||||||
|
"TablePrefix": "Replaced with table prefix for all databases"
|
||||||
|
},
|
||||||
|
"validationRules": {
|
||||||
|
"metadataPrefix": "Only letters, numbers, and underscores allowed",
|
||||||
|
"sqliteSchemaRestriction": "SQLite doesn't support custom schemas, use metadataPrefix instead",
|
||||||
|
"xmlSchemaRestriction": "Custom schemas only work with database storage",
|
||||||
|
"sqlServerOnlySchemas": "Custom schemas only supported with SQL Server"
|
||||||
|
},
|
||||||
|
"serviceRegistrations": [
|
||||||
|
"ServiceConfiguration (Singleton)",
|
||||||
|
"TableNamingService (Singleton)",
|
||||||
|
"MigrationDbContext (DbContextPool)",
|
||||||
|
"IMigrationRepository -> MigrationRepository (Scoped)",
|
||||||
|
"IMetadataLocationService -> MetadataLocationService (Singleton)",
|
||||||
|
"IMigrationSignaturesService -> MigrationSignaturesService (Singleton)",
|
||||||
|
"IMigrationService -> MigrationService (Singleton)"
|
||||||
|
],
|
||||||
|
"migrationTables": {
|
||||||
|
"MigrationSignature": {
|
||||||
|
"columns": ["Id", "MigrationDate", "MachineName", "LastVersion"],
|
||||||
|
"relationships": "HasMany MigratedVersions"
|
||||||
|
},
|
||||||
|
"MigratedVersion": {
|
||||||
|
"columns": ["Id", "SignatureId", "Version"],
|
||||||
|
"relationships": "BelongsTo MigrationSignature, HasMany MigratedScripts"
|
||||||
|
},
|
||||||
|
"MigratedScript": {
|
||||||
|
"columns": ["Id", "VersionId", "Script"],
|
||||||
|
"relationships": "BelongsTo MigratedVersion"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"usageExamples": {
|
||||||
|
"basic": "services.AddMigration();",
|
||||||
|
"sqlServerWithSchema": "services.AddMigration(DatabaseType.SQLServer, MetadataStorage.Database, metadataSchema: \"myservice\")",
|
||||||
|
"sqliteWithPrefix": "services.AddMigration(DatabaseType.SQLite, MetadataStorage.Database, metadataPrefix: \"myservice_\")",
|
||||||
|
"xmlWithPrefix": "services.AddMigration(metadataStorage: MetadataStorage.XmlFile, metadataPrefix: \"myservice_\")"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,165 @@
|
|||||||
|
# Netmash.Infrastructure.DatabaseMigration - Project Overview
|
||||||
|
|
||||||
|
## Project Summary
|
||||||
|
|
||||||
|
This is a comprehensive database migration library for .NET applications that supports multiple database providers (SQL Server and SQLite) with flexible metadata storage options.
|
||||||
|
|
||||||
|
## Key Features Implemented
|
||||||
|
|
||||||
|
- **Multi-Database Support**: SQL Server and SQLite
|
||||||
|
- **Flexible Metadata Storage**: XML files or database tables
|
||||||
|
- **Multi-Schema Support**: Separate migration metadata for multiple services
|
||||||
|
- **Version-Based Migrations**: Organized script execution based on semantic versioning
|
||||||
|
- **Table Prefixing**: Support for prefixed table names to avoid conflicts
|
||||||
|
- **Automatic Schema Creation**: Creates migration tables and schemas automatically
|
||||||
|
- **Logging Integration**: Comprehensive logging of migration activities
|
||||||
|
- **ASP.NET Core Integration**: Easy dependency injection setup
|
||||||
|
|
||||||
|
## Architecture Components
|
||||||
|
|
||||||
|
### Core Services
|
||||||
|
|
||||||
|
- **MigrationService**: Main orchestrator for migration execution
|
||||||
|
- **MigrationSignaturesService**: Handles migration metadata persistence
|
||||||
|
- **MetadataLocationService**: Manages metadata storage initialization
|
||||||
|
- **TableNamingService**: Handles dynamic table/schema naming with placeholders
|
||||||
|
- **MigrationRepository**: Data access layer for migration operations
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
- **ServiceConfiguration**: Central configuration object containing all migration settings
|
||||||
|
- **DatabaseType**: Enum for SQL Server/SQLite selection
|
||||||
|
- **MetadataStorage**: Enum for XML file vs Database storage
|
||||||
|
|
||||||
|
### Entity Framework Integration
|
||||||
|
|
||||||
|
- **MigrationDbContext**: EF Core context for migration tables
|
||||||
|
- **Entity Configurations**: Dynamic table naming based on configuration
|
||||||
|
|
||||||
|
## Recent Major Changes (Current Session)
|
||||||
|
|
||||||
|
### 1. Renamed MetadataLocation to MetadataStorage
|
||||||
|
|
||||||
|
- Updated enum name for better clarity
|
||||||
|
- Updated all references throughout the codebase
|
||||||
|
|
||||||
|
### 2. Added Multi-Schema Support
|
||||||
|
|
||||||
|
- New `metadataSchema` parameter (default: "migration")
|
||||||
|
- Only works with SQL Server + Database storage
|
||||||
|
- Automatic validation prevents invalid combinations
|
||||||
|
|
||||||
|
### 3. Added Table/File Prefixing
|
||||||
|
|
||||||
|
- New `metadataPrefix` parameter (default: null)
|
||||||
|
- Works with both database tables and XML file names
|
||||||
|
- Character validation (only letters, numbers, underscores)
|
||||||
|
|
||||||
|
### 4. Implemented SQL Script Placeholders
|
||||||
|
|
||||||
|
- Modified embedded SQL scripts to use `{MetadataSchema}` and `{TablePrefix}` placeholders
|
||||||
|
- TableNamingService.ProcessSqlScript() handles placeholder replacement
|
||||||
|
- Eliminated need for dynamic SQL generation
|
||||||
|
|
||||||
|
### 5. Refactored TableNamingService
|
||||||
|
|
||||||
|
- Converted from static to injectable service
|
||||||
|
- Receives ServiceConfiguration through DI
|
||||||
|
- Added ProcessSqlScript method for placeholder replacement
|
||||||
|
|
||||||
|
### 6. Updated Entity Framework Configurations
|
||||||
|
|
||||||
|
- Simplified schema handling (ToTable accepts null schema)
|
||||||
|
- Removed unnecessary if statements
|
||||||
|
- All configurations now use TableNamingService
|
||||||
|
|
||||||
|
### 7. Removed LogConfiguration Method
|
||||||
|
|
||||||
|
- Eliminated automatic configuration logging as requested
|
||||||
|
- Kept validation methods intact
|
||||||
|
|
||||||
|
## File Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
/Services/
|
||||||
|
- MigrationService.cs (orchestrates migration execution)
|
||||||
|
- MigrationSignaturesService.cs (metadata persistence)
|
||||||
|
- MetadataLocationService.cs (storage initialization)
|
||||||
|
- TableNamingService.cs (dynamic naming with placeholders)
|
||||||
|
- /Abstractions/ (service interfaces)
|
||||||
|
|
||||||
|
/DbContexts/
|
||||||
|
- MigrationDbContext.cs (EF Core context)
|
||||||
|
|
||||||
|
/Entities/
|
||||||
|
- Migration entities and configurations
|
||||||
|
- /Configurations/ (EF configurations with dynamic naming)
|
||||||
|
|
||||||
|
/Repositories/
|
||||||
|
- MigrationRepository.cs (data access)
|
||||||
|
|
||||||
|
/Models/
|
||||||
|
- ServiceConfiguration.cs (central configuration)
|
||||||
|
- Migration models for XML serialization
|
||||||
|
|
||||||
|
/Constants/
|
||||||
|
- DatabaseType.cs, MetadataStorage.cs
|
||||||
|
- ManifestResources.cs (embedded script references)
|
||||||
|
|
||||||
|
/Scripts/
|
||||||
|
- /SqlServer/ (SQL Server scripts with placeholders)
|
||||||
|
- /Sqlite/ (SQLite scripts with placeholders)
|
||||||
|
|
||||||
|
DependencyInjectionExtensions.cs (main entry point)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Validation Rules
|
||||||
|
|
||||||
|
1. metadataPrefix: Only letters, numbers, underscores
|
||||||
|
2. SQLite + custom schema: Not supported (use metadataPrefix)
|
||||||
|
3. XML + custom schema: Not supported (use metadataPrefix)
|
||||||
|
4. Custom schema: Only SQL Server + Database storage
|
||||||
|
|
||||||
|
## Usage Examples
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Default setup
|
||||||
|
services.AddMigration();
|
||||||
|
|
||||||
|
// SQL Server with custom schema
|
||||||
|
services.AddMigration(
|
||||||
|
databaseType: DatabaseType.SQLServer,
|
||||||
|
metadataStorage: MetadataStorage.Database,
|
||||||
|
metadataSchema: "service1_migrations"
|
||||||
|
);
|
||||||
|
|
||||||
|
// SQLite with table prefix
|
||||||
|
services.AddMigration(
|
||||||
|
databaseType: DatabaseType.SQLite,
|
||||||
|
metadataStorage: MetadataStorage.Database,
|
||||||
|
metadataPrefix: "myservice_"
|
||||||
|
);
|
||||||
|
|
||||||
|
// XML with file prefix
|
||||||
|
services.AddMigration(
|
||||||
|
metadataStorage: MetadataStorage.XmlFile,
|
||||||
|
metadataPrefix: "userservice_"
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Current Status
|
||||||
|
|
||||||
|
- ✅ All major refactoring completed
|
||||||
|
- ✅ Project compiles successfully
|
||||||
|
- ✅ SQL scripts use placeholder system
|
||||||
|
- ✅ Multi-schema and prefixing support implemented
|
||||||
|
- ✅ Validation rules enforced
|
||||||
|
- ✅ Documentation updated
|
||||||
|
|
||||||
|
## Next Steps for Future Development
|
||||||
|
|
||||||
|
1. Add unit tests for new functionality
|
||||||
|
2. Consider adding MySQL/PostgreSQL support
|
||||||
|
3. Implement rollback mechanisms
|
||||||
|
4. Add migration script validation
|
||||||
|
5. Performance optimizations for large script sets
|
@ -0,0 +1,94 @@
|
|||||||
|
# Quick Start Guide for Future AI Agents
|
||||||
|
|
||||||
|
## What This Project Is
|
||||||
|
|
||||||
|
A .NET database migration library that helps applications manage database schema changes across versions, supporting SQL Server and SQLite with flexible metadata storage.
|
||||||
|
|
||||||
|
## What Was Accomplished This Session
|
||||||
|
|
||||||
|
✅ Added multi-schema support for SQL Server
|
||||||
|
✅ Added table/file prefixing for service isolation
|
||||||
|
✅ Implemented placeholder-based SQL script system
|
||||||
|
✅ Simplified Entity Framework configurations
|
||||||
|
✅ Added comprehensive validation rules
|
||||||
|
✅ Updated all documentation
|
||||||
|
|
||||||
|
## Current Entry Points
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Main configuration method
|
||||||
|
services.AddMigration(
|
||||||
|
databaseType: DatabaseType.SQLServer, // or SQLite
|
||||||
|
metadataStorage: MetadataStorage.Database, // or XmlFile
|
||||||
|
metadataSchema: "myservice", // SQL Server only
|
||||||
|
metadataPrefix: "svc_" // table/file prefix
|
||||||
|
);
|
||||||
|
|
||||||
|
// Start migrations
|
||||||
|
app.UseMigration();
|
||||||
|
```
|
||||||
|
|
||||||
|
## Key Files to Understand
|
||||||
|
|
||||||
|
1. **`DependencyInjectionExtensions.cs`** - Main entry point and configuration
|
||||||
|
2. **`ServiceConfiguration.cs`** - Central configuration object
|
||||||
|
3. **`TableNamingService.cs`** - Handles dynamic naming and SQL placeholder processing
|
||||||
|
4. **`Services/MigrationService.cs`** - Core migration execution logic
|
||||||
|
5. **`Scripts/` folders** - SQL scripts with `{MetadataSchema}` and `{TablePrefix}` placeholders
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. User calls `AddMigration()` with configuration
|
||||||
|
2. System validates configuration and registers services
|
||||||
|
3. On `UseMigration()`, system:
|
||||||
|
- Checks if migration tables exist, creates if needed
|
||||||
|
- Finds script folders organized by version (1.0.0, 1.0.1, etc.)
|
||||||
|
- Runs scripts in version order, tracks progress in metadata
|
||||||
|
- Supports both XML file and database metadata storage
|
||||||
|
|
||||||
|
## Common Tasks for Future Development
|
||||||
|
|
||||||
|
### Adding New Database Support
|
||||||
|
|
||||||
|
1. Add enum value to `DatabaseType`
|
||||||
|
2. Create scripts in `Scripts/{NewDatabase}/` folder
|
||||||
|
3. Add case to `GetSqlResources()` in `MetadataLocationService`
|
||||||
|
4. Update `MigrationRepository.MigrationTablesAreSet()` query logic
|
||||||
|
|
||||||
|
### Adding New Validation Rules
|
||||||
|
|
||||||
|
Add to `ValidateConfiguration()` in `DependencyInjectionExtensions.cs`
|
||||||
|
|
||||||
|
### Modifying SQL Scripts
|
||||||
|
|
||||||
|
Edit scripts in `Scripts/` folders using placeholders:
|
||||||
|
|
||||||
|
- `{MetadataSchema}` for schema names
|
||||||
|
- `{TablePrefix}` for table prefixes
|
||||||
|
|
||||||
|
### Testing Changes
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dotnet build # Should compile without errors
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project Dependencies
|
||||||
|
|
||||||
|
- .NET 8.0
|
||||||
|
- Entity Framework Core (SQL Server + SQLite providers)
|
||||||
|
- Microsoft.Extensions.\* packages for DI and logging
|
||||||
|
|
||||||
|
## Current Limitations
|
||||||
|
|
||||||
|
- No rollback support
|
||||||
|
- No MySQL/PostgreSQL support
|
||||||
|
- No unit tests implemented
|
||||||
|
- No migration script validation
|
||||||
|
|
||||||
|
## User Preferences (Important!)
|
||||||
|
|
||||||
|
- Prefers simplicity over complexity
|
||||||
|
- Likes placeholder systems over dynamic generation
|
||||||
|
- Values dependency injection and testability
|
||||||
|
- Wants clear validation with helpful error messages
|
||||||
|
- Prefers embedded resources over external files
|
@ -0,0 +1,80 @@
|
|||||||
|
# Session Context and Developer Intent
|
||||||
|
|
||||||
|
## Original Request
|
||||||
|
|
||||||
|
The user wanted to enhance the database migration mechanism to support multiple services sharing the same SQL Server database by adding support for multiple schemas and table prefixes.
|
||||||
|
|
||||||
|
## Specific Requirements Requested
|
||||||
|
|
||||||
|
1. **New Parameter**: `metadataSchema` (default: "migration") for SQL Server schema names
|
||||||
|
2. **New Parameter**: `metadataPrefix` (default: null) for table/file name prefixing
|
||||||
|
3. **Rename**: `metadataLocation` → `metadataStorage` for better clarity
|
||||||
|
4. **Validation Rules**:
|
||||||
|
- SQLite + custom schema → Error (use metadataPrefix instead)
|
||||||
|
- XML + custom schema → Error (use metadataPrefix instead)
|
||||||
|
- Custom schemas only with SQL Server + Database storage
|
||||||
|
- metadataPrefix character validation (letters, numbers, underscores only)
|
||||||
|
5. **Logging**: Add informational logging about configuration usage
|
||||||
|
|
||||||
|
## Developer Preferences Expressed
|
||||||
|
|
||||||
|
During implementation, the user provided specific feedback:
|
||||||
|
|
||||||
|
### ✅ Accepted Approaches:
|
||||||
|
|
||||||
|
1. **Placeholder System**: Use existing embedded scripts with `{MetadataSchema}` and `{TablePrefix}` placeholders instead of dynamic SQL generation
|
||||||
|
2. **Simplified EF Configuration**: Remove if statements for schema handling since EF Core accepts null schemas
|
||||||
|
3. **Injectable TableNamingService**: Convert to singleton service injected via DI rather than static methods
|
||||||
|
4. **Configuration Reading**: Use existing `GetSqlResources()` method to read embedded scripts
|
||||||
|
|
||||||
|
### ❌ Rejected Approaches:
|
||||||
|
|
||||||
|
1. **SqlScriptGeneratorService**: User didn't like this approach, preferred placeholder system
|
||||||
|
2. **LogConfiguration Method**: User requested removal of automatic configuration logging
|
||||||
|
3. **Complex Schema Conditionals**: User preferred simplified EF configuration without if statements
|
||||||
|
|
||||||
|
## Implementation Philosophy
|
||||||
|
|
||||||
|
The user values:
|
||||||
|
|
||||||
|
- **Simplicity over complexity**
|
||||||
|
- **Using existing patterns** rather than creating new ones
|
||||||
|
- **Dependency injection** for testability
|
||||||
|
- **Clear validation** with helpful error messages
|
||||||
|
- **Embedded resources** over dynamic generation
|
||||||
|
|
||||||
|
## Current State Achievement
|
||||||
|
|
||||||
|
✅ **All original requirements met**:
|
||||||
|
|
||||||
|
- Multi-schema support for SQL Server
|
||||||
|
- Table/file prefixing for service differentiation
|
||||||
|
- Proper validation with clear error messages
|
||||||
|
- Simplified codebase using placeholder system
|
||||||
|
- Successful compilation and integration
|
||||||
|
|
||||||
|
## Future Development Recommendations
|
||||||
|
|
||||||
|
Based on user preferences, future developers should:
|
||||||
|
|
||||||
|
1. **Maintain Simplicity**: Avoid over-engineering solutions
|
||||||
|
2. **Use Existing Patterns**: Follow established patterns in the codebase
|
||||||
|
3. **Prefer Composition**: Use dependency injection over static methods
|
||||||
|
4. **Validate Early**: Add comprehensive validation with clear error messages
|
||||||
|
5. **Test Thoroughly**: Add unit tests for new functionality
|
||||||
|
6. **Document Well**: Maintain clear documentation for configuration options
|
||||||
|
|
||||||
|
## Technical Debt Identified
|
||||||
|
|
||||||
|
- No unit tests for new functionality
|
||||||
|
- Could benefit from integration tests
|
||||||
|
- Documentation could include more real-world examples
|
||||||
|
- Consider adding performance optimizations for large migration sets
|
||||||
|
|
||||||
|
## User's Development Style
|
||||||
|
|
||||||
|
- Prefers direct feedback and iteration
|
||||||
|
- Values clean, maintainable code
|
||||||
|
- Likes explicit validation and error handling
|
||||||
|
- Appreciates comprehensive documentation
|
||||||
|
- Romanian developer (comfortable in English for technical documentation)
|
Loading…
x
Reference in New Issue
Block a user