-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
360 sim fix validators create and update methods (#361)
* chore: migrated the database validators stake field * docs: improved migrations documentation * refactor: improved the frontend validators form * force digits input keys on number fields * fix forceInteger prop * switch back to true * docs: updated steps for running db migrations Co-authored-by: Agustín Díaz <[email protected]> * docs: fixed items list number --------- Co-authored-by: Den <[email protected]> Co-authored-by: Agustín Díaz <[email protected]>
- Loading branch information
1 parent
b354fe3
commit a8795af
Showing
6 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
## Pre-requisites | ||
|
||
1. set your virtual environment | ||
1. `pip install -r requirements.txt` | ||
### Window One | ||
1. Launch the simulator | ||
|
||
## User guide | ||
|
||
1. Change the `model` | ||
1. Set your current working directory to `backend/database_handler` | ||
1. Run `alembic revision --autogenerate -m "migration name here"` to generate the migration file | ||
1. Modify the migration file if needed | ||
1. Apply the migration: we have different options here | ||
- [preferred] If using `docker-compose`, run `docker-compose up database-migration --build` | ||
### Window Two | ||
1. Set your virtual environment | ||
2. Pip install `pip install -r backend/database_handler/requirements.txt` | ||
3. Update the "models" at `models.py` with your preferences | ||
4. Set your current working directory to `backend/database_handler` | ||
5. Run `alembic revision --autogenerate -m "migration name here"` to generate the migration file | ||
6. Modify the migration file if needed | ||
7. Apply the migration: we have different options here | ||
- [preferred] If using `docker-compose`, run `docker compose up database-migration --build` | ||
- Run `alembic upgrade head` to "manually" apply the migration | ||
|
||
## Revert migrations | ||
To revert the latest migration, run `alembic downgrade -1` | ||
|
||
## Docs | ||
|
||
- [Alembic](https://alembic.sqlalchemy.org/en/latest/) |
65 changes: 65 additions & 0 deletions
65
...abase_handler/migration/versions/d9ddc7436122_changed_validators_stage_property_to_int.py
This file contains 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,65 @@ | ||
"""changed validators stage property to int | ||
Revision ID: d9ddc7436122 | ||
Revises: 02aa0c34a463 | ||
Create Date: 2024-08-06 14:26:15.737405 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "d9ddc7436122" | ||
down_revision: Union[str, None] = "02aa0c34a463" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
connection = op.get_bind() | ||
|
||
column_name = "stake" | ||
id_column = "id" | ||
table_name = "validators" | ||
|
||
result = connection.execute( | ||
sa.text(f"SELECT {id_column}, {column_name} FROM {table_name}") | ||
) | ||
|
||
for [id, value] in result: | ||
int_value = int(value) | ||
new_value = int_value if int_value > 0 else 1 | ||
print(f"Updating {table_name} {id} with `{new_value}`") | ||
# Update the row | ||
connection.execute( | ||
sa.text( | ||
f"UPDATE {table_name} SET {column_name} = :value WHERE {id_column} = :id" | ||
), | ||
{"value": new_value, id_column: id}, | ||
) | ||
|
||
op.alter_column( | ||
"validators", | ||
"stake", | ||
existing_type=sa.NUMERIC(), | ||
type_=sa.Integer(), | ||
existing_nullable=False, | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column( | ||
"validators", | ||
"stake", | ||
existing_type=sa.Integer(), | ||
type_=sa.NUMERIC(), | ||
existing_nullable=False, | ||
) | ||
# ### end Alembic commands ### |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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