-
Notifications
You must be signed in to change notification settings - Fork 1.6k
refactor: split out persons postgres #31099
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
base: master
Are you sure you want to change the base?
Conversation
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.
PR Summary
This PR refactors the PostHog plugin server to support a separate PostgreSQL database for person data, enabling better scalability and separation of concerns.
- Added new configuration variables
PERSONS_DATABASE_URL
andPERSONS_READONLY_DATABASE_URL
with appropriate defaults - Introduced new
PostgresUse
enum values (PERSONS_READ and PERSONS_WRITE) for directing queries to the correct database - Updated all person-related database operations to use the new database connection types
- Removed the broken
doesPersonBelongToCohort
query and simplified cohort matching logic - Modified CI workflows and Docker configuration to support testing with the new database architecture
13 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
PERSONS_DATABASE_URL: string // Optional read-write Postgres database for persons | ||
PERSONS_READONLY_DATABASE_URL: string // Optional read-only replica to the persons Postgres database |
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.
logic: The description says "Optional" but the type doesn't reflect this - should this be string | null
to match other optional database URLs in the config?
PERSONS_DATABASE_URL: string // Optional read-write Postgres database for persons | |
PERSONS_READONLY_DATABASE_URL: string // Optional read-only replica to the persons Postgres database | |
PERSONS_DATABASE_URL: string | null // Optional read-write Postgres database for persons | |
PERSONS_READONLY_DATABASE_URL: string | null // Optional read-only replica to the persons Postgres database |
if (serverConfig.PERSONS_READONLY_DATABASE_URL) { | ||
logger.info('🤔', `Connecting to persons read-only Postgresql...`) | ||
this.pools.set( | ||
PostgresUse.PERSONS_READ, | ||
createPostgresPool( | ||
serverConfig.PERSONS_READONLY_DATABASE_URL, | ||
serverConfig.POSTGRES_CONNECTION_POOL_SIZE, | ||
app_name | ||
) | ||
) |
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.
logic: Missing success log message after connecting to persons read-only PostgreSQL. All other connection blocks have a success message, but this one doesn't.
if (serverConfig.PERSONS_READONLY_DATABASE_URL) { | |
logger.info('🤔', `Connecting to persons read-only Postgresql...`) | |
this.pools.set( | |
PostgresUse.PERSONS_READ, | |
createPostgresPool( | |
serverConfig.PERSONS_READONLY_DATABASE_URL, | |
serverConfig.POSTGRES_CONNECTION_POOL_SIZE, | |
app_name | |
) | |
) | |
if (serverConfig.PERSONS_READONLY_DATABASE_URL) { | |
logger.info('🤔', `Connecting to persons read-only Postgresql...`) | |
this.pools.set( | |
PostgresUse.PERSONS_READ, | |
createPostgresPool( | |
serverConfig.PERSONS_READONLY_DATABASE_URL, | |
serverConfig.POSTGRES_CONNECTION_POOL_SIZE, | |
app_name | |
) | |
) | |
logger.info('👍', `Persons read-only Postgresql ready`) | |
} |
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.
Generally looks good to me
PERSONS_DATABASE_URL: string // Optional read-write Postgres database for persons | ||
PERSONS_READONLY_DATABASE_URL: string // Optional read-only replica to the persons Postgres database |
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.
PERSONS_DATABASE_URL: string // Optional read-write Postgres database for persons | |
PERSONS_READONLY_DATABASE_URL: string // Optional read-only replica to the persons Postgres database | |
PERSONS_DATABASE_URL?: string // Optional read-write Postgres database for persons | |
PERSONS_READONLY_DATABASE_URL?: string // Optional read-only replica to the persons Postgres database |
Important
👉 Stay up-to-date with PostHog coding conventions for a smoother review.
Problem
We're moving persons out of the main postgres and we need to point plugin-server to both databases.
Changes
Does this work well for both Cloud and self-hosted?
Yes, might need to review the setup docs
How did you test this code?
Using existing tests
Will validate on dev first