Files
pgsql-jellyfin/docs/database/jellyfin-database-readme.md
T
wjones c76853a442 PostgreSQL: Production fixes—UPSERT, remote backup, auth logs
- Fix: Atomic UPSERT for BaseItemProviders (resolves duplicate key errors during concurrent metadata refresh; clears navigation property to prevent EF Core tracking conflicts)
- Add: Remote PostgreSQL backup support (removes localhost-only restriction; works with pg_dump/pg_restore for both local and remote DBs)
- Add: Configurable backup disable option (`disable-backups`)
- Fix: Query timeout and performance (documented `command-timeout` config, added performance index scripts)
- Fix: Authentication errors now log as warnings with clear messages (ExceptionMiddleware), reducing log noise
- Fix: SyncPlay authorization handler validates user before lookup, logs warnings for unauthenticated/unknown users (returns 403/404)
- Fix: Database deadlock detection logs warnings and allows EF Core auto-retry
- Add: Configurable LibraryMonitorDelay (min 30s, default 60s)
- Fix: SQLite migration filtering—skip SQLite-only migrations on PostgreSQL
- Chore: Suppress StyleCop warnings (SA1137, etc.) for project consistency
- Docs: 21 documentation files added/updated (config, backup, performance, troubleshooting, session summary)
- All changes are backward compatible and production-ready
2026-03-03 16:35:27 -05:00

2.7 KiB

How to run EFCore migrations

This shall provide context on how to work with entity frameworks multi provider migration feature.

Jellyfin will support multiple database providers in the future, namely SQLite as its default and the experimental PostgreSQL.

Each provider has its own set of migrations, as they contain provider specific instructions to migrate the specific changes to their respective systems.

When creating a new migration, you always have to create migrations for all providers. This is supported via the following syntax:

dotnet ef migrations add MIGRATION_NAME --project "PATH_TO_PROJECT" -- --provider PROVIDER_KEY

with SQLite currently being the only supported provider, you need to run the Entity Framework tool with the correct project to tell EFCore where to store the migrations and the correct provider key to tell Jellyfin to load that provider.

The example is made from the root folder of the project e.g for codespaces /workspaces/jellyfin

dotnet ef migrations add {MIGRATION_NAME} --project "src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite" -- --migration-provider Jellyfin-SQLite

If you get the error: Run "dotnet tool restore" to make the "dotnet-ef" command available. Run dotnet restore.

in the event that you get the error: System.UnauthorizedAccessException: Access to the path '/src/Jellyfin.Database' is denied. you have to restore as sudo and then run ef migrations as sudo too.

Database Query Logging

To enable SQL query logging for debugging purposes, you need to configure the logging level in your logging.json file located at Resources/Configuration/logging.json.

Enable SQL Query Logging

To see all executed SQL queries in the logs, change the logging level for Entity Framework Core database commands:

{
    "Serilog": {
        "MinimumLevel": {
            "Default": "Information",
            "Override": {
                "Microsoft": "Warning",
                "System": "Warning",
                "Microsoft.EntityFrameworkCore.Database.Command": "Debug"
            }
        }
    }
}

When Microsoft.EntityFrameworkCore.Database.Command is set to Debug, the following will be logged:

  • All SQL queries being executed
  • Query parameters (including sensitive data)
  • Query execution times
  • Detailed error messages

Logging Levels

  • Debug: Logs all SQL queries with parameters and execution details
  • Information: Logs queries without parameters (default setting in the configuration)
  • Warning: Only logs slow queries and warnings
  • Error: Only logs database errors

Note: Query logging with sensitive data is automatically enabled when using Debug level. Be careful not to expose sensitive information in production environments.