Skip to content

Commit 7b5a37a

Browse files
committed
Move the create db scripts last in the init
1 parent c5af5d5 commit 7b5a37a

File tree

5 files changed

+68
-59
lines changed

5 files changed

+68
-59
lines changed

containers/server-postgresql-image/root/docker-entrypoint-initdb.d/create-db.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

containers/server-postgresql-image/root/docker-entrypoint-initdb.d/create-reportdb.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
MANAGER_DB_NAME=susemanager
3+
4+
run_sql() {
5+
PGHOST= PGHOSTADDR= psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" --no-password --no-psqlrc "$@"
6+
}
7+
8+
echo "CREATE DATABASE $MANAGER_DB_NAME ENCODING = UTF8 ;" | run_sql
9+
echo "CREATE ROLE $MANAGER_USER PASSWORD '$MANAGER_PASSWORD' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;" | run_sql
10+
echo "GRANT ALL PRIVILEGES ON DATABASE $MANAGER_DB_NAME TO $MANAGER_USER;" | run_sql -d $MANAGER_DB_NAME
11+
echo "GRANT ALL PRIVILEGES ON SCHEMA public TO $MANAGER_USER;" | run_sql -d $MANAGER_DB_NAME
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
REPORTDB_NAME=reportdb
4+
5+
run_sql() {
6+
PGHOST= PGHOSTADDR= psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" --no-password --no-psqlrc "$@"
7+
}
8+
9+
echo "CREATE DATABASE $REPORTDB_NAME ENCODING = UTF8 ;" | run_sql
10+
echo "CREATE ROLE $REPORTDB_USER PASSWORD '$REPORTDB_PASSWORD' NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN;" | run_sql -d $REPORTDB_NAME
11+
echo "GRANT ALL PRIVILEGES ON DATABASE $REPORTDB_NAME TO $REPORTDB_USER;" | run_sql -d $REPORTDB_NAME
12+
echo "GRANT ALL PRIVILEGES ON SCHEMA public TO $REPORTDB_USER;" | run_sql -d $REPORTDB_NAME

