Skip to content

Conversation

@manuelwedler
Copy link
Member

@manuelwedler manuelwedler commented Jul 17, 2025

Closes #31
Closes argotorg/sourcify#2199

This sets up the structure for schema migrations, which we need for managing changes to the schema. I introduced a tool called (dbmate)[https://github.com/amacneil/dbmate] for this purpose. The reasons for dbmate are mainly that it uses raw SQL files, it is language and framework agnostic and writes a full schema file automatically.

The changes include:

  • Adds the current state of the VerA schema as the first migration file
  • Changes database.sql to be an automatically generated file by dbmate
  • Adds a CI test for verifying that migrations in new PRs lead to the same database.sql as the one comitted (via git diff)
  • Adds documentation on how to add a new migration file
  • Adds a migration for adding an index on address of contract_deployments (Add "address" column as single index in contract_deployments table argotorg/sourcify#2199)

@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

@manuelwedler manuelwedler force-pushed the add-migrations branch 3 times, most recently from 2d131e8 to 896390c Compare July 17, 2025 14:59
@samczsun
Copy link
Contributor

The handwritten database.sql has some potentially useful comments which would get lost with this mechanism. Maybe it's unavoidable

@manuelwedler
Copy link
Member Author

@samczsun I agree that we should keep the comments. They are still inside migrations/20250717103432_database.sql which is basically the original database.sql. I will add a comment about this in the README.

@manuelwedler manuelwedler marked this pull request as ready for review July 21, 2025 15:43
@manuelwedler manuelwedler moved this to Sprint - Needs Review in Sourcify Public [Archived] Jul 21, 2025
Copy link
Contributor

@marcocastignoli marcocastignoli left a comment

Choose a reason for hiding this comment

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

Just a couple questions regarding the schema name. Good job! I like the approach

Copy link
Contributor

Choose a reason for hiding this comment

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

I see in the new version we are forcing as schema public, would it be possible to keep it without the schema?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, this is not possible with pg_dump which is used by dbmate for creating the file (or at least there is no clean solution, see https://stackoverflow.com/questions/49108981/postgresql-pg-dump-without-schema-name).

Would you be fine with dumping to v1? I think if you load the db from the dump you can also rename the schema afterwards.

Copy link
Contributor

Choose a reason for hiding this comment

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

By "no clean solution", do you mean for example running a replaceAll("public.", "")? Maybe that's enough and it works, idk.

I honestly don't know if it's better to use v1 vs public

Copy link
Member Author

Choose a reason for hiding this comment

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

By "no clean solution", do you mean for example running a replaceAll("public.", "")? Maybe that's enough and it works, idk.

changing the file only via string matching seems error-prone to me. I think we should not change the dump like this. Besides, we would have to remove the SELECT pg_catalog.set_config('search_path', '', false); from the top of the dump. It's a security feature which is added so the dump is only loaded on the predefined schema.

Copy link
Contributor

Choose a reason for hiding this comment

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

okok, let's try to keep it like this for now and deal with it in the future only if we encounter the problem

Copy link
Member Author

Choose a reason for hiding this comment

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

I still do agree that dumping to public does not feel ideal. We can easily dump to another schema name by specifying the search path on dbmate, but I ran into the problem that no extensions are dumped when doing so (which might be fixable if I dig deeper). However, I agree that we can leave it like it is now, since you would probably load the dump into a fresh db anyway if you use it.

Copy link
Contributor

@marcocastignoli marcocastignoli left a comment

Choose a reason for hiding this comment

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

lgtm!

@manuelwedler manuelwedler merged commit 8aafd98 into master Jul 24, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from Sprint - Needs Review to Sprint - Done in Sourcify Public [Archived] Jul 24, 2025
@manuelwedler manuelwedler deleted the add-migrations branch July 24, 2025 13:57
@marcocastignoli marcocastignoli moved this from Sprint - Done to COMPLETED in Sourcify Public [Archived] Jul 31, 2025
@stackenbotten3000 stackenbotten3000 moved this to COMPLETED in Sourcify Public Aug 27, 2025
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.

Add schema migrations Add "address" column as single index in contract_deployments table

4 participants