Compare commits

..

3 Commits

Author SHA1 Message Date
Mike Lang 9e6e20cee2 schema: Create a type for image areas
This creates a new postgres "domain" which is a subtype of some other type
(in this case, of INTEGER[]) with some constraints applied.
We use this to create a type which is explicitly an array of length 4.

This saves us from needing to repeat this constraint everywhere (which already led to one copy-paste error)
and is arguably clearer in intent.
5 months ago
Mike Lang de3e85c893 Fixes to make postgres 17 work
- WUBLOADER_USER now explicitly requires a grant on the public schema to create tables
- `wal_keep_segments` renamed to `wal_keep_size` and is now a file size, not a number of segments
- Remove some other config entries which did nothing or matched defaults
5 months ago
Christopher Usher fed653dfbd Updated Postgres version 5 months ago

@ -1,4 +1,4 @@
FROM postgres:12 FROM postgres:17
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 / COPY postgres/buscribe.sql /

@ -26,6 +26,10 @@ CREATE TYPE thumbnail_mode as ENUM (
'CUSTOM' 'CUSTOM'
); );
-- Represents an area in an image as (left, top, bottom, right)
-- or equivalently as (x1, y1, x2, y2) where x is the top-left corner and y is the bottom-right.
CREATE DOMAIN box_coords AS INTEGER[] CHECK (cardinality(VALUE) = 4 OR VALUE IS NULL);
-- The end time for an event can be unset, "--" or a timestamp. -- The end time for an event can be unset, "--" or a timestamp.
-- If dashed is true, value should be the same as start time (which may be NULL if start time is unset). -- If dashed is true, value should be the same as start time (which may be NULL if start time is unset).
-- Otherwise value is the value (which may be NULL if end time is unset). -- Otherwise value is the value (which may be NULL if end time is unset).
@ -89,14 +93,8 @@ CREATE TABLE events (
OR thumbnail_mode = 'NONE' OR thumbnail_mode = 'NONE'
OR thumbnail_last_written IS NOT NULL OR thumbnail_last_written IS NOT NULL
), ),
thumbnail_crop INTEGER[] CHECK ( thumbnail_crop box_coords, -- pixel coordinates to crop the selected frame
cardinality(thumbnail_crop) = 4 thumbnail_location box_coords, -- pixel coordinates to position the cropped frame
OR thumbnail_crop IS NULL
), -- left, upper, right, and lower pixel coordinates to crop the selected frame
thumbnail_location INTEGER[] CHECK (
cardinality(thumbnail_location) = 4
OR thumbnail_location IS NULL
), -- left, top, right, bottom pixel coordinates to position the cropped frame
state event_state NOT NULL DEFAULT 'UNEDITED', state event_state NOT NULL DEFAULT 'UNEDITED',
uploader TEXT CHECK (state IN ('UNEDITED', 'EDITED', 'DONE', 'MODIFIED') OR uploader IS NOT NULL), uploader TEXT CHECK (state IN ('UNEDITED', 'EDITED', 'DONE', 'MODIFIED') OR uploader IS NOT NULL),
@ -194,6 +192,6 @@ CREATE TABLE templates (
image BYTEA NOT NULL, image BYTEA NOT NULL,
description TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '',
attribution TEXT NOT NULL DEFAULT '', attribution TEXT NOT NULL DEFAULT '',
crop INTEGER[] NOT NULL CHECK (cardinality(crop) = 4), crop box_coords NOT NULL,
location INTEGER[] NOT NULL CHECK (cardinality(location) = 4) location box_coords NOT NULL
); );

@ -1,6 +1,6 @@
#! /bin/bash #! /bin/bash
set -e set -eu
sql() { sql() {
local user local user
@ -14,9 +14,10 @@ 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"
sql "$POSTGRES_USER" <<-EOSQL sql "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOSQL
CREATE USER $WUBLOADER_USER LOGIN PASSWORD '$WUBLOADER_PASSWORD'; CREATE USER $WUBLOADER_USER LOGIN PASSWORD '$WUBLOADER_PASSWORD';
GRANT CREATE ON SCHEMA public TO $WUBLOADER_USER;
EOSQL EOSQL
@ -32,11 +33,7 @@ if [ -n "$REPLICATION_USER" ]; then
EOSQL EOSQL
cat >> ${PGDATA}/postgresql.conf <<-EOF cat >> ${PGDATA}/postgresql.conf <<-EOF
wal_level = replica wal_keep_size = 128MB
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 8
wal_keep_segments = 8
EOF EOF
fi fi

Loading…
Cancel
Save