# SQL Objects Management

EF Core does NOT generate DDL for TVFs, views, and stored procedures.
SQL source scripts are in `Persistence/SqlObjects/` (Embedded Resources, `CREATE OR ALTER`).

## Automatic Startup Deployment

SQL objects are applied **automatically at application startup** via `SqlObjectHelper.ApplyAllAsync(dbContext)` in `SmartStackExtensions.InitializeSmartStackAsync()`, right after `MigrateAsync()`.

**No migration injection is needed.** To add or modify a SQL object:

1. Create or edit the `.sql` file in `Persistence/SqlObjects/{Functions,Views,StoredProcedures}/`
2. Ensure it uses `CREATE OR ALTER` (idempotent)
3. Ensure `.csproj` has `<EmbeddedResource Include="Persistence\SqlObjects\**\*.sql" />`
4. Restart the application — the SQL object is deployed automatically

## Legacy Note

Older migrations may still contain `SqlObjectHelper.ApplyAll(migrationBuilder)` calls. These are harmless (idempotent) but no longer required. New migrations should NOT include this call.
