When start a docker container from postgres image, it only creates a public schema under a database. here is my setting
postgres:
container_name: postgres
image: postgres:latest
ports:
- "${DB_PORT}:5432"
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
my solution is
// 111111-create-schema.js
await queryInterface.createSchema('custom');
// 222222-create-user.js
await queryInterface.createTable('Users', {}, {schema: 'custom'}
When I run npx sequelize-cli db:migrate
, I do see my user table in custom schema. However, the sequelizeMeta table which stores the migrations is in PUBLIC shema
I also tried to add schema: 'custom'
in config.json. however, I got custom schema is not found error when I run db:migrate. I assume at that point my migration script has not run yet before it trys to locate this custom schema.
Then I tried to manually create the schema in the pgadmin. then I see both my user and sequelizeMeta table are in this custom schema.
I am wondering how I can let postgres docker container precreate a schema just like it precreate a database using a POSTGRES_DB environment variable ? something like
postgres:
container_name: postgres
image: postgres:latest
ports:
- "${DB_PORT}:5432"
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
- POSTGRES_SCHEMA=${DB_SCHEMA} <---------------
Or there is an easy or proper way in sequelize migration that I missed ?