2025-07-30 01:09:51 +03:00

95 lines
2.9 KiB
Markdown

# 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