- Moved all documentation to docs/ and updated README with categorized links and new docs/INDEX.md - Added HOW_TO_SWITCH_DATABASE.md and several new analysis/action docs - Introduced db-config.ps1 for centralized DB config; all scripts now use it for easy DB switching - Added db-quick.ps1 for interactive diagnostics and index management - Updated Add-All-Indexes.bat to use db-config.ps1 - Added Fix-ItemValues-Performance.ps1 to create 3 critical indexes on ItemValues, addressing 1.3B row seq scan issue - Updated performance_indexes.sql with new ItemValues indexes and ANALYZE - Updated diagnostics.sql and database_report.txt for improved output and clarity - All scripts and docs now reference the new config and index optimization workflow
6.4 KiB
✅ SQL Files Not Included in Publish - Solution
Problem
When publishing Jellyfin, the SQL files in the sql/ directory are not being included in the publish output.
Root Cause
MSBuild's content copy behavior is tricky with dotnet publish. The files need special handling to be included in the publish directory.
✅ Solution: Manual Copy Post-Publish
Since the automatic copy isn't working reliably, here's a simple post-publish script:
Option 1: PowerShell Script (Recommended)
Create copy-sql-files.ps1 in the project root:
# copy-sql-files.ps1
# Run this after publish to copy SQL files
param(
[string]$PublishDir = "Jellyfin.Server\bin\Release\net11.0\publish"
)
Write-Host "Copying SQL files to $PublishDir..." -ForegroundColor Cyan
# Create sql directory
New-Item -ItemType Directory -Path "$PublishDir\sql" -Force | Out-Null
New-Item -ItemType Directory -Path "$PublishDir\sql\schema_init" -Force | Out-Null
# Copy SQL files
Copy-Item "Jellyfin.Server\sql\*.sql" "$PublishDir\sql\" -Force
Copy-Item "Jellyfin.Server\sql\schema_init\*.sql" "$PublishDir\sql\schema_init\" -Force -ErrorAction SilentlyContinue
Write-Host "✓ SQL files copied successfully!" -ForegroundColor Green
# List copied files
Get-ChildItem "$PublishDir\sql" -Recurse -File | Select-Object Name, Length
Usage:
# After publishing
dotnet publish Jellyfin.Server\Jellyfin.Server.csproj -c Release
# Copy SQL files
.\copy-sql-files.ps1
Option 2: Batch Script
Create copy-sql-files.bat:
@echo off
SET PUBLISH_DIR=Jellyfin.Server\bin\Release\net11.0\publish
echo Copying SQL files to %PUBLISH_DIR%...
mkdir "%PUBLISH_DIR%\sql" 2>nul
mkdir "%PUBLISH_DIR%\sql\schema_init" 2>nul
copy /Y "Jellyfin.Server\sql\*.sql" "%PUBLISH_DIR%\sql\" >nul
copy /Y "Jellyfin.Server\sql\schema_init\*.sql" "%PUBLISH_DIR%\sql\schema_init\" 2>nul >nul
echo SQL files copied successfully!
dir "%PUBLISH_DIR%\sql" /B
Option 3: Automated in Publish Command
Create a combined script that does both:
# publish-with-sql.ps1
Write-Host "Publishing Jellyfin..." -ForegroundColor Cyan
dotnet publish Jellyfin.Server\Jellyfin.Server.csproj -c Release -o Jellyfin.Server\bin\Release\net11.0\publish
if ($LASTEXITCODE -eq 0) {
Write-Host "✓ Publish successful" -ForegroundColor Green
Write-Host "Copying SQL files..." -ForegroundColor Cyan
$publishDir = "Jellyfin.Server\bin\Release\net11.0\publish"
New-Item -ItemType Directory -Path "$publishDir\sql" -Force | Out-Null
New-Item -ItemType Directory -Path "$publishDir\sql\schema_init" -Force | Out-Null
Copy-Item "Jellyfin.Server\sql\*.sql" "$publishDir\sql\" -Force
Copy-Item "Jellyfin.Server\sql\schema_init\*.sql" "$publishDir\sql\schema_init\" -Force -ErrorAction SilentlyContinue
Write-Host "✓ SQL files copied" -ForegroundColor Green
Write-Host "`nPublish complete at: $publishDir" -ForegroundColor Cyan
Get-ChildItem "$publishDir\sql" -Recurse | Select-Object FullName
} else {
Write-Host "❌ Publish failed" -ForegroundColor Red
}
Usage:
.\publish-with-sql.ps1
✅ Solution: Fix .csproj (Alternative)
If you want to fix it properly in the .csproj, use this configuration:
Edit Jellyfin.Server\Jellyfin.Server.csproj
Add this before the closing </Project> tag:
<!-- Ensure SQL files are in the project directory -->
<ItemGroup>
<None Include="sql\**\*.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<Pack>false</Pack>
</None>
</ItemGroup>
<!-- Manual copy target to ensure SQL files are included -->
<Target Name="CopySQLToOutput" AfterTargets="Build;Publish">
<Message Importance="high" Text="Copying SQL files to output directory..." />
<!-- Create sql directory -->
<MakeDir Directories="$(OutDir)sql" />
<MakeDir Directories="$(OutDir)sql\schema_init" />
<!-- Copy SQL files -->
<ItemGroup>
<SQLFilesMain Include="$(ProjectDir)sql\*.sql" />
<SQLFilesInit Include="$(ProjectDir)sql\schema_init\*.sql" />
</ItemGroup>
<Copy SourceFiles="@(SQLFilesMain)"
DestinationFolder="$(OutDir)sql"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SQLFilesInit)"
DestinationFolder="$(OutDir)sql\schema_init"
SkipUnchangedFiles="true" />
<Message Importance="high" Text="✓ SQL files copied to $(OutDir)sql" />
</Target>
Then rebuild:
dotnet clean Jellyfin.Server\Jellyfin.Server.csproj -c Release
dotnet build Jellyfin.Server\Jellyfin.Server.csproj -c Release
Verification
After publishing, verify SQL files are present:
# Check if files exist
Test-Path "Jellyfin.Server\bin\Release\net11.0\publish\sql\all_performance_indexes.sql"
# List all SQL files
Get-ChildItem "Jellyfin.Server\bin\Release\net11.0\publish\sql" -Recurse | Select-Object FullName
Expected output:
FullName
--------
E:\Projects\pgsql-jellyfin\Jellyfin.Server\bin\Release\net11.0\publish\sql\all_performance_indexes.sql
E:\Projects\pgsql-jellyfin\Jellyfin.Server\bin\Release\net11.0\publish\sql\add_base_performance_indexes.sql
E:\Projects\pgsql-jellyfin\Jellyfin.Server\bin\Release\net11.0\publish\sql\diagnostics.sql
...
Quick Test
# Publish
dotnet publish Jellyfin.Server\Jellyfin.Server.csproj -c Release
# Copy SQL
.\copy-sql-files.ps1
# Verify
dir "Jellyfin.Server\bin\Release\net11.0\publish\sql"
# Should see:
# all_performance_indexes.sql
# add_base_performance_indexes.sql
# diagnostics.sql
# schema_init\
Files to Create
- ✅
copy-sql-files.ps1- PowerShell copy script - ✅
copy-sql-files.bat- Batch copy script - ✅
publish-with-sql.ps1- Combined publish + copy script
All three scripts are provided above. Choose whichever fits your workflow!
Summary
Quick Fix: Use publish-with-sql.ps1 - one command does everything
Best Fix: Update .csproj with the Target shown above - automatic and permanent
The SQL files will be at:
publish/
└── sql/
├── all_performance_indexes.sql
├── add_base_performance_indexes.sql
├── diagnostics.sql
└── schema_init/
└── 10_create_supplementary_indexes.sql
And the PostgresDatabaseProvider will find them automatically at startup! 🎉