Skip to content

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

pl
Copy link
Contributor

@pl pl commented Apr 10, 2025

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

  • Adds new configuration for persons postgres
  • Updates the queries to use the persons postgres
  • Removes the does person belong to cohort query, which is apparently broken anywa

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

@pl pl requested review from timgl, benjackwhite and a team April 10, 2025 23:40
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 and PERSONS_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

Comment on lines +143 to +144
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
Copy link
Contributor

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?

Suggested change
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

Comment on lines +89 to +98
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
)
)
Copy link
Contributor

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.

Suggested change
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`)
}

Copy link
Contributor

@benjackwhite benjackwhite left a 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

Comment on lines +143 to +144
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants