Skip to content
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

chore: bump pgx to v5 #1032

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

Conversation

iwpnd
Copy link
Member

@iwpnd iwpnd commented Mar 5, 2025

description

  • bump pgx to v5
  • refactor registering types on connect
  • hstore now is a buildin type with changed behaviour, it was required to treat it separately in decipherFields

Copy link
Member

@ARolek ARolek left a comment

Choose a reason for hiding this comment

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

Looking good so far! Thank you for kicking off this upgrade. I left some minor comments inline on my first pass.

@@ -315,44 +314,33 @@ func BuildDBConfig(opts *DBConfigOptions) (*pgxpool.Config, error) {
return nil, err
}

dbconfig.ConnConfig.LogLevel = pgx.LogLevelWarn
Copy link
Member

Choose a reason for hiding this comment

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

Note to self. Has this log level config been moved to somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self. Has this log level config been moved to somewhere else?

yes it did. instead of a logger within pgx, logging is extracted to be in the pgx tracelog package. I'll have to take a look on how to make that work for us later on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, i'd have to build a log adapter for the tracelog package of pgx for our custom logger. 🤔

Something like so:

        // this would be an instance of slog logger
	logAdapter := log.NewLoggerAdapter(logger)
	tracer := &tracelog.TraceLog{
		Logger:   logAdapter,
		LogLevel: tracelog.LogLevelNone,
	}
	if <pg debug enabled> {
		tracer.LogLevel = tracelog.LogLevelDebug
	}
	conf.ConnConfig.Tracer = tracer

there's readily available adapters for slog already. I don't think it make sense to build a custom logadapter for our custom logger if we agree that slog should be come the default logger and we drop str logger and zap. wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that we should move towards adopting slog, but I'm not sure if we should land this PR without a logger in place. One option is that we could shift over to the slog refactor, land that, and then circle back to this PR. If we don't want to do that, I think implementing the custom log adapter would be the way to go, even if it's temporary.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a logger, tegola logger remains untouched by this. PGX however does not come with logger any longer, but expects the user to pass it if required.
I will add a very simple adapter that reflects the previous behaviour of:

dbconfig.ConnConfig.LogLevel = pgx.LogLevelWarn

Which is currently logging anything that pgx considers as warning.

@iwpnd
Copy link
Member Author

iwpnd commented Mar 11, 2025

I wanted to test the hstore tags and noticed that both in master and in my branch the tags do not show properly in the ui. Default tags are ignored as well. @ARolek

update:
was able to get tags in master disabling the file cache. the fields property doesn't work either. the only way to get tags into features is by extending the sql statement to include the fields.

update2:
ok, all of those options are postgis provider only. 💡

@@ -32,6 +32,8 @@ services:
environment:
PGUSER: postgres
PGPASSWORD: postgres
volumes:
- ./scripts:/scripts
Copy link
Member Author

@iwpnd iwpnd Mar 11, 2025

Choose a reason for hiding this comment

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

this allows us to extend test tables a little more flexible than downloading a dump, wdyt? @ARolek

break
// NOTE: if it can also be a tag, then breaking here
// will never add it to tags
// break
Copy link
Member Author

@iwpnd iwpnd Mar 11, 2025

Choose a reason for hiding this comment

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

this was an odd find. the comment above explicitly says it can also be a tag, but it will never be parsed to tags with the break in place. Do you remember how that came to be maybe? @ARolek
This was just never noticed, as the case is not tested. 🙈

return
}

log.Warnf("Postgis: %s, %#v", msg, data)
Copy link
Member Author

@iwpnd iwpnd Mar 11, 2025

Choose a reason for hiding this comment

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

I'm having trouble testing this locally. Can you think of an action where pgx would emit a warning before? @ARolek

Name: "uuid",
OID: pgtype.UUIDOID,
})
pgxuuid.Register(conn.TypeMap())
Copy link
Member Author

@iwpnd iwpnd Mar 11, 2025

Choose a reason for hiding this comment

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

I was hoping to avoid by using the builtin pgtype codec for uuid, but I just couldn't get it to work without this external dependency. Considering the official wiki is proposing this approach, I think we're on the safe side tho.

@iwpnd
Copy link
Member Author

iwpnd commented Mar 11, 2025

tests will pass once #1033 is accepted :)

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