ERROR: syntax error at or near "CREATE" in Docker-compose Postgres

Viewed 569

I am trying to create two tables using docker-compose and a dockerfile with postgres sql. However, I get the following error.

psql:/docker-entrypoint-initdb.d/tables/users.sql:11: ERROR: syntax error at or near "CREATE" postgres_1 | LINE 2: CREATE TABLE users

I am not sure what I am doing wrong, but I checked my sql query via eversql.com/sql-syntax-check-validator/ and it seems to be valid sql.

could it be the version of the postgres image I am using or something else? My dockerfiles look correct to me but please do let me know if I am missing something.

Here is my Dockerfile

FROM postgres:latest

ADD /tables/ /docker-entrypoint-initdb.d/tables/
ADD /deploy_schemas.sql/ /docker-entrypoint-initdb.d/

Here is my deploy_schemas.sql

-- Deploy login and users tables

\i '/docker-entrypoint-initdb.d/tables/users.sql'
\i '/docker-entrypoint-initdb.d/tables/login.sql'

Here is my users.sql

BEGIN TRANSACTION


CREATE TABLE users (
    id serial PRIMARY KEY,
    name VARCHAR(100),
    email text UNIQUE NOT NULL,
    entries BIGINT DEFAULT 0,
    joined TIMESTAMP NOT NULL
);


COMMIT;

Here is my login.sql

BEGIN TRANSACTION 



CREATE TABLE login (
    id serial PRIMARY KEY,
    hash VARCHAR(100) NOT NULL,
    email text UNIQUE NOT NULL,
); 




COMMIT;

and finally here is docker-compose.yml

version: "3.8"

services:
  #Backend API
  smart-brain-api:
    container_name: backend
    build: ./
    command: npm start
    working_dir: /usr/src/test-api
    environment:
      POSTGRES_URI: postgres://admin:password@postgres:5432/test-api
    links:
      - postgres
    ports:
      - "3000:3000"
    volumes:
      - ./:/usr/src/test-api

  #Postgres
  postgres:
    environment:
      POSTGRES_USER: admin
      POSTGRES_DB: docker-test-api
      POSTGRES_HOST: postgres
      POSTGRES_PASSWORD: password
    build: ./postgres  
    ports:
      - "5432:5432"

any ideas?

1 Answers

you miss semicolon after BEGIN TRANSACTION

Related