I have postgres docker question.
After following this link How to create User/Database in script for Docker Postgres
I have added .sql files to init folder. All queries are executing, but the problem is tables are getting created in default postgres database instead of the database i have created.
SQL Files i have
01-init.sql
CREATE USER test;
CREATE DATABASE orders;
GRANT ALL PRIVILEGES ON DATABASE orders TO test;
02-tables.sql
CREATE TABLE IF NOT EXISTS orders_list
(
id uuid,
data jsonb,
created_date timestamp with time zone DEFAULT now(),
modified_date timestamp with time zone DEFAULT now(),
CONSTRAINT orders_pkey PRIMARY KEY (id)
);
Once i'm done with docker-compose up. As expected all queries executed inside the init folder.
But as i mentioned earlier the tables.sql created the tables under postgres database.
Can anyone explain or explain how to fix this ?
I want the tables to be created under orders database.
Note: I'm asking in the context of postgres docker-compose, I know create database
does not mean i have switched to that database, i want to know how to do this by using .sql files itself.
- Solutions & Problems i'm foreseeing
In case if i have to write shell script to create database first then i have to use psql to execute the table files.
If i copy the sql files to init folder it will automatically run all the sql files. How can i stop init.d to run all the sql files copied ?