containers/server-postgresql-image/root/docker-entrypoint-initdb.d/evr_t.sql renamed to containers/server-postgresql-image/root/docker-entrypoint-initdb.d/zz-evr_t.sh

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
--
2-
-- Copyright (c) 2008--2013 Red Hat, Inc.
3-
--
4-
-- This software is licensed to you under the GNU General Public License,
5-
-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
6-
-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
7-
-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8-
-- along with this software; if not, see
9-
-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10-
--
11-
-- Red Hat trademarks are not licensed under GPLv2. No permission is
12-
-- granted to use or replicate Red Hat trademarks that are incorporated
13-
-- in this software or its documentation.
14-
--
15-
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2008--2013 Red Hat, Inc.
4+
#
5+
# This software is licensed to you under the GNU General Public License,
6+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
7+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
8+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
9+
# along with this software; if not, see
10+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
11+
#
12+
# Red Hat trademarks are not licensed under GPLv2. No permission is
13+
# granted to use or replicate Red Hat trademarks that are incorporated
14+
# in this software or its documentation.
15+
#
16+
17+
run_sql() {
18+
PGHOST= PGHOSTADDR= psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" --no-password --no-psqlrc -d susemanager "$@"
19+
}
20+
21+
cat << EOF | run_sql
1622
create type evr_t as (
1723
epoch varchar(16),
1824
version varchar(512),
@@ -21,12 +27,12 @@ create type evr_t as (
2127
);
2228
2329
create or replace function evr_t(e varchar, v varchar, r varchar, t varchar)
24-
returns evr_t as $$
25-
select row($1,$2,$3,$4)::evr_t
26-
$$ language sql;
30+
returns evr_t as \$\$
31+
select row(\$1,\$2,\$3,\$4)::evr_t
32+
\$\$ language sql;
2733
2834
create or replace function evr_t_compare( a evr_t, b evr_t )
29-
returns int as $$
35+
returns int as \$\$
3036
begin
3137
if a.type = b.type then
3238
if a.type = 'rpm' then
@@ -45,49 +51,49 @@ begin
4551
end if;
4652
end if;
4753
end;
48-
$$ language plpgsql immutable strict;
54+
\$\$ language plpgsql immutable strict;
4955
5056
create or replace function evr_t_lt( a evr_t, b evr_t )
51-
returns boolean as $$
57+
returns boolean as \$\$
5258
begin
5359
return evr_t_compare( a, b ) < 0;
5460
end;
55-
$$ language plpgsql immutable strict;
61+
\$\$ language plpgsql immutable strict;
5662
5763
create or replace function evr_t_le( a evr_t, b evr_t )
58-
returns boolean as $$
64+
returns boolean as \$\$
5965
begin
6066
return evr_t_compare( a, b ) <= 0;
6167
end;
62-
$$ language plpgsql immutable strict;
68+
\$\$ language plpgsql immutable strict;
6369
6470
create or replace function evr_t_eq( a evr_t, b evr_t )
65-
returns boolean as $$
71+
returns boolean as \$\$
6672
begin
6773
return evr_t_compare( a, b ) = 0;
6874
end;
69-
$$ language plpgsql immutable strict;
75+
\$\$ language plpgsql immutable strict;
7076
7177
create or replace function evr_t_ne( a evr_t, b evr_t )
72-
returns boolean as $$
78+
returns boolean as \$\$
7379
begin
7480
return evr_t_compare( a, b ) != 0;
7581
end;
76-
$$ language plpgsql immutable strict;
82+
\$\$ language plpgsql immutable strict;
7783
7884
create or replace function evr_t_ge( a evr_t, b evr_t )
79-
returns boolean as $$
85+
returns boolean as \$\$
8086
begin
8187
return evr_t_compare( a, b ) >= 0;
8288
end;
83-
$$ language plpgsql immutable strict;
89+
\$\$ language plpgsql immutable strict;
8490
8591
create or replace function evr_t_gt( a evr_t, b evr_t )
86-
returns boolean as $$
92+
returns boolean as \$\$
8793
begin
8894
return evr_t_compare( a, b ) > 0;
8995
end;
90-
$$ language plpgsql immutable strict;
96+
\$\$ language plpgsql immutable strict;
9197
9298
create operator < (
9399
leftarg = evr_t,
@@ -160,13 +166,13 @@ default for type evr_t using btree as
160166
function 1 evr_t_compare( evr_t, evr_t )
161167
;
162168
163-
create or replace function evr_t_as_vre( a evr_t ) returns varchar as $$
169+
create or replace function evr_t_as_vre( a evr_t ) returns varchar as \$\$
164170
begin
165171
return a.version || '-' || a.release || ':' || coalesce(a.epoch, '');
166172
end;
167-
$$ language plpgsql immutable strict;
173+
\$\$ language plpgsql immutable strict;
168174
169-
create or replace function evr_t_as_vre_simple( a evr_t ) returns varchar as $$
175+
create or replace function evr_t_as_vre_simple( a evr_t ) returns varchar as \$\$
170176
declare
171177
vre_out VARCHAR(256);
172178
begin
@@ -177,11 +183,11 @@ begin
177183
end if;
178184
return vre_out;
179185
end;
180-
$$ language plpgsql immutable strict;
186+
\$\$ language plpgsql immutable strict;
181187
182188
create or replace function evr_t_larger(a evr_t, b evr_t)
183189
returns evr_t
184-
as $$
190+
as \$\$
185191
begin
186192
if a > b
187193
then
@@ -190,10 +196,11 @@ begin
190196
return b;
191197
end if;
192198
end;
193-
$$ language plpgsql immutable strict;
199+
\$\$ language plpgsql immutable strict;
194200
195201
create aggregate max (
196202
sfunc=evr_t_larger,
197203
basetype=evr_t,
198204
stype=evr_t
199205
);
206+
EOF

0 commit comments

Comments
 (0)