feat(database): add PostgreSQL support alongside SQLite - #380
Merged
Conversation
Introduces a dialect abstraction layer that allows AltMount to run against
either SQLite (default, unchanged behaviour) or PostgreSQL, selected via the
new `database.type` / `database.dsn` config keys.
Key changes:
- `internal/database/dialect.go` – new `Dialect` type + `dialectHelper` with
helpers for placeholder rewriting (?→$N), datetime expressions, JSON
extraction, and avg-time-diff calculations
- `dialectAwareDB` / `dialectAwareTx` wrappers auto-apply query rewriting on
every ExecContext / QueryContext / QueryRowContext call
- All repository constructors now accept a `Dialect` parameter; `datetime('now')`
in SET clauses replaced with bound `time.Now()` params; `LastInsertId()`
replaced with `RETURNING id` for PostgreSQL branches
- `internal/database/db.go` – `newPostgresDB` path using `pgx/v5/stdlib`;
goose migrations split into `migrations/sqlite/` and `migrations/postgres/`
- `internal/config/manager.go` – `DatabaseConfig` extended with `Type` and `DSN`
fields (SQLite path remains default)
- `cmd/altmount/cmd/setup.go` – wires `Type`, `DSN`, and `db.Dialect()` through
to all repository constructors
- 17 PostgreSQL migration files created (BIGSERIAL, TIMESTAMPTZ, JSONB, triggers)
- Test files updated to pass `DialectSQLite` to updated constructors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d importer tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
yoshitaka420
pushed a commit
to yoshitaka420/altmount
that referenced
this pull request
Jun 1, 2026
* feat(database): add PostgreSQL support alongside SQLite
Introduces a dialect abstraction layer that allows AltMount to run against
either SQLite (default, unchanged behaviour) or PostgreSQL, selected via the
new `database.type` / `database.dsn` config keys.
Key changes:
- `internal/database/dialect.go` – new `Dialect` type + `dialectHelper` with
helpers for placeholder rewriting (?→$N), datetime expressions, JSON
extraction, and avg-time-diff calculations
- `dialectAwareDB` / `dialectAwareTx` wrappers auto-apply query rewriting on
every ExecContext / QueryContext / QueryRowContext call
- All repository constructors now accept a `Dialect` parameter; `datetime('now')`
in SET clauses replaced with bound `time.Now()` params; `LastInsertId()`
replaced with `RETURNING id` for PostgreSQL branches
- `internal/database/db.go` – `newPostgresDB` path using `pgx/v5/stdlib`;
goose migrations split into `migrations/sqlite/` and `migrations/postgres/`
- `internal/config/manager.go` – `DatabaseConfig` extended with `Type` and `DSN`
fields (SQLite path remains default)
- `cmd/altmount/cmd/setup.go` – wires `Type`, `DSN`, and `db.Dialect()` through
to all repository constructors
- 17 PostgreSQL migration files created (BIGSERIAL, TIMESTAMPTZ, JSONB, triggers)
- Test files updated to pass `DialectSQLite` to updated constructors
javi11
added a commit
to dclipca/altmount
that referenced
this pull request
Sep 6, 2026
PostgreSQL requires an expression index column to be wrapped in its own parentheses; the single-paren form has failed with a syntax error on every fresh PostgreSQL install since kipsilabs#380, so no database can have applied the old text.
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.
Summary
Dialectabstraction (sqlite|postgres) with adialectAwareDB/dialectAwareTxwrapper layer that auto-rewrites queries (placeholder?→$N,datetime('now')→NOW(), etc.) on every call — zero per-query boilerplateDialectat construction;LastInsertId()replaced withRETURNING idfor PostgreSQL; date/time cutoffs computed in Go rather than SQLmigrations/sqlite/subdirectoryDatabaseConfigextended with optionaltypeanddsnfields — SQLite remains the default and is fully backwards-compatibleCloses #82
Configuration
Test plan
go build ./...— clean buildgo test ./internal/database/...— all existing SQLite tests passtype: postgres— migrations run, all operations workAddToQueuewith both new inserts and conflicts on both backendsFilterExistingNzbdavIds— JSONB extraction returns correct results on PostgreSQL🤖 Generated with Claude Code