# Umbraco.Cms.Persistence.EFCore.Sqlite

SQLite-specific EF Core provider for Umbraco CMS. Contains SQLite migrations and provider setup for the EF Core persistence layer.

**Project Type**: Class Library (NuGet package)
**Target Framework**: net10.0
**Dependencies**: Umbraco.Cms.Persistence.EFCore

---

## 1. Architecture

### Project Purpose

This is a thin provider project that implements SQLite-specific functionality for the EF Core persistence layer:

1. **Migration Provider** - Executes SQLite-specific migrations
2. **Migration Provider Setup** - Configures DbContext to use SQLite
3. **Migrations** - SQLite-specific migration files for OpenIddict tables

### Folder Structure

```
Umbraco.Cms.Persistence.EFCore.Sqlite/
├── Migrations/
│   ├── 20230622183638_InitialCreate.cs          # No-op (NPoco creates tables)
│   ├── 20230807123456_AddOpenIddict.cs          # OpenIddict tables
│   ├── 20240403141051_UpdateOpenIddictToV5.cs   # OpenIddict v5 schema
│   ├── 20251006140958_UpdateOpenIddictToV7.cs   # OpenIddict v7 (no-op for SQLite)
│   └── UmbracoDbContextModelSnapshot.cs         # Current model state
├── EFCoreSqliteComposer.cs                       # DI registration
├── SqliteMigrationProvider.cs                    # IMigrationProvider impl
└── SqliteMigrationProviderSetup.cs               # IMigrationProviderSetup impl
```

### Relationship with Parent Project

This project extends `Umbraco.Cms.Persistence.EFCore`:

- Implements `IMigrationProvider` interface defined in parent
- Implements `IMigrationProviderSetup` interface defined in parent
- Uses `UmbracoDbContext` from parent project
- Provider name: `Microsoft.Data.Sqlite` (from `Constants.ProviderNames.SQLLite`)

---

## 2. Commands

**For Git workflow and build commands**, see [repository root](../../CLAUDE.md).
**For EF Core migration commands**, see [parent project](../Umbraco.Cms.Persistence.EFCore/CLAUDE.md) (substitute `-p src/Umbraco.Cms.Persistence.EFCore.Sqlite`).

---

## 3. Key Components

### EFCoreSqliteComposer (line 10-14)

Registers `IMigrationProvider` and `IMigrationProviderSetup` for SQLite.

### SqliteMigrationProvider

- `MigrateAsync(EFCoreMigration)` - Runs specific named migration
- `MigrateAllAsync()` - Runs all pending migrations
- **Critical**: Cannot run `MigrateAllAsync` when transaction is active (line 26-29)

### SqliteMigrationProviderSetup (line 11-14)

Configures `DbContextOptionsBuilder` with `UseSqlite` and migrations assembly.

---

## 4. Migrations

### Migration History

| Migration | Date | Purpose |
|-----------|------|---------|
| `InitialCreate` | 2023-06-22 | No-op - NPoco creates base tables |
| `AddOpenIddict` | 2023-08-07 | Creates OpenIddict tables (Applications, Tokens, Authorizations, Scopes) |
| `UpdateOpenIddictToV5` | 2024-04-03 | Schema updates for OpenIddict v5 |
| `UpdateOpenIddictToV7` | 2025-10-06 | No-op for SQLite (no schema changes needed) |

### OpenIddict Tables Created

All tables prefixed with `umbraco`:
- `umbracoOpenIddictApplications` - OAuth client applications
- `umbracoOpenIddictAuthorizations` - User authorizations
- `umbracoOpenIddictScopes` - OAuth scopes
- `umbracoOpenIddictTokens` - Access/refresh tokens

### SQLite-Specific Notes

- **TEXT column type** - SQLite uses TEXT for all strings (no varchar)
- **InitialCreate is no-op** - NPoco creates base tables, EF Core manages OpenIddict only
- **v7 migration is no-op** - SQLite didn't require schema changes that SQL Server needed

### Adding New Migrations

1. Configure SQLite connection string in `src/Umbraco.Web.UI/appsettings.json`
2. Run migration command from repository root (see parent project docs)
3. **Critical**: Also add equivalent migration to `Umbraco.Cms.Persistence.EFCore.SqlServer`
4. Update `SqliteMigrationProvider.GetMigrationType()` switch (line 34-42) if adding named migrations

---

## 5. Project-Specific Notes

### Named Migration Mapping

`SqliteMigrationProvider.GetMigrationType()` (line 34-42) maps `EFCoreMigration` enum to migration types. When adding named migrations, update both the parent project's enum and this switch.

### Auto-Generated Files

`UmbracoDbContextModelSnapshot.cs` is regenerated by EF Core - do not edit manually.

---

## Quick Reference

### Essential Files

| File | Purpose |
|------|---------|
| `SqliteMigrationProvider.cs` | Migration execution |
| `SqliteMigrationProviderSetup.cs` | DbContext configuration |
| `EFCoreSqliteComposer.cs` | DI registration |
| `Migrations/*.cs` | Migration files |

### Provider Name
`Constants.ProviderNames.SQLLite` = `"Microsoft.Data.Sqlite"`

### Related Projects
- **Parent**: `Umbraco.Cms.Persistence.EFCore` - Interfaces and base DbContext
- **Sibling**: `Umbraco.Cms.Persistence.EFCore.SqlServer` - SQL Server equivalent
