-
Notifications
You must be signed in to change notification settings - Fork 22
Add Aleph Credits system with balance tracking and API endpoints #827
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
Open
amalcaraz
wants to merge
4
commits into
main
Choose a base branch
from
angel-credit_balances
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
deployment/migrations/versions/0035_a1b2c3d4e5f6_add_credit_balances_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""add credit_balances table | ||
|
||
Revision ID: a1b2c3d4e5f6 | ||
Revises: 8ece21fbeb47 | ||
Create Date: 2025-07-14 00:00:00.000000 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.sql import func | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'a1b2c3d4e5f6' | ||
down_revision = '8ece21fbeb47' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Create credit_balances table | ||
op.create_table( | ||
'credit_balances', | ||
sa.Column('id', sa.BigInteger(), autoincrement=True), | ||
sa.Column('address', sa.String(), nullable=False), | ||
sa.Column('amount', sa.BigInteger(), nullable=False), | ||
sa.Column('ratio', sa.DECIMAL(), nullable=True), | ||
sa.Column('tx_hash', sa.String(), nullable=True), | ||
sa.Column('token', sa.String(), nullable=True), | ||
sa.Column('chain', sa.String(), nullable=True), | ||
sa.Column('provider', sa.String(), nullable=True), | ||
sa.Column('origin', sa.String(), nullable=True), | ||
sa.Column('payment_ref', sa.String(), nullable=True), | ||
sa.Column('payment_method', sa.String(), nullable=True), | ||
sa.Column('distribution_ref', sa.String(), nullable=False), | ||
sa.Column('distribution_index', sa.Integer(), nullable=False), | ||
sa.Column('expiration_date', sa.TIMESTAMP(timezone=True), nullable=True), | ||
sa.Column('last_update', sa.TIMESTAMP(timezone=True), nullable=False, | ||
server_default=func.now(), onupdate=func.now()), | ||
sa.PrimaryKeyConstraint('distribution_ref', 'distribution_index'), | ||
) | ||
|
||
# Create index on address for efficient lookups | ||
op.create_index(op.f('ix_credit_balances_address'), 'credit_balances', ['address'], unique=False) | ||
|
||
# Add unique constraint on tx_hash to prevent duplicate credit lines (when tx_hash is not null) | ||
op.execute( | ||
""" | ||
ALTER TABLE credit_balances ADD CONSTRAINT credit_balances_tx_hash_uindex | ||
UNIQUE (tx_hash) | ||
""" | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
# Drop the credit_balances table and its constraints | ||
op.drop_index('ix_credit_balances_address', 'credit_balances') | ||
op.drop_constraint('credit_balances_tx_hash_uindex', 'credit_balances') | ||
op.drop_table('credit_balances') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.