Skip to content

Fix getting-started example: broken database setup#85

Open
danielgerlag wants to merge 2 commits into
mainfrom
getting-started-db
Open

Fix getting-started example: broken database setup#85
danielgerlag wants to merge 2 commits into
mainfrom
getting-started-db

Conversation

@danielgerlag
Copy link
Copy Markdown
Contributor

Problem

The getting-started example's manual tutorial flow was completely broken due to multiple inconsistencies between the database setup and server configuration:

  1. init.sql never executeddocker-compose.yml didn't mount it into /docker-entrypoint-initdb.d/, so the database was never initialized
  2. Password had no defaultserver-config.yaml used ${POSTGRES_PASSWORD} with no fallback, resolving to empty
  3. Publication/slot name mismatchinit.sql created drasi_pub/drasi_slot but the server config and scripts expected drasi_getting_started_pub/drasi_getting_started_slot
  4. Table/column casing mismatchinit.sql used PascalCase ("Message", "MessageId") but the server config and shell scripts used lowercase (message, messageid)
  5. External Docker networkdocker-compose.yml required a pre-existing drasi-network that setup-database.sh never created
  6. start-server.sh didn't set POSTGRES_PASSWORD

Changes

docker-compose.yml

  • Mount init.sql into /docker-entrypoint-initdb.d/ so the DB gets initialized
  • Use postgres superuser in healthcheck (guaranteed to exist)
  • Remove external drasi-network requirement (not needed; server connects via localhost)

init.sql

  • Lowercase table/column names to match server config and scripts
  • Fix publication name: drasi_pubdrasi_getting_started_pub
  • Fix slot name: drasi_slotdrasi_getting_started_slot

server-config.yaml

  • Add default password: ${POSTGRES_PASSWORD:-drasi_password}

start-server.sh

  • Export POSTGRES_PASSWORD=drasi_password as default before launching server

Not affected

  • run-end-to-end.sh and CI workflows do their own inline schema setup, so they are unaffected by these changes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the examples/getting-started manual tutorial flow by aligning PostgreSQL initialization, server configuration, and helper scripts so the database is actually initialized and the server can connect with sensible defaults.

Changes:

  • Ensures the getting-started Postgres container executes init.sql on first startup and simplifies healthcheck/networking.
  • Aligns getting-started schema/config/scripts around the Message table name and updated publication/slot names.
  • Adds a default POSTGRES_PASSWORD for the server config and exports it in start-server.sh.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
examples/getting-started/server-config.yaml Adds default DB password and updates table name / Cypher labels to Message.
examples/getting-started/scripts/start-server.sh Exports a default POSTGRES_PASSWORD before launching the server.
examples/getting-started/scripts/setup-database.sh Updates verification query to reference "Message".
examples/getting-started/scripts/run-end-to-end.sh Updates inline schema/setup SQL to use "Message" consistently.
examples/getting-started/scripts/delete-message.sh Updates SQL statements to reference "Message".
examples/getting-started/scripts/add-message.sh Updates SQL statement to reference "Message".
examples/getting-started/database/init.sql Updates schema columns to lowercase + adjusts publication/slot names for getting-started.
examples/getting-started/database/docker-compose.yml Mounts init.sql into /docker-entrypoint-initdb.d/, switches healthcheck user, removes external network requirement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/getting-started/database/init.sql
Comment thread examples/getting-started/database/init.sql
Comment thread examples/getting-started/scripts/run-end-to-end.sh
Comment thread examples/getting-started/scripts/add-message.sh
Comment thread examples/getting-started/scripts/delete-message.sh
- "${POSTGRES_HOST_PORT:-5432}:5432"
volumes:
- getting_started_postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this if the user is going to run docker exec -i getting-started-postgres psql -U postgres -d getting_started < examples/getting-started/database/init.sql?

See https://drasi.io/drasi-server/getting-started/#initialize-the-database

BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'drasi_slot') THEN
PERFORM pg_create_logical_replication_slot('drasi_slot', 'pgoutput');
IF NOT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'drasi_getting_started_slot') THEN
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we use the wizard to create the server config yaml file, it uses drasi_slot instead of drasi_getting_started_slot. The users will use this yaml file instead of server-config.yaml.

I suggest we update server-config.yaml to use drasi_slot so that it is consistent with the output from the wizard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants