Skip to content

Add basic postgres#324

Open
chris124567 wants to merge 17 commits into
masterfrom
christopher/add-postgres
Open

Add basic postgres#324
chris124567 wants to merge 17 commits into
masterfrom
christopher/add-postgres

Conversation

@chris124567

@chris124567 chris124567 commented May 14, 2026

Copy link
Copy Markdown
Member

Re: #321

This is meant to be a very literal translation of the sqlite with a minimum amount of changes for things that broke. I will do postgres specific optimizations in a followup PR.

To reviewers, use this command to view the difference between the sqlite files and the postgres files:

for f in persist/sqlite/*.go; do n=$(basename "$f"); o="persist/postgres/$n"; [ -f "$o" ] && git diff --no-index --color=always -- "$f" "$o"; done

Copilot AI review requested due to automatic review settings May 14, 2026 21:43

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@n8mgr

n8mgr commented May 14, 2026

Copy link
Copy Markdown
Member

@claude review

Comment thread persist/postgres/contracts.go
Comment thread persist/postgres/addresses.go
Comment thread persist/postgres/v2consensus.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an initial PostgreSQL persistence backend alongside the existing SQLite store, and refactors the store tests so the same suite can run against either backend.

Changes:

  • Introduces a new persist/postgres store implementation with schema initialization, encoding, transactions, chain updates, queries, host handling, metrics, and tests.
  • Refactors internal/storetest from SQLite-specific tests into shared backend tests with SQLite/PostgreSQL factories.
  • Adds PostgreSQL CI coverage and pgx-related dependencies.

Reviewed changes

Copilot reviewed 39 out of 40 changed files in this pull request and generated 28 comments.

Show a summary per file
File Description
.github/workflows/main.yml Adds a PostgreSQL-backed CI test job.
go.mod Adds PostgreSQL/pgx and test dependencies.
go.sum Adds checksums for new dependencies.
internal/storetest/addresses_test.go Moves address tests into shared storetest package.
internal/storetest/consensus_test.go Adds shared consensus store tests.
internal/storetest/contracts_test.go Moves contract tests into shared storetest package.
internal/storetest/events_test.go Moves event tests into shared storetest package.
internal/storetest/factory_postgres_test.go Adds PostgreSQL test-store factory.
internal/storetest/factory_sqlite_test.go Adds SQLite test-store factory.
internal/storetest/hosts_test.go Refactors host tests to use shared store helpers.
internal/storetest/metrics_test.go Moves metrics tests into shared storetest package.
internal/storetest/transactions_test.go Moves transaction tests into shared storetest package.
internal/storetest/v2consensus_test.go Moves v2 consensus tests into shared storetest package.
internal/storetest/v2contracts_test.go Moves v2 contract tests into shared storetest package.
internal/storetest/v2transactions_test.go Moves v2 transaction tests into shared storetest package.
persist/sqlite/consensus_test.go Removes SQLite-local consensus tests after moving them to storetest.
persist/sqlite/testing.go Adds SQLite host seeding helper for shared tests.
persist/postgres/addresses.go Adds PostgreSQL address/event/balance queries.
persist/postgres/blocks.go Adds PostgreSQL block and tip queries.
persist/postgres/consensus.go Adds PostgreSQL chain-state update and host scan logic.
persist/postgres/contracts.go Adds PostgreSQL v1 contract queries.
persist/postgres/encoding.go Adds PostgreSQL value encoding/decoding helpers.
persist/postgres/events.go Adds PostgreSQL event queries and unconfirmed event annotation.
persist/postgres/hosts.go Adds PostgreSQL host scan and host query support.
persist/postgres/init.go Adds PostgreSQL schema initialization and migration handling.
persist/postgres/init.sql Adds initial PostgreSQL schema.
persist/postgres/merkle.go Adds PostgreSQL Merkle proof lookup.
persist/postgres/metrics.go Adds PostgreSQL network/host/difficulty metrics.
persist/postgres/migrations.go Adds PostgreSQL migration list scaffold.
persist/postgres/revert.go Adds PostgreSQL chain revert deletion logic.
persist/postgres/search.go Adds PostgreSQL search implementation.
persist/postgres/sql.go Adds pgx transaction/statement wrappers.
persist/postgres/store.go Adds PostgreSQL store constructor, connection handling, and transactions.
persist/postgres/store_test.go Adds PostgreSQL database creation test.
persist/postgres/testing.go Adds PostgreSQL test helpers.
persist/postgres/transactions.go Adds PostgreSQL v1 transaction queries.
persist/postgres/v2consensus.go Adds PostgreSQL v2 chain-state persistence.
persist/postgres/v2contracts.go Adds PostgreSQL v2 contract queries.
persist/postgres/v2transactions.go Adds PostgreSQL v2 transaction queries.
Comments suppressed due to low confidence (1)

persist/postgres/v2transactions.go:285

  • These errors are emitted while querying/scanning siafund inputs, but they say “siacoin inputs”. That will make debugging PostgreSQL failures harder because the reported component is wrong.

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

Comment thread go.mod Outdated
Comment thread persist/postgres/contracts.go
Comment thread persist/postgres/store.go
Comment thread persist/postgres/testing.go Outdated
Comment thread persist/postgres/store.go
Comment thread persist/postgres/testing.go Outdated
Comment thread persist/postgres/store.go Outdated
Comment thread persist/postgres/store.go
Comment thread persist/postgres/sql.go Outdated
Comment thread persist/postgres/store.go
@chris124567

Copy link
Copy Markdown
Member Author

That Claude review was hardly worth $15!

@socket-security

socket-security Bot commented May 14, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​jackc/​pgx/​v5@​v5.9.273100100100100
Addedgo.uber.org/​goleak@​v1.3.0100100100100100

View full report

@chris124567 chris124567 force-pushed the christopher/add-postgres branch from b523462 to 0a5aaba Compare May 14, 2026 23:08
@chris124567 chris124567 force-pushed the christopher/add-postgres branch from 0a5aaba to 13c5498 Compare May 14, 2026 23:13

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has reached its monthly code review spending cap.

An organization admin can view or raise the cap at claude.ai/admin-settings/claude-code. The cap resets at the start of the next billing period.

Once the cap resets or is raised, reopen this pull request to trigger a review.

@chris124567 chris124567 force-pushed the christopher/add-postgres branch from e703d4e to a8357c0 Compare May 15, 2026 00:55
Comment thread persist/postgres/init.sql Outdated
Comment thread persist/postgres/migrations.go
Comment thread persist/sqlite/testing.go
Comment thread persist/postgres/init.sql Outdated
@chris124567 chris124567 force-pushed the christopher/add-postgres branch 2 times, most recently from 39bb556 to 913753b Compare May 15, 2026 16:22
@chris124567 chris124567 force-pushed the christopher/add-postgres branch from 913753b to 11cc994 Compare May 15, 2026 16:27
@chris124567 chris124567 force-pushed the christopher/add-postgres branch from c2c0119 to 6bf0bbb Compare May 15, 2026 22:01
@chris124567 chris124567 force-pushed the christopher/add-postgres branch from 9db643d to 72e8370 Compare May 15, 2026 22:09
peterjan

This comment was marked as resolved.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has reached its monthly code review spending cap.

An organization admin can view or raise the cap at claude.ai/admin-settings/claude-code. The cap resets at the start of the next billing period.

Once the cap resets or is raised, reopen this pull request to trigger a review.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has reached its monthly code review spending cap.

An organization admin can view or raise the cap at claude.ai/admin-settings/claude-code. The cap resets at the start of the next billing period.

Once the cap resets or is raised, reopen this pull request to trigger a review.

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

5 participants