Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 7654735

Browse files
authored
Fix make_full_schema to create the db with the right options and user (#9931)
1 parent b65ecaf commit 7654735

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

changelog.d/9931.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Minor fixes to the `make_full_schema.sh` script.

scripts-dev/make_full_schema.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# It does so by having Synapse generate an up-to-date SQLite DB, then running
77
# synapse_port_db to convert it to Postgres. It then dumps the contents of both.
88

9-
POSTGRES_HOST="localhost"
9+
export PGHOST="localhost"
1010
POSTGRES_DB_NAME="synapse_full_schema.$$"
1111

1212
SQLITE_FULL_SCHEMA_OUTPUT_FILE="full.sql.sqlite"
@@ -32,7 +32,7 @@ usage() {
3232
while getopts "p:co:h" opt; do
3333
case $opt in
3434
p)
35-
POSTGRES_USERNAME=$OPTARG
35+
export PGUSER=$OPTARG
3636
;;
3737
c)
3838
# Print all commands that are being executed
@@ -69,7 +69,7 @@ if [ ${#unsatisfied_requirements} -ne 0 ]; then
6969
exit 1
7070
fi
7171

72-
if [ -z "$POSTGRES_USERNAME" ]; then
72+
if [ -z "$PGUSER" ]; then
7373
echo "No postgres username supplied"
7474
usage
7575
exit 1
@@ -84,8 +84,9 @@ fi
8484
# Create the output directory if it doesn't exist
8585
mkdir -p "$OUTPUT_DIR"
8686

87-
read -rsp "Postgres password for '$POSTGRES_USERNAME': " POSTGRES_PASSWORD
87+
read -rsp "Postgres password for '$PGUSER': " PGPASSWORD
8888
echo ""
89+
export PGPASSWORD
8990

9091
# Exit immediately if a command fails
9192
set -e
@@ -131,9 +132,9 @@ report_stats: false
131132
database:
132133
name: "psycopg2"
133134
args:
134-
user: "$POSTGRES_USERNAME"
135-
host: "$POSTGRES_HOST"
136-
password: "$POSTGRES_PASSWORD"
135+
user: "$PGUSER"
136+
host: "$PGHOST"
137+
password: "$PGPASSWORD"
137138
database: "$POSTGRES_DB_NAME"
138139
139140
# Suppress the key server warning.
@@ -150,7 +151,7 @@ scripts-dev/update_database --database-config "$SQLITE_CONFIG"
150151

151152
# Create the PostgreSQL database.
152153
echo "Creating postgres database..."
153-
createdb $POSTGRES_DB_NAME
154+
createdb --lc-collate=C --lc-ctype=C --template=template0 "$POSTGRES_DB_NAME"
154155

155156
echo "Copying data from SQLite3 to Postgres with synapse_port_db..."
156157
if [ -z "$COVERAGE" ]; then
@@ -181,7 +182,7 @@ DROP TABLE user_directory_search_docsize;
181182
DROP TABLE user_directory_search_stat;
182183
"
183184
sqlite3 "$SQLITE_DB" <<< "$SQL"
184-
psql $POSTGRES_DB_NAME -U "$POSTGRES_USERNAME" -w <<< "$SQL"
185+
psql "$POSTGRES_DB_NAME" -w <<< "$SQL"
185186

186187
echo "Dumping SQLite3 schema to '$OUTPUT_DIR/$SQLITE_FULL_SCHEMA_OUTPUT_FILE'..."
187188
sqlite3 "$SQLITE_DB" ".dump" > "$OUTPUT_DIR/$SQLITE_FULL_SCHEMA_OUTPUT_FILE"

0 commit comments

Comments
 (0)