Skip to content

feat: Implement SQLite database support - #4912

Merged
marcelomendoncasoares merged 38 commits into
serverpod:mainfrom
marcelomendoncasoares:sqlite
Apr 13, 2026
Merged

marcelomendoncasoares merged 38 commits into
serverpod:mainfrom
marcelomendoncasoares:sqlite

Conversation

@marcelomendoncasoares

@marcelomendoncasoares marcelomendoncasoares commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #4785
Closes: #160

Implementation followed closely the spec on the issue (worth reading before reviewing this PR).

The only deviation was to ignore unsupported indexes instead of forbidding. This was preferred because it allows the same project definition to be used for different dialects - which is specially important for modules, that will be used in different projects with different dialects.

About batch operations

The original idea was to completely reuse all SQL query builders from Postgres, since SQLite is mostly compatible on the syntax. However, for insert and update operations, Postgres rely on the DEFAULT keyword that can be used inside the VALUES clause, and this is not supported by SQLite. On SQLite, we need to use the DEFAULT keyword outside the VALUES clause and omit the columns that have a default value for it to take effect.

Because of this, batch inserts on SQLite were simplified to a transaction/savepoint wrapper around multiple single row inserts. An improvement could be to group rows by the columns that are present, but this would introduce a lot of complexity and mess with the order of the rows. If a better solution is found in the future, this should be improved.

Migrations

As specified, SQLite has way less column types than Postgres, which requires us to store the target column type during migrations for a proper analysis when inspecting the database schema. This is specially important for repair migrations. If the ColumnDefinition class receive new fields, such fields must also be added to the stored schema table.

Testing

This PR introduces the serverpod_test_sqlite package, which contains the integration and migrations e2e tests for the SQLite dialect. These tests will run in the CI in parallel with the other tests.

Tests were copied from the serverpod_test_server package "as is" on commit 91006c7 and adapted to the SQLite dialect later on commit 32cb49f so we can track exactly what is supported and how the behavior differs from the Postgres dialect.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None.

@marcelomendoncasoares
marcelomendoncasoares force-pushed the sqlite branch 8 times, most recently from 52664ec to dd6c04d Compare April 1, 2026 22:54
@marcelomendoncasoares
marcelomendoncasoares force-pushed the sqlite branch 3 times, most recently from 2915f8a to 1e912fb Compare April 2, 2026 03:02
@marcelomendoncasoares
marcelomendoncasoares marked this pull request as ready for review April 2, 2026 03:52
@marcelomendoncasoares
marcelomendoncasoares requested a review from a team April 2, 2026 03:52

@nielsenko nielsenko left a comment

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.

This was a big one. Looks good, but got some comments/questions.

@nielsenko nielsenko left a comment

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.

LGTM 🎸

We have a recurring issue with:

serverpod_test_server-1 | +1654 ~6 -1: test_integration/future_calls/broken_future_calls_test.dart: Given a Serverpod server instance with default config and at least 1000future calls in the database containing unregistered and broken future calls when starting Serverpod then a warning is logged about skipping the check for broken future calls [E]

etc.

But not related to this PR.

@marcelomendoncasoares
marcelomendoncasoares merged commit 94d559b into serverpod:main Apr 13, 2026
78 of 81 checks passed
@marcelomendoncasoares
marcelomendoncasoares deleted the sqlite branch April 13, 2026 14:46
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SQLite database support sqlite3 & drift database support

3 participants