Skip to content

A platform for community discussion. Free, open, simple.

DEV: Handle running TemporaryDb as root (#38988)

Jarek Radosz0092d481f375
diff --git a/lib/temporary_db.rb b/lib/temporary_db.rb
index 00a746f2f5c..d2642c65be3 100644
--- a/lib/temporary_db.rb
+++ b/lib/temporary_db.rb
@@ -8,11 +8,13 @@ class TemporaryDb
PG_TEMP_PREFIX = "pg_schema_tmp"
VERSIONS = 10..30 # arbitrary upper limit to avoid updating this code for a long time
STARTUP_TIMEOUT_SECONDS = 60
+ DEFAULT_PG_SYSTEM_USER = "postgres"
- def initialize
+ def initialize(pg_system_user: DEFAULT_PG_SYSTEM_USER)
@pg_temp_path = File.join(Dir.tmpdir, "#{PG_TEMP_PREFIX}_#{SecureRandom.hex(6)}")
@pg_conf = "#{@pg_temp_path}/postgresql.conf"
@pg_sock_path = "#{@pg_temp_path}/sockets"
+ @pg_system_user = pg_system_user
end
def port_available?(port)
@@ -41,6 +43,10 @@ class TemporaryDb
bin_path = "/Applications/Postgres.app/Contents/Versions/latest/bin"
return @pg_bin_path = bin_path if File.exist?("#{bin_path}/pg_ctl")
+ # Fallback: check if pg_ctl is on PATH (e.g. Fedora system packages install to /usr/bin)
+ pg_ctl = `which pg_ctl 2>/dev/null`.strip
+ return @pg_bin_path = File.dirname(pg_ctl) if pg_ctl.present?
+
raise "Cannot find pg_ctl. Install the PostgreSQL server package."
end
@@ -82,7 +88,9 @@ class TemporaryDb
def stop
@started = false
- `#{pg_ctl_path} -D '#{@pg_temp_path}' stop`
+ args = [pg_ctl_path, "-D", @pg_temp_path, "stop"]
+ args = ["sudo", "-u", @pg_system_user, *args] if running_as_root?
+ Open3.capture3(*args)
ensure
restore_discourse_pg_port
end
@@ -154,6 +162,7 @@ class TemporaryDb
def configure_ports
FileUtils.mkdir(@pg_sock_path)
+ FileUtils.chown(@pg_system_user, nil, @pg_sock_path) if running_as_root?
conf = File.read(@pg_conf)
File.write(@pg_conf, conf + "\nport = #{pg_port}\nunix_socket_directories = '#{@pg_sock_path}'")
end
@@ -202,6 +211,7 @@ class TemporaryDb
end
def run_command!(*args, error_prefix:)
+ args = ["sudo", "-u", @pg_system_user, *args] if running_as_root?
stdout, stderr, status = Open3.capture3(*args)
return if status.success?
@@ -213,6 +223,10 @@ class TemporaryDb
raise "#{error_prefix}: #{e.message}"
end
+ def running_as_root?
+ Process.uid == 0
+ end
+
def restore_discourse_pg_port
ENV["DISCOURSE_PG_PORT"] = @previous_discourse_pg_port
@previous_discourse_pg_port = nil
diff --git a/migrations/config/schema/plugin_manifest.yml b/migrations/config/schema/plugin_manifest.yml
index c459f9e0cc4..79fe8f2c948 100644
--- a/migrations/config/schema/plugin_manifest.yml
+++ b/migrations/config/schema/plugin_manifest.yml
@@ -57,6 +57,7 @@ plugins:
columns: {}
discourse-ai:
tables:
+ - ai_agent_mcp_servers
- ai_agents
- ai_api_audit_logs
- ai_api_request_stats
@@ -64,6 +65,8 @@ plugins:
- ai_artifact_versions
- ai_artifacts
- ai_document_fragments_embeddings
+ - ai_mcp_oauth_tokens
+ - ai_mcp_servers
- ai_moderation_settings
- ai_posts_embeddings
- ai_secrets
@@ -194,11 +197,11 @@ plugin_checksums:
chat: a44b3089f09fe0cef90e270aa2b4bedb
discourse-adplugin: 9e52419decf1099c5bc301a90e6cc91a
discourse-affiliate: '08c6e1a851441a082e9be9ddddc63910'
- discourse-ai: c85508b1ece1b90b668d1a65a1d8af85
+ discourse-ai: '093aaf7828d3b833e4dfeae25d2cca02'
discourse-assign: 65afd026c76ff19a8d4f0ed1d9c21aa1
discourse-cakeday: a5bb91366c8dc8d267088eb0c2679187
discourse-calendar: 8ec0c0ab443991a508c337ee137c4bba
- discourse-chat-integration: e39798f3f1a02b0c774f9d6c0595a2c7
+ discourse-chat-integration: ffa3bf5dba9089491d2fc02971eb96f8
discourse-data-explorer: 3c8891eb000d2f91f1edf1a48c28a96e
discourse-gamification: 864797c200fde3faf8508c500af6915d
discourse-github: 3bd17b2c09828e232e7565edbf2c746f
diff --git a/migrations/lib/database/intermediate_db/enums/site_setting_datatype.rb b/migrations/lib/database/intermediate_db/enums/site_setting_datatype.rb
index 1ce83c9ba53..aaecf8deff6 100644
--- a/migrations/lib/database/intermediate_db/enums/site_setting_datatype.rb
+++ b/migrations/lib/database/intermediate_db/enums/site_setting_datatype.rb
@@ -42,6 +42,7 @@ module Migrations
LOCALE_ENUM = 29
TOPIC = 30
DATETIME = 31
+ ICON = 32
end
end
end