Skip to content

docs: add SQL schema documentation - #8493

Draft
link2xt wants to merge 2 commits into
mainfrom
link2xt/sql-schema-docs
Draft

docs: add SQL schema documentation#8493
link2xt wants to merge 2 commits into
mainfrom
link2xt/sql-schema-docs

Conversation

@link2xt

@link2xt link2xt commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

There is currently no place to document up to date SQL schema. New database is initialized with src/sql/tables.sql and then updated by migrations,
So tracking down how some column is used requires grepping the code, looking for a migration adding it and corresponding commits.

The documentation is frozen at version 160.
Ideally it should be updated when adding a migration, but most of the value is documenting old stable tables.

There was an idea to automatically check
if the documentation corresponds to the database schema, but there is no tool to compare the schema.
SQLite itself stores database schema as the text
in the schema table, with columns appended later
without any formatting.
Even SQLite REPL which has ".schema --indent" option does not handle the comments properly
and produces invalid SQL
with closing parenthesis commented out.

Comment thread docs/schema.sql
starred INTEGER DEFAULT 0,
timestamp_sent INTEGER DEFAULT 0, -- Timestamp of the message as sent in the Date header.
timestamp_rcvd INTEGER DEFAULT 0,
hidden INTEGER DEFAULT 0,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is a bad column, needs a good documentation.

In many cases the message should be trashed instead of hiding. Hiding is used for rare cases when you want the message to be "in the chat" so they are marked as seen. One is reactions, but there was something else, i think location streaming. Would be great to deprecate it somehow or at least discourage more usage of it. The problem with such hidden messages is that it is unclear when they are supposed to be cleaned up and they likely slow down chat loading if you have lots of reactions in the chat.

Comment thread docs/schema.sql Outdated
mime_compressed INTEGER NOT NULL DEFAULT 0,
txt_normalized TEXT,
deleted INTEGER NOT NULL DEFAULT 0,
pre_rfc724_mid TEXT DEFAULT ''

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This should be grouped with rfc724_mid and also needs a very good documentation, it is always difficult to remember what goes into rfc724_mid when only a pre-message is received.

Comment thread docs/schema.sql
-- Commented SQLite database schema.
--
-- This file should only be used for documentation,
-- do not run this SQL e.g. to create databases.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
-- do not run this SQL e.g. to create databases.
-- do not run this SQL e.g. to create databases.
-- This is because we want to be 100% sure
-- that new users and users who run the migrations
-- get the same database schema.

Comment thread docs/schema.sql
CREATE INDEX tls_spki_index_timestamp ON tls_spki (timestamp);

--
-- Deprecated tables.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
-- Deprecated tables.
-- Deprecated and unused tables.
-- We don't immediately drop unused tables,
-- because we want users to be able to downgrade.

I think none of them are used anymore?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think we can even make a migration to finally drop all of them.

link2xt added 2 commits July 31, 2026 23:05
There is currently no place to document up to date SQL schema.
New database is initialized with src/sql/tables.sql
and then updated by migrations,
So tracking down how some column is used requires grepping the code,
looking for a migration adding it and corresponding commits.

The documentation is frozen at version 160.
Ideally it should be updated when adding a migration,
but most of the value is documenting old stable tables.

There was an idea to automatically check
if the documentation corresponds to the database schema,
but there is no tool to compare the schema.
SQLite itself stores database schema as the text
in the schema table, with columns appended later
without any formatting.
Even SQLite REPL which has ".schema --indent" option
does not handle the comments properly
and produces invalid SQL
with closing parenthesis commented out.
@link2xt
link2xt force-pushed the link2xt/sql-schema-docs branch from 8e4c7f3 to 4e7ee48 Compare July 31, 2026 23:05
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.

2 participants