buscribe: Do database schema and user setup

pull/414/head
Mike Lang 1 month ago
parent 5f3a02fd14
commit 005ff9dac7

@ -1,6 +1,7 @@
FROM postgres:12 FROM postgres:12
COPY postgres/setup.sh /docker-entrypoint-initdb.d/setup.sh COPY postgres/setup.sh /docker-entrypoint-initdb.d/setup.sh
COPY postgres/schema.sql / COPY postgres/schema.sql /
COPY postgres/buscribe.sql /
RUN chmod 0666 /docker-entrypoint-initdb.d/setup.sh RUN chmod 0666 /docker-entrypoint-initdb.d/setup.sh
COPY postgres/standby_setup.sh /standby_setup.sh COPY postgres/standby_setup.sh /standby_setup.sh
LABEL org.opencontainers.image.source https://github.com/dbvideostriketeam/wubloader LABEL org.opencontainers.image.source https://github.com/dbvideostriketeam/wubloader

@ -1,22 +1,3 @@
BEGIN TRANSACTION;
DROP TABLE IF EXISTS buscribe_verified_lines;
DROP TABLE IF EXISTS buscribe_line_speakers;
DROP TABLE IF EXISTS buscribe_speakers;
DROP TABLE IF EXISTS buscribe_verifiers;
DROP TABLE IF EXISTS buscribe_transcriptions;
ROLLBACK;
BEGIN TRANSACTION;
TRUNCATE buscribe_verified_lines RESTART IDENTITY CASCADE;
TRUNCATE buscribe_line_speakers RESTART IDENTITY CASCADE;
TRUNCATE buscribe_speakers RESTART IDENTITY CASCADE;
TRUNCATE buscribe_verifiers RESTART IDENTITY CASCADE;
TRUNCATE buscribe_transcriptions RESTART IDENTITY CASCADE;
ROLLBACK;
CREATE TABLE buscribe_transcriptions CREATE TABLE buscribe_transcriptions
( (
@ -43,19 +24,12 @@ CREATE TABLE buscribe_speakers
CREATE TABLE buscribe_verifiers CREATE TABLE buscribe_verifiers
( (
-- id SERIAL PRIMARY KEY,
email TEXT PRIMARY KEY, email TEXT PRIMARY KEY,
name TEXT NOT NULL name TEXT NOT NULL
); );
-- For testing
-- INSERT INTO buscribe_verifiers(email, name)
-- VALUES ('placeholder@example.com', 'Place Holder'),
-- ('aguy@example.com', 'Arnold Guyana');
CREATE TABLE buscribe_line_speakers CREATE TABLE buscribe_line_speakers
( (
-- id BIGSERIAL PRIMARY KEY,
line BIGINT NOT NULL REFERENCES buscribe_transcriptions, line BIGINT NOT NULL REFERENCES buscribe_transcriptions,
speaker BIGINT NOT NULL REFERENCES buscribe_speakers, speaker BIGINT NOT NULL REFERENCES buscribe_speakers,
verifier text NOT NULL REFERENCES buscribe_verifiers, verifier text NOT NULL REFERENCES buscribe_verifiers,
@ -71,7 +45,6 @@ CREATE TABLE buscribe_line_inferred_speakers
CREATE TABLE buscribe_verified_lines CREATE TABLE buscribe_verified_lines
( (
-- id BIGSERIAL PRIMARY KEY,
line BIGINT NOT NULL REFERENCES buscribe_transcriptions, line BIGINT NOT NULL REFERENCES buscribe_transcriptions,
verified_line TEXT NOT NULL, verified_line TEXT NOT NULL,
verifier text REFERENCES buscribe_verifiers, verifier text REFERENCES buscribe_verifiers,
@ -82,10 +55,6 @@ CREATE TABLE buscribe_verified_lines
CREATE INDEX buscribe_verified_lines_idx ON buscribe_verified_lines USING CREATE INDEX buscribe_verified_lines_idx ON buscribe_verified_lines USING
GIN (setweight(to_tsvector('english', verified_line), 'C')); GIN (setweight(to_tsvector('english', verified_line), 'C'));
BEGIN;
DROP VIEW buscribe_all_transcriptions;
CREATE VIEW buscribe_all_transcriptions AS CREATE VIEW buscribe_all_transcriptions AS
SELECT buscribe_transcriptions.id, SELECT buscribe_transcriptions.id,
start_time, start_time,
@ -127,8 +96,6 @@ FROM buscribe_transcriptions
GROUP BY line GROUP BY line
) AS speakers ON id = speakers.line; ) AS speakers ON id = speakers.line;
ROLLBACK;
CREATE VIEW buscribe_all_transcriptions2 AS CREATE VIEW buscribe_all_transcriptions2 AS
SELECT buscribe_transcriptions.id, SELECT buscribe_transcriptions.id,
start_time, start_time,

@ -2,12 +2,19 @@
set -e set -e
sql() {
local user
user="$1"
shift
psql -v ON_ERROR_STOP=1 -U "$user" "$@"
}
# only allow the $WUBLOADER_USER to connect remotely rather than all users # only allow the $WUBLOADER_USER to connect remotely rather than all users
sed -i "/host all all all/d" "$PGDATA/pg_hba.conf" sed -i "/host all all all/d" "$PGDATA/pg_hba.conf"
echo "host all $WUBLOADER_USER all md5" >> "$PGDATA/pg_hba.conf" echo "host all $WUBLOADER_USER all md5" >> "$PGDATA/pg_hba.conf"
echo "Creating $WUBLOADER_USER" echo "Creating $WUBLOADER_USER"
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER <<-EOSQL sql "$POSTGRES_USER" <<-EOSQL
CREATE USER $WUBLOADER_USER LOGIN PASSWORD '$WUBLOADER_PASSWORD'; CREATE USER $WUBLOADER_USER LOGIN PASSWORD '$WUBLOADER_PASSWORD';
@ -18,7 +25,7 @@ if [ -n "$REPLICATION_USER" ]; then
echo "Creating $REPLICATION_USER" echo "Creating $REPLICATION_USER"
# allow the $REPLICATION user to replicate remotely # allow the $REPLICATION user to replicate remotely
echo "host replication $REPLICATION_USER all md5" >> "$PGDATA/pg_hba.conf" echo "host replication $REPLICATION_USER all md5" >> "$PGDATA/pg_hba.conf"
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER <<-EOSQL sql "$POSTGRES_USER" <<-EOSQL
CREATE USER $REPLICATION_USER LOGIN REPLICATION PASSWORD '$REPLICATION_PASSWORD'; CREATE USER $REPLICATION_USER LOGIN REPLICATION PASSWORD '$REPLICATION_PASSWORD';
@ -35,27 +42,27 @@ if [ -n "$REPLICATION_USER" ]; then
fi fi
echo "Applying schema for $POSTGRES_DB" echo "Applying schema for $POSTGRES_DB"
psql -v ON_ERROR_STOP=1 -U $WUBLOADER_USER -d $POSTGRES_DB < /schema.sql sql "$WUBLOADER_USER" -d "$POSTGRES_DB" < /schema.sql
if [ -a /mnt/wubloader/nodes.csv ]; then if [ -a /mnt/wubloader/nodes.csv ]; then
echo "Loading nodes from nodes.csv" echo "Loading nodes from nodes.csv"
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d $POSTGRES_DB <<-EOF sql "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOF
COPY nodes FROM '/mnt/wubloader/nodes.csv' DELIMITER ',' CSV HEADER; COPY nodes FROM '/mnt/wubloader/nodes.csv' DELIMITER ',' CSV HEADER;
EOF EOF
fi fi
if [ -a /mnt/wubloader/editors.csv ]; then if [ -a /mnt/wubloader/editors.csv ]; then
echo "Loading editors from editors.csv" echo "Loading editors from editors.csv"
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d $POSTGRES_DB <<-EOF sql "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOF
COPY editors FROM '/mnt/wubloader/editors.csv' DELIMITER ',' CSV HEADER; COPY editors FROM '/mnt/wubloader/editors.csv' DELIMITER ',' CSV HEADER;
EOF EOF
fi fi
if [ -n "READONLY_USER" ]; then if [ -n "$READONLY_USER" ]; then
echo "Creating $READONLY_USER" echo "Creating $READONLY_USER"
# allow $READONLY_USER to connect remotely # allow $READONLY_USER to connect remotely
echo "host all $READONLY_USER all md5" >> "$PGDATA/pg_hba.conf" echo "host all $READONLY_USER all md5" >> "$PGDATA/pg_hba.conf"
psql -v ON_ERROR_STOP=1 -U $POSTGRES_USER -d $POSTGRES_DB <<-EOSQL sql "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOSQL
CREATE USER $READONLY_USER WITH CONNECTION LIMIT 50 LOGIN PASSWORD '$READONLY_PASSWORD'; CREATE USER $READONLY_USER WITH CONNECTION LIMIT 50 LOGIN PASSWORD '$READONLY_PASSWORD';
GRANT CONNECT ON DATABASE $POSTGRES_DB TO $READONLY_USER; GRANT CONNECT ON DATABASE $POSTGRES_DB TO $READONLY_USER;
@ -64,3 +71,14 @@ if [ -n "READONLY_USER" ]; then
EOSQL EOSQL
fi fi
if [ -n "$BUSCRIBE_USER" ]; then
echo "Creating $BUSCRIBE_USER"
echo "host all $BUSCRIBE_USER all md5" >> "$PGDATA/pg_hba.conf"
sql "$POSTGRES_USER" <<-EOSQL
CREATE USER $BUSCRIBE_USER LOGIN PASSWORD '$BUSCRIBE_PASSWORD';
EOSQL
echo "Applying schema for $BUSCRIBE_DB"
sql "$BUSCRIBE_USER" -d "$BUSCRIBE_DB" < /buscribe.sql
fi

Loading…
Cancel
Save