-
-
Notifications
You must be signed in to change notification settings - Fork 707
[management] Add postgres support for activity event store #3890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: bcmmbaga <[email protected]>
Signed-off-by: bcmmbaga <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds optional Postgres support for the activity event store by extracting database initialization and pooling logic, while keeping SQLite as the default engine.
- Extracts database setup into
initDatabase
/configureConnectionPool
to support multiple engines - Introduces
NB_ACTIVITY_EVENT_STORE_ENGINE
,NB_ACTIVITY_EVENT_POSTGRES_DSN
, andNB_SQL_MAX_OPEN_CONNS
environment variables - Adds Postgres driver import and connection logic
Comments suppressed due to low confidence (3)
management/server/activity/sqlite/sqlite.go:46
- [nitpick] The function name
NewSQLiteStore
no longer accurately reflects its support for Postgres. Consider renaming toNewEventStore
orNewStore
for clarity.
func NewSQLiteStore(ctx context.Context, dataDir string, encryptionKey string) (
management/server/activity/sqlite/sqlite.go:31
- The new environment variables (
NB_ACTIVITY_EVENT_STORE_ENGINE
,NB_ACTIVITY_EVENT_POSTGRES_DSN
,NB_SQL_MAX_OPEN_CONNS
) should be documented in the repo README or a configuration guide so users know how to configure Postgres mode.
const (
management/server/activity/sqlite/sqlite.go:240
- We should add unit tests for the Postgres initialization path and the error path when
NB_ACTIVITY_EVENT_POSTGRES_DSN
is unset to ensure coverage of the new logic.
func initDatabase(ctx context.Context, dataDir string) (*gorm.DB, error) {
Signed-off-by: bcmmbaga <[email protected]>
50e1f62
to
7a9c80a
Compare
Signed-off-by: bcmmbaga <[email protected]>
@bcmmbaga there's a problem with the migration Once I migrated my local env to use postgres, I started having I suspect there's something up with gorm's primary key check with postgres or the schema the delete users table was created with. I started management once before executing pgloader to have gorm migrate the tables. |
Signed-off-by: bcmmbaga <[email protected]>
Signed-off-by: bcmmbaga <[email protected]>
7ccb87b
to
5024a08
Compare
|
Describe your changes
Adds postgres as an optional storage engine for activity events while keeping sqlite as the default. To use postgres, set the environment variable
NB_ACTIVITY_EVENT_STORE_ENGINE=postgres
and provide a connection string viaNB_ACTIVITY_EVENT_POSTGRES_DSN
.Migrating existing events to Postgres
pgloader --type sqlite backup/events.db "postgresql://<PG_USER>:<PG_PASSWORD>@<PG_HOST>:<PG_PORT>/<PG_DB_NAME>"
Issue ticket number and link
Stack
Checklist