Save the search path when importing Postgres dumps #2441

Merged
merged 2 commits into from Oct 14, 2015

Conversation

Projects
None yet
3 participants
@EspadaV8
Contributor

EspadaV8 commented Oct 12, 2015

Currently the search path isn't saved when importing a PostgreSQL dump
which causes problems when trying to fill a database table using COPY.
If the search_path isn't reset for the new connection then the import
will try to COPY the data into the default schema (usually public)
and cause the import to fail with
pg_query(): Query failed: ERROR: relation "..." does not exist

I would consider this a bug fix since my imports are currently failing
without the patch, but it could change some behaviour for badly created
database dumps that always assume the search path for COPYs
will be set to the public schema. If you'd prefer I could change the
base for the merge to be master and not the 2.1 branch.

Save the search path when importing postgres dumps
Currently the search path isn't saved when importing a PostgreSQL dump
which causes problems when trying to fill a database table using `COPY`.
If the search_path isn't reset for the new connection then the import
will try to `COPY` the data into the default schema (usually `public)
and cause the import to fail with
`pg_query(): Query failed: ERROR:  relation "..." does not exist`
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Oct 12, 2015

Member

👍
There are no reports about this or similar issue.
It is unlikely to affect any users, and if someone is affected, they can quickly fix their dump files, right?

Member

Naktibalda commented Oct 12, 2015

👍
There are no reports about this or similar issue.
It is unlikely to affect any users, and if someone is affected, they can quickly fix their dump files, right?

@EspadaV8

This comment has been minimized.

Show comment
Hide comment
@EspadaV8

EspadaV8 Oct 12, 2015

Contributor

Yeah, they can add in a SET search_path = public, pg_catalog; line before the COPY commands. I'm not sure how people would get a broken SQL file since pg_dump includes all the SET search_path commands.

As an aside, I was trying to create a test for this with an SQL file that includes different search_paths but I was unable to run the tests because they were being skipped. Is there some documentation on how to run the PostgreSQL tests?

Contributor

EspadaV8 commented Oct 12, 2015

Yeah, they can add in a SET search_path = public, pg_catalog; line before the COPY commands. I'm not sure how people would get a broken SQL file since pg_dump includes all the SET search_path commands.

As an aside, I was trying to create a test for this with an SQL file that includes different search_paths but I was unable to run the tests because they were being skipped. Is there some documentation on how to run the PostgreSQL tests?

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Oct 13, 2015

Member

Make sure that your postgres server is running and create a passwordless user named postgres and codeception_test database.

Or set valid credentials in https://github.com/Codeception/Codeception/blob/2.1/tests/unit/Codeception/Lib/Driver/PostgresTest.php#L10

Member

Naktibalda commented Oct 13, 2015

Make sure that your postgres server is running and create a passwordless user named postgres and codeception_test database.

Or set valid credentials in https://github.com/Codeception/Codeception/blob/2.1/tests/unit/Codeception/Lib/Driver/PostgresTest.php#L10

Add test that selects from a postgres schema
The postgresql dump file has been updated to include another schema that just includes a single row in a users table. The test tries to select this row from that schema to see if the dump has been imported correctly.
@EspadaV8

This comment has been minimized.

Show comment
Hide comment
@EspadaV8

EspadaV8 Oct 13, 2015

Contributor

I've just added a simple test to make sure that the dump imports correctly where there's a SET search_path other than public. I've tried to keep the dump changes to a minimum but if there's anything you'd like me to remove/update just let me know.

Contributor

EspadaV8 commented Oct 13, 2015

I've just added a simple test to make sure that the dump imports correctly where there's a SET search_path other than public. I've tried to keep the dump changes to a minimum but if there's anything you'd like me to remove/update just let me know.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Oct 13, 2015

Member

@Naktibalda I wish I knew anything about Postgres ) If you feel it is ok - please merge this PR.

Member

DavertMik commented Oct 13, 2015

@Naktibalda I wish I knew anything about Postgres ) If you feel it is ok - please merge this PR.

Naktibalda added a commit that referenced this pull request Oct 14, 2015

Merge pull request #2441 from EspadaV8/feature/import-postgresql-with…
…-schema-copy

Save the search path when importing Postgres dumps

@Naktibalda Naktibalda merged commit 00ed987 into Codeception:2.1 Oct 14, 2015

2 checks passed

continuous-integration/appveyor AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment