I like to be able to execute sql script file and then
directory of scripts and then another directory of scripts .
how can i control the order if execution what is mapped under docker-entrypoint-initdb.d
for example : i have
run_me_first.sql
direcoty_first
a.sql
aa.sql
directory_second
bb.sql
i like to be able to execute:
First : run_me_first.sql
Second : direcoty_first -> the inner scripts order dosn't matter
third: directory_second -> the inner scripts order don't matter
using the docker-compose mapping to docker-entrypoint-initdb.d how can i control the scrips executing order
They should execute in lexicographical (sorted, alphabetical) order; if you name them 01-bb.sql, 02-a.sql, 03-aa.sql that will be the ordering.
When the container first starts up, the postgres image entrypoint specifies the scripts to run at startup time as just
docker_process_init_files /docker-entrypoint-initdb.d/*
(where docker_process_init_files is a shell function defined earlier in the script). When the shell expands this pattern, the POSIX.1 shell specification indicates
If the pattern matches any existing filenames or pathnames, the pattern shall be replaced with those filenames and pathnames, sorted according to the collating sequence in effect in the current locale. If this collating sequence does not have a total ordering of all characters (see XBD LC_COLLATE), any filenames or pathnames that collate equally should be further compared byte-by-byte using the collating sequence for the POSIX locale.
The flip side of this is that the scripts have to directly be in the /docker-entrypoint-initdb.d directory, setup scripts in subdirectories will not be noticed by this particular filename expansion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With