I am using the postgres docker image to create a local database for development. A feature of the image is that any shell scripts in a directory will be run on startup, I use this to setup my schema and users. Everything is working great for creating my schema and user with full access to it, however when I create a read only user things don't seem to work. The script appears to suddenly stop without granting the read only access I request. Its not a syntax issue because I can use psql to connect to the database and copy paste the commands which works perfectly.
The shell script that runs any sql files in the directory, only one for now.
for sql in /docker-entrypoint-initdb.d/*.sql
do
gosu postgres postgres --single < $sql
done
The actual sql file that gets run (connection details redacted)
-- Main user with full access to its schema
CREATE SCHEMA s;
CREATE USER u PASSWORD 'p';
GRANT ALL ON SCHEMA s TO u;
GRANT ALL ON ALL TABLES IN SCHEMA s TO u;
-- Readonly user
CREATE USER readonly PASSWORD 'r';
-- THE FOLLOWING DOESN'T SEEM TO RUN
-- Allows read on everything in schema s
GRANT USAGE ON SCHEMA s TO readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA s TO readonly;
Its those last two commands that don't seem to run. I can connect with the user 'readonly' but will get permission errors on schema 's' until I use psql to re-run the last two commands on the database.
The logs contain no errors or warnings