1

I am new at Postgres. I run the following script via flyway migration:

V1.0__Create_Service_Users.sql

DO
$do$
BEGIN
    IF NOT EXISTS(SELECT FROM pg_catalog.pg_roles WHERE  rolname = '${MYSERVICE_USERNAME}') THEN
        create role ${MYSERVICE_USERNAME} WITH LOGIN NOSUPERUSER NOINHERIT NOCREATEDB NOCREATEROLE NOREPLICATION PASSWORD '${MYSERVICE_PASSWORD}';
    END IF;
END
$do$

V1.1__Create_Schema.sql

create schema if not exists ${SCHEMA_PREFIX};

V1.2__Grant_Permissions_To_Users.sql

grant usage on all sequences in schema ${SCHEMA_PREFIX} to ${MYSERVICE_USERNAME};
alter default privileges in schema ${SCHEMA_PREFIX} grant SELECT, INSERT, UPDATE, DELETE on tables to ${MYSERVICE_USERNAME};

and finally: V2.1__Create_Images.Table.sql

CREATE TABLE ${SCHEMA_PREFIX}.images
(
    id          SERIAL primary key,
    name varchar(250) NOT NULL,
    link        varchar(250) NOT NULL,
    width       int          NOT NULL,
    height      int          NOT NULL,
    unique (name, link)
);

When I attempt to run application, it produces this error: relation "images" does not exist Here is also the database model:

@Entity
@Table(name = "images")
@EntityListeners(AuditingEntityListener.class)
public class ImagesDBO implements Serializable {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "id", nullable = false)
  private Long id;

  @Column(name = "name", nullable = false)
  private String name;

  @Column(name = "link", nullable = false)
  private String link;

  @Column(name = "width", nullable = false)
  private Integer width;

  @Column(name = "height", nullable = false)
  private Integer height;

In all the examples I can find where someone gets an error stating the relation does not exist, it's because they use uppercase letters in their table name. My table name does not have uppercase letters. I am kind stuck and cannot figure out why the table does not exist! can anybody help me please? Thank you.

3
  • 1
    I've never used spring, but presumably you might need to specify the schema in the @Table annotation? Commented Sep 27, 2020 at 14:33
  • I don't think that it's necessary, but even when I specified schema in that annotation, I received the same error Commented Sep 28, 2020 at 11:49
  • Try alter role ${MYSERVICE_USERNAME} set search_path = '${SCHEMA_PREFIX}, public'; to include the newly created schema in the search path Commented Sep 30, 2020 at 11:05

1 Answer 1

0

that error is provide by hibernates or flyway please ?

Did you try to specify schema with @Table :

Example :

@Entity
@Table(name = "author", schema = "bookstore")
public class ImagesDBO { ... }
Sign up to request clarification or add additional context in comments.

2 Comments

I tried to specify the schema with that annotation, but I always get the same issue when i run the application "schema does not exist"
I assume you checked the migrations execution. Can you add your logs ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.