Repository navigation
feat(db): Add EF Core code-first migrations and PostgreSQL support - #77
Open
tintinhamans wants to merge 7 commits into
Open
tintinhamans wants to merge 7 commits into
tintinhamans wants to merge 7 commits into
Conversation
tintinhamans
force-pushed
the
arctic/feat/ef-migrations-postgres
branch
2 times, most recently
from
October 26, 2026 20:51
48f745b to
0ed2840
Compare
tintinhamans
force-pushed
the
arctic/feat/ef-migrations-postgres
branch
from
October 29, 2026 04:59
0ed2840 to
dabd3b4
Compare
Replace the hand-written schema in Database_Structure/ with EF Core
migrations and add PostgreSQL as a second database provider next to
MySQL/MariaDB. Both run on EF Core 10 (Npgsql and the Microting fork of
Pomelo, since Pomelo has no EF Core 10 release).
- Select the provider with Database:db_provider ("mysql", the default, or
"postgres"); MySQL/MariaDB support is deprecated and will be removed in
the next major version
- Keep one provider-neutral model with per-provider contexts and migration
sets; the MySQL InitialCreate mirrors the production schema, the
PostgreSQL model stores unsigned values as signed, JSON as jsonb and
timestamps as timestamptz; all timestamps are normalized to UTC
- Model every index production relies on (match feed, social lookups, ban
reconciliation, device/IP lookups) plus the schema the website shares
(web_sessions, users.google_id/google_email/permissionslevel); use
partial indexes on PostgreSQL for the pending-publication and banned-user
lookups
- Add "GenOnlineService migrate [--yes] [--baseline]" as the only way to
change the schema; it lists pending migrations, prompts interactively and
fails fast without a TTY unless --yes is passed
- Add --baseline to adopt an existing pre-migrations database: it verifies
every table, column (incl. nullability) and index InitialCreate expects
and records InitialCreate without touching data
- Refuse to start the server while migrations are pending, with a baseline
hint for existing installs
- Replace the raw ON DUPLICATE KEY token upsert with EF calls and set match
start/finish times in code instead of SQL column defaults
- Detect duplicate keys on both providers (MySQL 1062, PostgreSQL 23505)
- Add a local dotnet-ef tool manifest and update the README for setup,
upgrading existing installs and per-provider schema changes
Collect Npgsql spans and metrics next to MySqlConnector's, strip the connection-derived Npgsql data source name from database spans, and keep Npgsql logging at Warning like MySqlConnector.
tintinhamans
force-pushed
the
arctic/feat/ef-migrations-postgres
branch
from
October 29, 2026 05:13
dabd3b4 to
e6969c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the hand-written
Database_StructureSQL with EF Core code-first migrations and adds PostgreSQL next to MySQL.Database:db_providerpicksmysql(default, deprecated, will be dropped in next major) orpostgres. Each provider has its own context andInitialCreate; the MySQL one matches the prod schema exactly, including the website tables, and adds the missingidx_finished_timeindex. Postgres usestimestamptz,jsonband partial indexes. All timestamps are UTC on both, and the token-state upsert is plain EF now, so there's no raw SQL left.The server never migrates on its own and refuses to start while migrations are pending.
GenOnlineService migrateapplies them (asks first,--yesfor deploys).--baselinemarks an existing database asInitialCreateafter checking every table, column and index is already there. Verified on Postgres 17 and MariaDB 12.1, including baseline against a copy of the prod schema.Before deploying, run this once on prod and test, otherwise the service won't start:
After that,
migrate --yesruns as a deploy step before starting the new version.Builds on #78, so its commits stay in the diff until it lands. The last commit adds the Npgsql meter and trace source and strips the Npgsql data source name from spans.