Skip to content

SQLite3 as the database#642

Draft
dentarg wants to merge 9 commits intomainfrom
sqlite
Draft

SQLite3 as the database#642
dentarg wants to merge 9 commits intomainfrom
sqlite

Conversation

@dentarg
Copy link
Copy Markdown
Member

@dentarg dentarg commented Jun 15, 2024

PoC for #641

  • Does search still work?

Comment thread Gemfile Outdated
Comment thread config/database.rb Outdated
Comment on lines +6 to +9
# https://github.com/Starkast/wikimum/issues/412
# https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_validator_rb.html
DB.extension(:connection_validator)
DB.pool.connection_validation_timeout = 60 * 5
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't make any sense when using SQLite? 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not.

dentarg added 9 commits May 8, 2026 09:19
Sequel's full_text_search supports PostgreSQL/MySQL/MSSQL but not SQLite,
where it silently returned no results. Replace with a portable LIKE-based
match that requires every term to appear in at least one searched column.

Add an integration test covering title/content matches, case
insensitivity, AND-of-terms behaviour, concealed-page exclusion, and the
single-match redirect.
The endpoint shelled out to pg_dump, which doesn't apply to SQLite. Use
SQLite's online backup API (SQLite3::Backup) to produce a consistent
copy of the live database into a tempfile, then serve it as
application/vnd.sqlite3.

The integration test now compares the response body bytes against the
UTF-8 bytes of the page title, since the response is a binary database
file rather than a SQL dump.
The app now runs on SQLite only. Remove PostgreSQL-specific code,
dependencies and tooling:

- Drop pg and sequel_pg gems (and the corresponding vendor/cache).
- Drop postgresql-client and libpq-dev from the Dockerfile.
- Drop the postgres service from docker-compose; the app uses a
  bind-mounted ./storage directory for the SQLite file instead.
- Remove the PGGSSENCMODE workaround in config/app.rb and the unused
  App.macos? helper.
- Remove bin/cleanup_test_databases (no postgres test databases to
  clean up) and switch bin/download_database_backup to save .sqlite3.
- Use a SQLite tempfile in test/test_database.rb instead of createdb.
The database URL is now built in code from two simpler env vars:

  DATABASE_DIR  (default "./storage")
  DATABASE_NAME (default "wiki")

  → sqlite://${DATABASE_DIR}/${DATABASE_NAME}.db

On Fly the volume is mounted at /storage and DATABASE_DIR is set to
match. The test helper uses Dir.tmpdir as DATABASE_DIR and a random
DATABASE_NAME per process so tests go through the same code path as
production.
Replace bin/dev_db_bootstrap with a migrate step inside bin/dev.
SQLite needs no createdb step, so a separate bootstrap script is
overhead. bin/setup drops the corresponding step too — bin/dev now
handles it on the next start.
Document DATABASE_DIR and DATABASE_NAME, drop the PostgreSQL setup
instructions, and replace the Aiven preview-database notes with the
Fly volume setup.
backup_path = File.join(backup_tmpdir, rel_path)

send_file dump_path, type: "text/plain"
send_file backup_path, type: "application/vnd.sqlite3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants