Skip to content

Commit

Permalink
Bump postgres to 17
Browse files Browse the repository at this point in the history
Rename the database while we're at it
  • Loading branch information
Earlopain committed Dec 11, 2024
1 parent 79d3cf2 commit 76c2ef5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE:-ruby:3.3.6-alpine3.21} AS ruby-builder

RUN apk --no-cache add build-base cmake postgresql16-dev git
RUN apk --no-cache add build-base cmake postgresql17-dev git

COPY Gemfile Gemfile.lock ./
RUN gem i foreman && bundle install \
Expand All @@ -19,7 +19,7 @@ WORKDIR /app

RUN apk --no-cache add \
tzdata \
postgresql16-client \
postgresql17-client \
vips ffmpeg \
sudo jemalloc

Expand Down
8 changes: 2 additions & 6 deletions app/logical/docker_env.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module DockerEnv
NEEDED_PG_VERSION = "16"
NEEDED_PG_VERSION = "17"

module_function

Expand All @@ -16,11 +16,7 @@ def selenium_url
end

def pg_data_version
File.read("/docker/db_data/PG_VERSION").strip
rescue StandardError
# On first boot the entrypoint was not yet able to modify permissions of the file.
# Only subsequent ups will do that. The first start will have the correct version anyways
NEEDED_PG_VERSION
`sudo cat /docker/db_data/PG_VERSION`.strip.presence || NEEDED_PG_VERSION
end

def specifies_docker_user?
Expand Down
19 changes: 16 additions & 3 deletions app/views/application/pg_version_mismatch.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<h1> Postgres database version mismatch: <%= DockerEnv.pg_data_version %> vs <%= DockerEnv::NEEDED_PG_VERSION %></h1>
<h1> Postgres database version mismatch: <%= DockerEnv::NEEDED_PG_VERSION %> (wanted) vs <%= DockerEnv.pg_data_version %> (actual)</h1>

FoxTrove updated its version of Postgres and requires action from your side:
TODO (:
FoxTrove updated its version of Postgres and requires action from your side. Please don't forget to make a backup before you start.

<ol>
<li>Stop services (keep this tab open). <br><code>docker compose down</code></li>
<li>Check out the last commit with previous postgres version. <br><code>git checkout 79d3cf242323ec5b0c228a1e3f9074f9f7599bf5</code></li>
<li>Start postgres to take a backup. <br><code>docker compose up -d postgres</code></li>
<li>Dump the data. <br><code>docker compose exec postgres pg_dump reverser_development -U reverser > backup.sql</code></li>
<li>Stop postgres. <br><code>docker compose down</code></li>
<li>Checkout out the current latest commit. <br><code>git checkout master</code></li>
<li>Remove old data. <br><code>rm -R ${FOXTROVE_DATA_PATH}/db_data</code></li>
<li>Start postgres to import the backup. <br><code>docker compose up -d postgres</code></li>
<li>Import the backup. <br><code>docker compose exec -T postgres psql -U foxtrove -d foxtrove_development < backup.sql</code></li>
<li>Start services. <br><code>docker compose up</code></li>
<li>Reload the page, this error should now be gone.</li>
</ol>

<% page_title "Version Mismatch" %>
6 changes: 3 additions & 3 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
default: &default
adapter: postgresql
encoding: unicode
username: reverser
username: foxtrove
host: <%= ENV.fetch("POSTGRES_HOST") { "postgres" } %>
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 15 } %>

development:
<<: *default
database: reverser_development
database: foxtrove_development

test:
<<: *default
database: reverser_test
database: foxtrove_test
12 changes: 4 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,21 @@ services:
command: foreman start --color

postgres:
image: postgres:16.6-alpine3.21
image: postgres:17.2-alpine3.21
environment:
- POSTGRES_USER=reverser
- POSTGRES_DB=reverser_development
- POSTGRES_USER=foxtrove
- POSTGRES_DB=foxtrove_development
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- ${REVERSER_DATA_PATH:-${FOXTROVE_DATA_PATH:-./data}}/db_data:/var/lib/postgresql/data
shm_size: 256mb
ports:
- ${EXPOSED_POSTGRES_PORT:-34518}:5432
healthcheck:
test: [CMD-SHELL, pg_isready -d reverser_development -U reverser]
test: [CMD-SHELL, pg_isready -d foxtrove_development -U foxtrove]
interval: 10s
timeout: 5s
retries: 5
# Make the version file world readable. Will only happen on second boot when the data actually exists
entrypoint: [/bin/sh, -c, chmod -f +r /var/lib/postgresql/data/PG_VERSION || true && docker-entrypoint.sh postgres]
# By default the command is "postgres" but that wouldn't properly appended to the entrypoint anymore
command: ""

iqdb:
image: ghcr.io/earlopain/iqdb:897214ffdc0b1ca18d1f9ca4749dff40d2dad2fc
Expand Down

0 comments on commit 76c2ef5

Please sign in to comment.