@@ -9,35 +9,25 @@ function wait_for_postgres() {
9
9
done
10
10
}
11
11
12
- # Only run on first init
13
- if [ " $1 " = " postgres" ]; then
14
- # Create sidecar DBs and users
15
- IFS=' ,' read -ra DBS <<< " $POSTGRES_DB_SIDECARS"
16
- for DB in " ${DBS[@]} " ; do
17
- DB_TRIMMED=$( echo " $DB " | xargs)
18
- if [ -z " $DB_TRIMMED " ]; then continue ; fi
19
- DB_LOWER=$( echo " $DB_TRIMMED " | tr ' [:upper:]' ' [:lower:]' )
20
- USER=" ${DB_LOWER} _user"
21
- PASS=" mydefaultpassword"
22
- echo " Creating sidecar DB: $DB_TRIMMED and user: $USER "
23
- psql -v ON_ERROR_STOP=1 --username " $POSTGRES_USER " << -EOSQL
24
- DO
25
- $$
26
- BEGIN
27
- IF NOT EXISTS (SELECT FROM pg_database WHERE datname = '$DB_TRIMMED ') THEN
28
- CREATE DATABASE "$DB_TRIMMED ";
29
- END IF;
30
- IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '$USER ') THEN
31
- CREATE ROLE "$USER " WITH LOGIN PASSWORD '$PASS ';
32
- END IF;
33
- GRANT ALL PRIVILEGES ON DATABASE "$DB_TRIMMED " TO "$USER ";
34
- END
35
- $$ ;
36
- EOSQL
37
- # Enable pgvector if VECTOR_ prefix
38
- if [[ " $DB_TRIMMED " =~ ^VECTOR_ ]]; then
39
- echo " Enabling pgvector on $DB_TRIMMED "
40
- psql -v ON_ERROR_STOP=1 --username " $POSTGRES_USER " --dbname=" $DB_TRIMMED " -c " CREATE EXTENSION IF NOT EXISTS vector;"
41
- fi
42
- done
43
- fi
12
+ # Create sidecar DBs and users
13
+ IFS=' ,' read -ra DBS <<< " $POSTGRES_DB_SIDECARS"
14
+ for DB in " ${DBS[@]} " ; do
15
+ DB_TRIMMED=$( echo " $DB " | xargs)
16
+ if [ -z " $DB_TRIMMED " ]; then continue ; fi
17
+ DB_LOWER=$( echo " $DB_TRIMMED " | tr ' [:upper:]' ' [:lower:]' )
18
+ USER=" ${DB_LOWER} _user"
19
+ PASS=" mydefaultpassword"
20
+ echo " Creating sidecar DB: $DB_TRIMMED and user: $USER "
21
+
22
+ # Use the template file and envsubst
23
+ export DB_TRIMMED USER PASS
24
+ envsubst < /docker-entrypoint-initdb.d/init-multidb.sql.template > /tmp/init-multidb.sql
25
+ psql -v ON_ERROR_STOP=1 --username " $POSTGRES_USER " -f /tmp/init-multidb.sql
26
+ rm -f /tmp/init-multidb.sql
27
+
28
+ # Enable pgvector if VECTOR_ prefix (case-insensitive)
29
+ if [[ " $DB_TRIMMED " =~ ^[Vv][Ee][Cc][Tt][Oo][Rr]_ ]]; then
30
+ echo " Enabling pgvector on $DB_TRIMMED "
31
+ psql -v ON_ERROR_STOP=1 --username " $POSTGRES_USER " --dbname=" $DB_TRIMMED " -c " CREATE EXTENSION IF NOT EXISTS vector;"
32
+ fi
33
+ done
0 commit comments