Skip to content

Add library for working with schemas in postgres#9

Merged
hundt-corbalt merged 2 commits intomainfrom
hundt-testdb
Sep 18, 2025
Merged

Add library for working with schemas in postgres#9
hundt-corbalt merged 2 commits intomainfrom
hundt-testdb

Conversation

@hundt-corbalt
Copy link
Contributor

Testing: used library successfully in https://github.com/Enterprise-CMCS/mac-fc-dso-metrics/pull/155

PR Checklist

  • New automated tests have been written to the extent possible.
  • The code has been checked for structural/syntactic validity.
    • AMI/application: a build was performed
    • terraform changes: "terraform plan" checked on every affected environment
  • (If applicable) the code has been manually tested on our infrastructure.
    • AMI/application: deployed an a test or dev environment
    • terraform changes: applied to test or dev environment
    • script: run against test or dev environment
  • Likely failure points and new functionality have been identified and tested manually.
    Examples:
    • Application manually run in a way that triggers any new branches
    • AMI logged into and changes verified from login shell
  • Pull request description includes a description of all the manual steps performed to accomplish the above.

To provide feedback on this template, visit https://docs.google.com/document/d/1YfTv7Amyop5G_8w1c2GJ_Mu-70L0KkZHhm9f9umDi3U/edit

Copy link

@jonah-corbalt jonah-corbalt left a comment

Choose a reason for hiding this comment

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

Looks great, a couple potential tweaks.

// Given a postgres connection string, generate a new one with the search path
// (https://www.postgresql.org/docs/17/ddl-schemas.html#DDL-SCHEMAS-PATH)
// set to just the given schema name.
func GetConnectionStringWithSearchPath(connStr, schemaName string) (string, error) {

Choose a reason for hiding this comment

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

Does this need to be exported? I think it is only used by the functions below.

// (https://www.postgresql.org/docs/17/ddl-schemas.html#DDL-SCHEMAS-PATH)
// It also registers a cleanup function (https://pkg.go.dev/testing#T.Cleanup)
// that will drop the schema after the test completes.
func ReconnectWithSchemaForTest(dbConnectionString string, t *testing.T) *sqlx.DB {

Choose a reason for hiding this comment

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

This looks great. I think the name would make more sense as ConnectWithSchemaForTest because although callers will often be reconnecting, the function doesn't necessarily do that.

@hundt-corbalt hundt-corbalt merged commit b59bf13 into main Sep 18, 2025
1 check passed
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