Move persistence to Supabase and S3
This guide moves QuOptuna’s durable data out of local SQLite files.
Install the deployment dependencies
Section titled “Install the deployment dependencies”uv syncConfigure the environment
Section titled “Configure the environment”Copy .env.example to .env, then set your Supabase PostgreSQL connection:
DATABASE_URL=postgresql+psycopg://USER:PASSWORD@HOST:5432/postgresOPTUNA_DATABASE_URL=postgresql+psycopg://USER:PASSWORD@HOST:5432/postgresOPTUNA_DB_SCHEMA=optunaDATABASE_URL stores QuOptuna application data such as runs, sessions,
datasets, analysis snapshots, and reports. OPTUNA_DATABASE_URL stores Optuna
studies and trials. They may point to the same Supabase database; QuOptuna
places Optuna tables in the separate optuna schema.
Migrate application metadata
Section titled “Migrate application metadata”Preview the migration:
uv run quoptuna migrate-supabase \ --source-db db/quoptuna_app.db \ --database-url "$DATABASE_URL" \ --dry-runRun it after reviewing the counts:
uv run quoptuna migrate-supabase \ --source-db db/quoptuna_app.db \ --database-url "$DATABASE_URL"The local database remains available as a backup.
Migrate the active Optuna database
Section titled “Migrate the active Optuna database”Identify the database used by the runs, then migrate that file. For example:
uv run quoptuna migrate-optuna db/results-trial-june15.dbThe command migrates every study in that file. Use --study-name when only one
study is needed. It copies trials, parameters, values, states, and study/trial
attributes.
Configure S3-compatible artifacts
Section titled “Configure S3-compatible artifacts”To store analysis images and uploaded datasets remotely:
ARTIFACT_STORAGE=s3S3_ENDPOINT_URL=https://YOUR-S3-ENDPOINTS3_BUCKET=YOUR-BUCKETS3_REGION=YOUR-REGIONS3_ACCESS_KEY_ID=YOUR-ACCESS-KEYS3_SECRET_ACCESS_KEY=YOUR-SECRET-KEYS3_PREFIX=quoptunaS3_SIGNED_URL_TTL=900For AWS S3, leave S3_ENDPOINT_URL empty. For Supabase Storage or MinIO, use
the provider’s S3-compatible endpoint. Create the bucket before starting the
server.
Verify the migration
Section titled “Verify the migration”Start the server:
uv run quoptuna run --no-browserCreate a new run and analysis, then confirm application records in Supabase:
select job_id, session_id, study_name, statusfrom public.quoptuna_runsorder by created_at desc;Confirm Optuna tables are isolated in the configured schema:
select table_schema, table_namefrom information_schema.tableswhere table_schema = 'optuna'order by table_name;If S3 is enabled, check that objects appear under:
quoptuna/runs/<run-id>/analysis/<snapshot-id>/revisions/<revision>/Restart the server and reopen the run. Successful rehydration confirms that the run metadata is coming from Supabase and analysis artifacts are coming from the configured object storage.
Troubleshooting
Section titled “Troubleshooting”No module named psycopg2
Section titled “No module named psycopg2”Use the psycopg URL form and reinstall dependencies:
uv syncThe URL should be accepted as either postgresql://... or
postgresql+psycopg://...; QuOptuna normalizes the former.
copy_study() got an unexpected keyword argument study_name
Section titled “copy_study() got an unexpected keyword argument study_name”Use the current CLI command from this version. It uses Optuna’s
to_study_name API internally:
uv run quoptuna migrate-optuna db/results-trial-june15.dbA study already exists
Section titled “A study already exists”The source may have been partially migrated. Inspect the destination before rerunning; do not delete the source SQLite database until the trial counts have been verified.