Skip to content

Fix: create 'shared' schema before shared DB connection #17

@chendingplano

Description

@chendingplano

Problem

On a fresh production system, the goose migrator fails on startup with:

ERROR Failed to ensure goose version table
  table_name="shared_migration"
  error="failed to create goose version table (MID_26033108): failed to create version table \"shared_migration\": pq: no schema has been selected to create in"

This causes the server to exit immediately.

Root Cause

SharedDBHandle connects with search_path=shared, so all tables it creates (including the goose migration tracking table shared_migration) go into the shared schema. However, PostgreSQL only has the public schema by default — if the shared schema doesn't exist yet, any CREATE TABLE on that connection fails with "no schema has been selected to create in".

The schema creation code in createPGDB() was commented out, so the shared schema was never created automatically.

Fix

Added CREATE SCHEMA IF NOT EXISTS shared using the ProjectDBHandle (which connects to public with full permissions) immediately before creating the SharedDBHandle. This is idempotent — safe to run on existing systems where the schema already exists.

Affected File

  • go/api/ApiUtils/ApiUtils.gocreatePGDB() function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions