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

PostgreSQL: Flyway fails after applying migration containing SET ROLE statement #1537

Closed
DrHaribo opened this issue Feb 22, 2017 · 2 comments
Closed

Comments

@DrHaribo
Copy link

@DrHaribo DrHaribo commented Feb 22, 2017

What version of Flyway are you using?

4.1.1

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin, SBT plugin, ANT tasks)

Command-line

What database are you using (type & version)?

Postgresql 9.6.2

What operating system are you using?

Ubuntu and OS X (no difference for this issue)

What did you do?

(Please include the content causing the issue, any relevant configuration settings, and the command you ran)

Upgraded from Flyway 3.2.1 to 4.1.1

What did you expect to see?

Migrations working like before

What did you see instead?

Whenever Flyway sees a "SET ROLE" command in an SQL file it attempts to create the metadata table again. But since it already exists that causes the migration to fail.

With a .sql file containing only "SET ROLE common;" this is the result:

$ ./flyway migrate
Flyway 4.1.1 by Boxfuse

Database: jdbc:postgresql://localhost:5432/test (PostgreSQL 9.6)
Successfully validated 3 migrations (execution time 00:00.017s)
Current version of schema "public": 1.1.2
Migrating schema "public" to version 1.1.3 - init common
Creating Metadata table: "public"."schema_version"
ERROR:
Script failed
-------------
SQL State  : 42P07
Error Code : 0
Message    : ERROR: relation "schema_version" already exists
Line       : 17
Statement  : CREATE TABLE "public"."schema_version" (
    "installed_rank" INT NOT NULL,
    "version" VARCHAR(50),
    "description" VARCHAR(200) NOT NULL,
    "type" VARCHAR(20) NOT NULL,
    "script" VARCHAR(1000) NOT NULL,
    "checksum" INTEGER,
    "installed_by" VARCHAR(100) NOT NULL,
    "installed_on" TIMESTAMP NOT NULL DEFAULT now(),
    "execution_time" INTEGER NOT NULL,
    "success" BOOLEAN NOT NULL
) WITH (
  OIDS=FALSE
)
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Feb 22, 2017

Could you include a small test case that reproduces the issue?

@DrHaribo
Copy link
Author

@DrHaribo DrHaribo commented Feb 23, 2017

Sure. Empty database with a single migration V1_1_1__test.sql that looks like this

CREATE ROLE test LOGIN PASSWORD 'test';
SET ROLE test;

@axelfontaine axelfontaine added this to the Flyway 4.1.2 milestone Feb 23, 2017
@axelfontaine axelfontaine changed the title Creating Metadata table that already exists PostgreSQL: Flyway fails after applying migration containing SET ROLE statement Mar 3, 2017
axelfontaine added a commit to flyway/flywaydb.org that referenced this issue Mar 3, 2017
pradheeps pushed a commit to pradheeps/flyway that referenced this issue Mar 7, 2017
dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants