Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.

Check schema consistency test#92

Merged
johnnyluo merged 4 commits into
mainfrom
90-autogenerate-and-verify-schemasql
Jun 12, 2025
Merged

Check schema consistency test#92
johnnyluo merged 4 commits into
mainfrom
90-autogenerate-and-verify-schemasql

Conversation

@neavra

@neavra neavra commented Jun 12, 2025

Copy link
Copy Markdown
Collaborator

Replicated vultisig/verifier#143 for plugins. Added in a Check schema updates test in migration-test. This generates a schema and checks it against the committed schema to see if there are any inconsistencies

Summary by CodeRabbit

  • New Features

    • Introduced a new PostgreSQL database schema with tables for plugin policies, scheduling triggers, transaction history, and transaction indexing.
    • Added support for custom enum types to track plugin IDs, transaction statuses, trigger statuses, and indexer statuses.
    • Enabled a Makefile command to export the current database schema to a file.
  • Chores

    • Enhanced automated checks to ensure the committed schema file stays consistent with the database schema.

@neavra neavra linked an issue Jun 12, 2025 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Jun 12, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new database schema file was added, defining several tables and enums for plugin policies, triggers, transaction history, and transaction indexing. The Makefile gained a dump-schema target to export the schema, and a GitHub Actions workflow step was introduced to verify that the committed schema matches the live database schema, enforcing consistency between code and database structure.

Changes

File(s) Change Summary
.github/workflows/migration-test.yml Added a step to check that the committed schema file matches the current database schema during CI.
Makefile Added a dump-schema target to export and clean the PostgreSQL schema to a file, requiring a config parameter.
storage/postgres/schema/schema.sql Introduced a new PostgreSQL schema with enums and tables for plugin policies, triggers, transaction history, and indexing.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant CI
    participant PostgreSQL
    participant Repo

    Developer->>Repo: Push code/schema changes
    CI->>PostgreSQL: Dump current schema (pg_dump)
    CI->>Repo: Read committed schema.sql
    CI->>CI: Compare dumped schema with schema.sql
    alt Schemas match
        CI->>Developer: Schema is up to date
    else Schemas differ
        CI->>Developer: Fail with update instructions
    end
Loading

Poem

🐇
The schema’s now written, so neat and precise,
With triggers and policies, enums that entice.
The Makefile can dump it, the workflow will check,
If things go awry, it gives you a peck.
Our database garden is tidy and bright—
The rabbit approves, all seems right!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 651f3e7 and cd78e02.

📒 Files selected for processing (1)
  • .github/workflows/migration-test.yml (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/migration-test.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@neavra neavra changed the title replicate schema consistency test Check schema consistency test Jun 12, 2025
@neavra
neavra marked this pull request as ready for review June 12, 2025 11:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (7)
Makefile (3)

22-28: Mark dump-schema as .PHONY and validate prerequisites
The new dump-schema target writes to a tracked schema file and depends on yq.

  • Add .PHONY: dump-schema to prevent collisions with the output file.
  • Insert a check at the top to ensure yq is installed (e.g., command -v yq >/dev/null || { echo "yq not found"; exit 1; }).

20-21: Remove trailing whitespace
Line 20 contains trailing spaces, triggering lint errors. Please trim the line to pass make lint.


1-40: Document external dependencies
Since dump-schema relies on yq, add a brief note in the Makefile header or project README specifying the required yq version (e.g., yq >= 4.x).

🧰 Tools
🪛 checkmake (0.2.2)

[warning] 1-1: Missing required phony target "all"

(minphony)


[warning] 1-1: Missing required phony target "clean"

(minphony)


[warning] 1-1: Missing required phony target "test"

(minphony)

.github/workflows/migration-test.yml (4)

131-132: Remove trailing whitespace
Lines 131–132 end with spaces, causing YAML lint errors. Please trim them.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 132-132: trailing spaces

(trailing-spaces)


133-155: DRY: centralize schema dump logic
The Check schema updates step reimplements the pg_dump | sed | awk pipeline already in the Makefile. Consider invoking the dump-schema target (possibly extended to accept an output file) to avoid duplication and ensure consistency.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 148-148: trailing spaces

(trailing-spaces)


[error] 155-155: trailing spaces

(trailing-spaces)


148-148: Remove trailing whitespace
Line 148 has trailing spaces. Please trim it to satisfy YAMLlint.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 148-148: trailing spaces

(trailing-spaces)


155-156: Ensure newline at end-of-file and no trailing spaces
YAMLlint reports no newline at EOF and trailing whitespace on line 155. Add a final newline and remove any spaces.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 155-155: trailing spaces

(trailing-spaces)


[error] 156-156: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 675c1c6 and 0d135b6.

📒 Files selected for processing (3)
  • .github/workflows/migration-test.yml (1 hunks)
  • Makefile (1 hunks)
  • internal/storage/postgres/schema/schema.sql (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/migration-test.yml

[error] 132-132: trailing spaces

(trailing-spaces)


[error] 148-148: trailing spaces

(trailing-spaces)


[error] 155-155: trailing spaces

(trailing-spaces)


[error] 156-156: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +82 to +96
CREATE TABLE "tx_indexer" (
"id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
"plugin_id" character varying(255) NOT NULL,
"tx_hash" character varying(255),
"chain_id" integer NOT NULL,
"policy_id" "uuid" NOT NULL,
"from_public_key" character varying(255) NOT NULL,
"proposed_tx_hex" "text" NOT NULL,
"status" "tx_indexer_status" DEFAULT 'PROPOSED'::"public"."tx_indexer_status" NOT NULL,
"status_onchain" "tx_indexer_status_onchain",
"lost" boolean DEFAULT false NOT NULL,
"broadcasted_at" timestamp without time zone,
"created_at" timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
"updated_at" timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Inconsistent plugin_id column type in tx_indexer
The tx_indexer table defines plugin_id as character varying(255), whereas plugin_policies.plugin_id uses the plugin_id enum. To enforce consistency and prevent invalid values, consider changing tx_indexer.plugin_id to use the same plugin_id enum type.

🤖 Prompt for AI Agents
In internal/storage/postgres/schema/schema.sql around lines 82 to 96, the
tx_indexer table defines plugin_id as character varying(255), but
plugin_policies.plugin_id uses the plugin_id enum type. To ensure consistency
and data integrity, change the plugin_id column in tx_indexer to use the same
plugin_id enum type instead of character varying(255).

Comment on lines +133 to +141
ALTER TABLE ONLY "transaction_history"
ADD CONSTRAINT "fk_policy" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id");

ALTER TABLE ONLY "time_triggers"
ADD CONSTRAINT "time_triggers_policy_id_fkey" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id");

ALTER TABLE ONLY "transaction_history"
ADD CONSTRAINT "transaction_history_policy_id_fkey" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Duplicate foreign key constraint on transaction_history.policy_id
There are two FKs referencing transaction_history.policy_id (fk_policy and transaction_history_policy_id_fkey). Remove one to avoid redundancy and naming conflicts.

🤖 Prompt for AI Agents
In internal/storage/postgres/schema/schema.sql around lines 133 to 141, there
are two foreign key constraints on transaction_history.policy_id named fk_policy
and transaction_history_policy_id_fkey. Remove one of these duplicate foreign
key constraints to avoid redundancy and naming conflicts, keeping only a single
foreign key constraint referencing plugin_policies(id).

Comment on lines +2 to +6
CREATE TYPE "plugin_id" AS ENUM (
'vultisig-dca-0000',
'vultisig-payroll-0000',
'vultisig-fees-feee'
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Possible typo in plugin_id enum value
The entry 'vultisig-fees-feee' has three es in feee. Please confirm that this is intentional; otherwise correct it to the intended plugin identifier.

🤖 Prompt for AI Agents
In internal/storage/postgres/schema/schema.sql lines 2 to 6, the enum value
'vultisig-fees-feee' likely contains a typo with an extra 'e' in 'feee'. Verify
the correct plugin identifier and update the enum value to the intended
spelling, such as 'vultisig-fees-fee', if the triple 'e' is unintentional.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
.github/workflows/migration-test.yml (2)

132-132: Fix trailing spaces and add newline at EOF.
YAMLlint reports trailing whitespace on lines 132, 148, and 155, and the file is missing a final newline. Please remove the extra spaces and ensure a newline at the end of the file.

Also applies to: 148-148, 155-156

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 132-132: trailing spaces

(trailing-spaces)


133-147: DRY: Leverage the existing dump-schema Makefile target.
This inline pg_dump | sed | awk pipeline duplicates logic captured in make dump-schema. Consider replacing it with:

run: |
  make dump-schema CONFIG=config-plugin.yaml
  if ! diff -u storage/postgres/schema/schema.sql current_schema.sql; then
    echo "Schema has changed but schema.sql was not updated!"
    exit 1
  fi

This reduces duplication and centralizes schema dumping.

storage/postgres/schema/schema.sql (1)

43-45: Inconsistent NOT NULL on timestamp columns.
Some tables enforce NOT NULL on created_at/updated_at while others allow NULLs. For consistency and data integrity, consider marking all timestamp fields as NOT NULL.

Also applies to: 76-78, 94-96

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d135b6 and 651f3e7.

📒 Files selected for processing (3)
  • .github/workflows/migration-test.yml (1 hunks)
  • Makefile (1 hunks)
  • storage/postgres/schema/schema.sql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Makefile
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/migration-test.yml

[error] 132-132: trailing spaces

(trailing-spaces)


[error] 148-148: trailing spaces

(trailing-spaces)


[error] 155-155: trailing spaces

(trailing-spaces)


[error] 156-156: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
.github/workflows/migration-test.yml (1)

149-154: Schema comparison logic looks solid.
The diff -u check will fail the job when discrepancies exist and provides clear instructions for updating the file.

Comment on lines +133 to +137
ALTER TABLE ONLY "transaction_history"
ADD CONSTRAINT "fk_policy" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id");

ALTER TABLE ONLY "time_triggers"
ADD CONSTRAINT "time_triggers_policy_id_fkey" FOREIGN KEY ("policy_id") REFERENCES "plugin_policies"("id");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Duplicate foreign key for transaction_history.policy_id.
The policy_id FK on transaction_history is applied twice (fk_policy and transaction_history_policy_id_fkey). Remove one to avoid conflicts during schema application.

🤖 Prompt for AI Agents
In storage/postgres/schema/schema.sql around lines 133 to 137, there are
duplicate foreign key constraints on transaction_history.policy_id named
fk_policy and transaction_history_policy_id_fkey. Remove one of these foreign
key constraints to avoid conflicts during schema application, ensuring only a
single foreign key constraint exists for transaction_history.policy_id
referencing plugin_policies(id).

Comment on lines +112 to +114
ALTER TABLE ONLY "transaction_history"
ADD CONSTRAINT "unique_tx_hash" UNIQUE ("tx_hash");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Redundant index on transaction_history.tx_hash.
You already add a unique constraint (unique_tx_hash) which creates an index. The separate idx_transaction_history_tx_hash is unnecessary and should be removed.

Also applies to: 129-129

🤖 Prompt for AI Agents
In storage/postgres/schema/schema.sql around lines 112 to 114 and line 129,
there is a redundant index on transaction_history.tx_hash because the unique
constraint unique_tx_hash already creates an index. Remove the separate index
named idx_transaction_history_tx_hash to avoid duplication and unnecessary
overhead.

Comment on lines +2 to +6
CREATE TYPE "plugin_id" AS ENUM (
'vultisig-dca-0000',
'vultisig-payroll-0000',
'vultisig-fees-feee'
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Typo in enum value ‘vultisig-fees-feee’.
The third entry in the plugin_id enum has an extra ‘e’. Please confirm the intended plugin identifier and correct this value.

🤖 Prompt for AI Agents
In storage/postgres/schema/schema.sql around lines 2 to 6, there is a typo in
the third enum value of the "plugin_id" type: 'vultisig-fees-feee' has an extra
'e'. Confirm the correct plugin identifier and update this enum value to the
intended spelling, removing the extra 'e' if it is a mistake.

@RaghavSood RaghavSood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@johnnyluo johnnyluo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@johnnyluo
johnnyluo merged commit ad8b277 into main Jun 12, 2025
3 checks passed
@johnnyluo
johnnyluo deleted the 90-autogenerate-and-verify-schemasql branch June 12, 2025 12:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autogenerate and verify schema.sql

3 participants