Skip to content

Account for schema when checking whether a column exists - #505

Merged
brandur merged 1 commit into
masterfrom
brandur-handle-schema
Aug 6, 2024
Merged

Account for schema when checking whether a column exists#505
brandur merged 1 commit into
masterfrom
brandur-handle-schema

Conversation

@brandur

@brandur brandur commented Aug 6, 2024

Copy link
Copy Markdown
Contributor

This one's aimed at addressing #503, in which migrations won't run when
using an alternate schema with search_path because the ColumnExists
query isn't accounting for schema in any way.

Here, modify ColumnExists so that it looks up within CURRENT_SCHEMA,
which will respect search path. Add test assertions to verify that this
works as expected, and similar ones in TableExists to avoid any
regressions there (it already does respect search path as written, but a
future change could potentially break that).

Fixes #503.

_, err = exec.Exec(ctx, "CREATE SCHEMA another_schema_123")
require.NoError(t, err)

_, err = exec.Exec(ctx, "SET search_path = another_schema_123")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this pollute the search path for this connection for future tests? Or does the conn pool get thrown away entirely after each test before the test DB goes back into the DB pool?

@brandur brandur Aug 6, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It gets rolled back with the transaction:

river_dev=# show search_path;
                 search_path
---------------------------------------------
 "$user", infra, logs, public
(1 row)

river_dev=# begin;
BEGIN

river_dev=*# set search_path = 'hello';
SET

river_dev=*# show search_path;
 search_path
-------------
 hello
(1 row)

river_dev=*# rollback;
ROLLBACK

river_dev=# show search_path;
                 search_path
---------------------------------------------
 "$user", infra, logs, public
(1 row)

This one's aimed at addressing #503, in which migrations won't run when
using an alternate schema with `search_path` because the `ColumnExists`
query isn't accounting for schema in any way.

Here, modify `ColumnExists` so that it looks up within `CURRENT_SCHEMA`,
which will respect search path. Add test assertions to verify that this
works as expected, and similar ones in `TableExists` to avoid any
regressions there (it already does respect search path as written, but a
future change could potentially break that).

Fixes #503.
@brandur
brandur force-pushed the brandur-handle-schema branch from 227cf7b to 38f9fc5 Compare August 6, 2024 00:45
@brandur
brandur merged commit fd60f72 into master Aug 6, 2024
@brandur
brandur deleted the brandur-handle-schema branch August 6, 2024 01:53
brandur added a commit that referenced this pull request Aug 6, 2024
Prepare release v0.11.1 containing #504 and #505. This will also require
a CLI release.
@brandur brandur mentioned this pull request Aug 6, 2024
brandur added a commit that referenced this pull request Aug 6, 2024
Prepare release v0.11.1 containing #504 and #505. This will also require
a CLI release.
brandur added a commit that referenced this pull request Aug 9, 2024
Prepare release v0.11.2, containing #504 and #505. This will also
require a separate CLI release because of some minimum Go version
changes in all the project's `go.mod` files.
@brandur brandur mentioned this pull request Aug 9, 2024
brandur added a commit that referenced this pull request Aug 9, 2024
Prepare release v0.11.2, containing #504 and #505. This will also
require a separate CLI release because of some minimum Go version
changes in all the project's `go.mod` files.
brandur added a commit that referenced this pull request Aug 9, 2024
Prepare release v0.11.2, containing #504 and #505. This will also
require a separate CLI release because of some minimum Go version
changes in all the project's `go.mod` files.
tigrato pushed a commit to gravitational/river that referenced this pull request Dec 18, 2024
Prepare release v0.11.2, containing riverqueue#504 and riverqueue#505. This will also
require a separate CLI release because of some minimum Go version
changes in all the project's `go.mod` files.
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.

ColumnExists query breaks when there are multiple river queues across different schemas

2 participants