discourse/script/start_test_db.rb
David Taylor 8a6d7a4594
DEV: Improve db_structure tasks (#40067)
- Try to use PG 15/16 for dump. Error if not available. PG17 has a
slightly different pg_dump output

- Update dump/check tasks to run all migrations from scratch. Previously
they were building on the existing schema, which could lead to drift

- Stop using UNLOGGED tables in CI. This causes a schema difference, and
any perf benefit can be retained using pg-server-level config.
2026-05-15 11:40:07 +01:00

43 lines
1 KiB
Ruby
Executable file
Vendored

#!/usr/bin/env ruby
# frozen_string_literal: true
BIN = "/usr/lib/postgresql/#{ENV["PG_MAJOR"]}/bin"
DATA = "/tmp/test_data/pg"
def run(*args)
system(*args, exception: true)
end
should_setup = true
should_run = true
should_exec = false
while a = ARGV.pop
if a == "--skip-setup"
should_setup = false
elsif a == "--skip-run"
should_run = false
elsif a == "--exec"
should_exec = true
else
raise "Unknown argument #{a}"
end
end
if should_setup
run "rm -rf #{DATA}"
run "mkdir -p #{DATA}"
run "#{BIN}/initdb -D #{DATA}"
run "echo fsync = off >> #{DATA}/postgresql.conf"
run "echo synchronous_commit = off >> #{DATA}/postgresql.conf"
run "echo full_page_writes = off >> #{DATA}/postgresql.conf"
run "echo wal_level = minimal >> #{DATA}/postgresql.conf"
run "echo max_wal_senders = 0 >> #{DATA}/postgresql.conf"
run "echo shared_buffers = 500MB >> #{DATA}/postgresql.conf"
end
if should_exec
exec "#{BIN}/postgres -D #{DATA}"
elsif should_run
run "#{BIN}/pg_ctl -D #{DATA} start"
end