Skip to main content

Migrate Open WebUI from SQLite to PostgreSQL

Project description

Migrate tool for Open WebUI - SQLite to Postgres

Python Tests & Coverage

Migrate from using SQLite (default) in Open WebUI to use Postgres.

Inspiration from: https://github.com/taylorwilsdon/open-webui-postgres-migration, one of the big differences is that this migration require no input, configurable with environment variables, you just run the script, no input needed.

This so you can automate the whole process.

Version supported

As we are migrating tables in a specific order, the known Open WebUI version that this tools support is at this moment 0.8.12.

Install

You can copy the script to you environment and run it, or you could install it:

pip install open-webui-sqlite-migration

Configuration

Before anything else, backup you SQLite database and keep it in a safe place.

Needed environment variables:

  • SQLITE_DB_PATH - exact path to your open webui db, like: /app/backend/data/webui.db.
  • MIGRATE_DATABASE_URL - normally the same you should use for DATABASE_URL, like postgresql://user:pass@postgres:5432/openwebui

Also you need to start Open WebUI with DATABASE_URL, so needed tables are created. After that, you remove that variable so you go back to use SQLite. When using SQLite, you run the migration script, then you stop Open WebUI, and then again set DATABASE_URL. If everything now runs smoothly, you can remove the SQLite database. Keep a backup of the database until you are really sure that all things are working as they should.

While you always should have a backup of your SQLite database before starting, the migration itself is done on a copy of the SQLite database, to avoid locking etc.

/tmp needs to be writeable during the migration.

Migration

  • Make sure you backup your SQLite database, before doing anything.
  • Set SQLITE_DB_PATH and MIGRATE_DATABASE_URL
  • Start Open WebUI with SQLite if it's not running (info logs should say: Context impl SQLiteImpl).
  • Stop Open WebUI.
  • Start Open WebUI with DATABASE_URL set. Needed tables should be created.
  • Stop Open WebUI.
  • Remove ENV variable DATABASE_URL, start Open WebUI.
  • Run open-webui-migrate-sqlite --dry-run
  • Check output, if what is you expected, go to next step.
  • Have you really done a backup of your SQLite database?
  • Run open-webui-migrate-sqlite
  • If all succeeds, restart Open WebUI with DATABASE_URL set.
  • You should now be running Open WebUI with Postgres (if you have info logs from Open WebUI, you should see Context impl PostgresqlImpl).

Usage

# Run migration
open-webui-migrate-sqlite

# Dry run (preview without writing)
open-webui-migrate-sqlite --dry-run

# Show row counts in SQLite (before migration)
open-webui-migrate-sqlite --sqlite-counts

# Show row counts in PostgreSQL (after migration)
open-webui-migrate-sqlite --postgres-counts

# Validate migration (compare SQLite to PostgreSQL counts)
open-webui-migrate-sqlite --validate

Development

Poetry is used.

poetry install

Release:

Make sure to change version, then:

poetry build
poetry publish

Tests

export SQLITE_DB_PATH="/web.db"
export MIGRATE_DATABASE_URL=postgresql://user:pass@postgres:5432/openwebui
poetry run pytest

Coverage

poetry run pytest --cov

Linting

poetry run pylint $(git ls-files '*.py')

SBOM

trivy repo --format cyclonedx --output sbom.cdx.json https://github.com/Digitalist-Open-Cloud/Open-WebUI-SQLite-migration

License

MIT

Copyright (c) Digitalist Open Cloud.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open_webui_sqlite_migration-0.1.14.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

open_webui_sqlite_migration-0.1.14-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file open_webui_sqlite_migration-0.1.14.tar.gz.

File metadata

File hashes

Hashes for open_webui_sqlite_migration-0.1.14.tar.gz
Algorithm Hash digest
SHA256 f425d164d88bb3b03fae77c8af9fcf372999def274b89c73ea89bbf35ead1ef7
MD5 7c0ab3f67d2c3934871428f6a13f7c9a
BLAKE2b-256 242b02e4f0b2a85d0a1b54c1ba080e1e0d1d7c3d6630a1c4bcc841fab55adee2

See more details on using hashes here.

File details

Details for the file open_webui_sqlite_migration-0.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for open_webui_sqlite_migration-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 f192f4ae477142e9433e18adc449a614322c1357163064b19a04ef18ffd338a4
MD5 1752c1c6259992b9b791e092913762ba
BLAKE2b-256 f18b219c823ae933b3d1993d9600a8f0043715462367ee6e9b1615667477ce5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page