Skip to content

Conversation

@roman98Z
Copy link

Refactor: Rename cardano_address to cardano_stake_key for Clarity

Overview

This Pull Request addresses issue #440 by renaming the cardano_address column and field to cardano_stake_key throughout the codebase. The previous naming was confusing because the field actually stores a Cardano stake key (reward address), not a regular Cardano address.

As noted in the issue: "the column name was what drove me off the road" - Giuseppe

Problem Statement

The cardano_address naming was misleading because:

  1. Semantic confusion: A "Cardano address" typically refers to a payment address, while this field stores a stake key (reward address)
  2. Developer confusion: QA feedback revealed that the naming caused confusion during development and debugging
  3. Documentation mismatch: The actual data type is CardanoRewardAddress, making the column name inconsistent with the domain model

Solution

Renamed all occurrences of cardano_address to cardano_stake_key to accurately reflect the data being stored.

Changes Summary

Rust Code Changes

File Changes
chain-indexer/src/domain/dust.rs Renamed field in DustRegistrationEvent enum variants
chain-indexer/src/infra/storage.rs Updated SQL queries and pattern matching
chain-indexer/src/infra/subxt_node/runtimes.rs Updated event construction
indexer-api/src/infra/storage/dust.rs Updated registration lookup query

Database Migration Changes

File Purpose
indexer-common/migrations/postgres/001_initial.sql Updated for new installations
indexer-common/migrations/sqlite/001_initial.sql Updated for new installations
indexer-common/migrations/postgres/003_rename_cardano_address.sql NEW - Migration for existing databases
indexer-common/migrations/sqlite/003_rename_cardano_address.sql NEW - Migration for existing databases

Migration Details

For New Installations

The initial migration (001_initial.sql) has been updated to use cardano_stake_key directly, so new installations will have the correct schema from the start.

For Existing Databases

A new migration (003_rename_cardano_address.sql) handles the transition:

PostgreSQL:

  • Renames the column using ALTER TABLE ... RENAME COLUMN
  • Drops and recreates the index with the new name
  • Updates the unique constraint

SQLite:

  • Creates a new table with the correct column name
  • Copies data from the old table
  • Drops the old table and renames the new one
  • Recreates all indexes

Breaking Changes

This is a breaking change for existing databases. Users must run the new migration before deploying this version.

Testing

The code has been validated with:

cargo check

Result: ✅ Compiles successfully with no warnings or errors

Related Issues

Checklist

  • Code compiles without errors
  • All SQL queries updated
  • Migration scripts for existing databases
  • Initial migrations updated for new installations
  • Documentation comments updated
  • Breaking change documented

This commit addresses issue midnightntwrk#440 by renaming the `cardano_address` column
and field to `cardano_stake_key` throughout the codebase. The previous name
was confusing because the field actually stores a Cardano stake key (reward
address), not a regular Cardano address.

Changes made:

1. Domain layer (chain-indexer/src/domain/dust.rs):
   - Renamed field in DustRegistrationEvent enum variants
   - Updated documentation comments

2. Infrastructure layer (chain-indexer/src/infra/storage.rs):
   - Updated SQL queries to use cardano_stake_key
   - Updated pattern matching for DustRegistrationEvent

3. Runtime layer (chain-indexer/src/infra/subxt_node/runtimes.rs):
   - Updated event construction to use cardano_stake_key field name

4. API storage layer (indexer-api/src/infra/storage/dust.rs):
   - Updated SQL query for registration lookup

5. Database migrations:
   - Updated initial migrations (001_initial.sql) for new installations
   - Added migration 003_rename_cardano_address.sql for existing databases
   - Both PostgreSQL and SQLite migrations included

This is a breaking change for existing databases that requires running the
new migration. The migration handles:
- Column rename
- Index recreation with new name
- Unique constraint update

Closes midnightntwrk#440
@roman98Z roman98Z requested a review from a team as a code owner December 22, 2025 23:41
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Manus AI seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hseeberger
Copy link
Collaborator

Thanks again, @roman98Z. Please notice that commits must have verified signatures. Also please sign the CLA.
I know that the issue mentions "migration", but we will soon start fresh and I want to start with a single migration file. What do you think @cosmir17?

@cosmir17
Copy link
Contributor

Hi @hseeberger, thanks for the heads up. I agree with your point about the migration files - we only use the single 001_initial.sql approach for cloud and standalone modes.

I'll also leave some review comments for @roman98Z.

Copy link
Contributor

@cosmir17 cosmir17 left a comment

Choose a reason for hiding this comment

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

Hi @roman98Z, thanks for the PR.
I have left review comments.
Hope you find them useful 🙏

btw, regarding your note in the PR description:

The code has been validated with:
cargo check

I don't think that's good enough.
just all is the command that we use.
it does linting check, fmt, running unit and integration tests etc.

@@ -0,0 +1,43 @@
--------------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not create new migration files before mainnet launch (that's my understanding).
Instead, update the existing 001_initial.sql files only.

Please remove:

  • indexer-common/migrations/postgres/003_rename_cardano_address.sql
  • indexer-common/migrations/sqlite/003_rename_cardano_address.sql

Keep: Your changes to 001_initial.sql files are correct.

-- so we need to recreate the table with the new column name.

-- Step 1: Create a new table with the correct column name
CREATE TABLE cnight_registrations_new (
Copy link
Contributor

Choose a reason for hiding this comment

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

every code in this file is not needed. they are redundant.

RENAME COLUMN cardano_address TO cardano_stake_key;

-- Drop and recreate the index with the new column name
DROP INDEX IF EXISTS cnight_registrations_cardano_address_idx;
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for migration, hence, we don't need operations and codes in this file.

@cosmir17
Copy link
Contributor

After making the code changes, could you also update the PR description to remove references to the 003 migration files?

  • Remove 003 entries from the "Database Migration Changes" table
  • Remove the "Migration Details" section
  • Update "Breaking Changes" to note we use chain reset (no incremental migrations)
  • Remove "Migration scripts for existing databases" from the checklist

This keeps the description accurate, easy to read and aligned with our migration approach.

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.

refactor: rename cardano_address DB column to cardano_stake_key for clarity

4 participants