skip to Main Content

I’m using quarkus and the DevServices to start a postgresql database.
I want to initilize this database with a csv file. To do so I want to mount a csv file into the container of postgresql which is started with DevServices, so that I can initalize my database with "COPY … FROM" in the init script.

I follow the quarkus documentation for database dev services:

I’ve tried to add the following to my project in the application properties:

quarkus.datasource.devservices.volumes."/resources/init/"=/container/resources/

or

quarkus.datasource.devservices.volumes."src/main/resources/init/"=/container/resources/

The problem is that my csv file isn’t mounted correctly: The path /container/resources is in the postgres container but the resources folder is empty. It should contain the csv-file titanic.csv.

What path do I need to provide?

2

Answers


  1. You need to provide an absolute path where your resource is located. However, since you want to bind a resource that is in your classpath already, you can use:

    quarkus.datasource.devservices.volumes."classpath:./init"=/container/resources
    

    Where "." stands for the path at either "src/test/resources" if exists or "src/main/resources".

    I hope it helps!

    Login or Signup to reply.
  2. The example in the documentation explains it well, I think:

    # Using a filesystem volume:
    quarkus.datasource.devservices.volumes."/path/from"=/container/to 
    # Using a classpath volume:
    quarkus.datasource.devservices.volumes."classpath:./file"=/container/to 
    

    Your attempts are wrong for several reasons:

    1. Your file is in your application resources and thus will be available in the classpath, so you probably should use the classpath: variant instead of the filesystem variant you’re using.
    2. Your first attempt uses "/resources/init/", which is an absolute path and probably doesn’t match anything (unless you have a resources directory at the root of your filesystem and an init directory inside it, but I doubt that).
    3. Your second attempt uses src/main/resources/init/ assuming paths are relative to your project’s root directory, but I doubt they are. More likely they’re relative to whatever directory you start your application from (and in the case of tests with Maven, that’s probably ./target).

    In your case I’d try this instead?

    quarkus.datasource.devservices.volumes."classpath:./init/"=/container/resources/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search