-
Notifications
You must be signed in to change notification settings - Fork 45
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
rename participant field (fixes #136) #142
rename participant field (fixes #136) #142
Conversation
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.
Few minor issues spotted, but deal-breaker here is how migration was created.
backend/tests/test_db.py
Outdated
@@ -29,18 +29,18 @@ def test_add_new_participant_to_db(_db, new_participant): | |||
assert len(db.session.query(Participant).all()) == 0 | |||
|
|||
new_participant = Participant( | |||
name=new_participant['name'], | |||
lastname=new_participant['lastname'], | |||
first_name=new_participant['first_name'], |
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.
We could do that as new_participant = Participant(**new_participant)
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.
changed :)
backend/tests/test_models.py
Outdated
@@ -19,14 +19,14 @@ def test_create_new_user(new_user): | |||
def test_create_new_participant(new_participant): | |||
"""Test participant model.""" | |||
new_participant = Participant( | |||
name=new_participant['name'], | |||
lastname=new_participant['lastname'], | |||
first_name=new_participant['first_name'], |
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.
Ditto: new_participant = Participant(**new_participant)
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.
changed :)
@@ -26,7 +26,7 @@ def upgrade(): | |||
op.create_table('participant', | |||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | |||
sa.Column('name', sa.String(length=20), nullable=True), | |||
sa.Column('lastname', sa.String(length=20), nullable=True), | |||
sa.Column('last_name', sa.String(length=20), nullable=True), |
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.
Historical cannot be changed.
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.
changed to lastname
backend/factories.py
Outdated
email = factory.LazyAttribute( | ||
lambda obj: "{}@cfp.com".format(obj.lastname) | ||
lambda obj: "{}@cfp.com".format(obj.last_name) |
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.
We don't own cfp.com
domain, it's not connected with us anyhow. We should change domain here to codeforpoznan.pl
od stick to reserved, testing domains (like example.com
, or codeforpoznan.test
).
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.
.test is the best option
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.
changed to "codeforpoznan.test"
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('participant', sa.Column('first_name', sa.String(length=50), nullable=True)) |
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.
We should use alter_column
here, not drop_column
and add_column
as altering will preserve data.
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.
It has been done automatically by alembic
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.
Not sure about this one with alembic. 😕
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.
@magul, we are waiting for your re-review
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.
I understand, that Alembic could create such migration, but that's just a tool and in that case, it does it wrong. We're not on production right now, but as a learning exercise, we should prepare that migration in such manner, that it could be safely run on a production environment.
Right now that migration will drop existing columns an create new ones. Data previously stored in removed columns are permanently lost. I belive we should use here https://alembic.sqlalchemy.org/en/latest/ops.html?highlight=unique#alembic.operations.Operations.alter_column
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.
@magul
I made all the requested changes in migration files. I checked the command flask db upgrade and flask db migrate - everything worked. When I opened the database in dbeaver it had column names: first_name and last_name. I hope that now everything works ok, but it would be nice if you could check :)
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('participant', sa.Column('first_name', sa.String(length=50), nullable=True)) |
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.
I understand, that Alembic could create such migration, but that's just a tool and in that case, it does it wrong. We're not on production right now, but as a learning exercise, we should prepare that migration in such manner, that it could be safely run on a production environment.
Right now that migration will drop existing columns an create new ones. Data previously stored in removed columns are permanently lost. I belive we should use here https://alembic.sqlalchemy.org/en/latest/ops.html?highlight=unique#alembic.operations.Operations.alter_column
existing_type=sa.VARCHAR(length=20), | ||
type_=sa.Date(), | ||
existing_nullable=True) | ||
op.execute("""ALTER TABLE hacknight ALTER COLUMN date TYPE DATE USING date::date""") |
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.
And what happened here?
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.
@magul there was some problem with the upgrade of database with date type. It required: "USING date::date" and in SQLAlchemy it was impossible to add this "USING" part. With @stanislawK we were looking for different solutions and we found that we should use pure SQL to solve this problem.
I hope that it is correct. I don't know how to test it.