0

Dears,
I have following file structure

-api
-database
 -init
  -create_database.sql
 -dane
 -domains.sql
 -procedures.sql
 -schema.sql
 -sequences.sql
 -tables.sql
 -views.sql
-docker-compose.yml

docker-compose.yml:

version: '3.1'

services:
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: example
      POSTGRES_PASSWORD: example
      POSTGRES_DB: DB
    container_name: postgres
    ports:
      - "5432:5432"
    volumes:
      - ./database/init:/docker-entrypoint-initdb.d/

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

create_database.sql

BEGIN;
\i schema.sql
\i domains.sql
\i sequences.sql
\i tables.sql
\i procedures.sql
\i dane/insert_default_expenses.sql
\i dane/insert_default_incomes.sql
\i dane/insert_default_payment.sql
\i dane/insert_users.sql
\i dane/insert_expenses.sql
\i dane/insert_incomes.sql
\i views.sql
COMMIT;

My issue is that I am not able to recreate database structure. I know that there is an issue with a path to slq files. Can someone help me ?

  • What happens? What error do you get? (Given the filesystem layout you show, are those files visible in the container at all?) – David Maze Apr 23 '20 at 11:08
  • Hello David, thank you for asking. I think that issue is caused by creating_database.sql file because when docker runs it moves that file to new folder /docker-entrypoint-initdb.d . creating_database.sql is being run by docker and I receiving: psql:/docker-entrypoint-initdb.d/create_database.sql:2: error: schema.sql: No such file or directory. I think docker is not able to find files like schema.sql because the directory right now is different. – Łukasz Naróg Apr 23 '20 at 14:09
  • 1
    You should be able to put all of these script files in the `docker-entrypoint-initdb.d` directory. They will be executed in lexicographic order, so naming them `01-schema.sql`, `02-domains.sql`, and so on will make the order correct. But they all need to be in that single directory (not a subdirectory), and you do not need a separate wrapper like this to run them. – David Maze Apr 23 '20 at 15:41
  • 1
    Since this only runs the very first time the database is created, you also might consider creating an empty database at startup time and running your application's normal database migration system. – David Maze Apr 23 '20 at 15:41

0 Answers0