-
Notifications
You must be signed in to change notification settings - Fork 14
refactor: rename cardano_address to cardano_stake_key for clarity #628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| -------------------------------------------------------------------------------- | ||
| -- Migration: Rename cardano_address to cardano_stake_key for clarity | ||
| -- Issue: #440 - The column name was confusing as it actually stores a Cardano | ||
| -- stake key (reward address), not a regular Cardano address. | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| -- Rename the column in cnight_registrations table | ||
| ALTER TABLE cnight_registrations | ||
| 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; | ||
| CREATE INDEX ON cnight_registrations (cardano_stake_key); | ||
|
|
||
| -- Update the unique constraint | ||
| -- Note: PostgreSQL automatically updates the constraint when the column is renamed, | ||
| -- but we recreate it for clarity and to ensure the constraint name reflects the change. | ||
| ALTER TABLE cnight_registrations | ||
| DROP CONSTRAINT IF EXISTS cnight_registrations_cardano_address_dust_address_key; | ||
| ALTER TABLE cnight_registrations | ||
| ADD CONSTRAINT cnight_registrations_cardano_stake_key_dust_address_key | ||
| UNIQUE (cardano_stake_key, dust_address); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| -------------------------------------------------------------------------------- | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). Please remove:
Keep: Your changes to 001_initial.sql files are correct. |
||
| -- Migration: Rename cardano_address to cardano_stake_key for clarity | ||
| -- Issue: #440 - The column name was confusing as it actually stores a Cardano | ||
| -- stake key (reward address), not a regular Cardano address. | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| -- SQLite does not support RENAME COLUMN directly in older versions, | ||
| -- 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 ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. every code in this file is not needed. they are redundant. |
||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| cardano_stake_key BLOB NOT NULL, | ||
| dust_address BLOB NOT NULL, | ||
| valid INTEGER NOT NULL, | ||
| registered_at INTEGER NOT NULL, | ||
| removed_at INTEGER, | ||
| block_id INTEGER REFERENCES blocks (id), | ||
| utxo_tx_hash BLOB, | ||
| utxo_output_index INTEGER, | ||
| UNIQUE (cardano_stake_key, dust_address) | ||
| ); | ||
|
|
||
| -- Step 2: Copy data from the old table to the new table | ||
| INSERT INTO cnight_registrations_new ( | ||
| id, cardano_stake_key, dust_address, valid, registered_at, removed_at, | ||
| block_id, utxo_tx_hash, utxo_output_index | ||
| ) | ||
| SELECT | ||
| id, cardano_address, dust_address, valid, registered_at, removed_at, | ||
| block_id, utxo_tx_hash, utxo_output_index | ||
| FROM cnight_registrations; | ||
|
|
||
| -- Step 3: Drop the old table | ||
| DROP TABLE cnight_registrations; | ||
|
|
||
| -- Step 4: Rename the new table to the original name | ||
| ALTER TABLE cnight_registrations_new RENAME TO cnight_registrations; | ||
|
|
||
| -- Step 5: Recreate indexes with the new column name | ||
| CREATE INDEX cnight_registrations_cardano_stake_key_idx ON cnight_registrations (cardano_stake_key); | ||
| CREATE INDEX cnight_registrations_dust_address_idx ON cnight_registrations (dust_address); | ||
| CREATE INDEX cnight_registrations_block_id_idx ON cnight_registrations (block_id); | ||
There was a problem hiding this comment.
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.