Skip to content
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

Set type and name not null #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pint_server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class ProviderImageBase(PintBase):


class ProviderServerBase(PintBase):
type = Column(Enum(ServerType, name=ServerType.__enum_name__))
type = Column(Enum(ServerType, name=ServerType.__enum_name__), nullable=False)
shape = Column(String(10))
name = Column(String(100))
name = Column(String(100), nullable=False)
# NOTE(gyee): the INET type is specific to PostgreSQL. If in the future
# we decided to support other vendors, we'll need to update this
# column type accordingly.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Set server type, name NOT NULL

Revision ID: b720d8b8b775
Revises: b381843009e0
Create Date: 2021-09-06 17:31:28.809521

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'b720d8b8b775'
down_revision = 'b381843009e0'
branch_labels = None
depends_on = None


def upgrade():
Copy link
Contributor

Choose a reason for hiding this comment

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

We could potentially clean this up a bit by defining the ENUM once instead of using duplicate definitions here in the op.alter_column() statements.

The auto-generated code is a little dumb in this regard. ;-)

I'm sure that under the hood SQLAlchemy/PostgreSQL are detecting equivalency but it would probably make the code look cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I know what you mean, and I have done some refactoring in other PRs but, as a rule thumb, if the auto-generated code by alembic does not need any change, leave like that (i.e. IPv6 PR)

# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('amazonservers', 'type',
existing_type=postgresql.ENUM('region', 'update', name='server_type'),
nullable=False)
op.alter_column('amazonservers', 'name',
existing_type=sa.VARCHAR(length=100),
nullable=False)
op.alter_column('googleservers', 'type',
existing_type=postgresql.ENUM('region', 'update', name='server_type'),
nullable=False)
op.alter_column('googleservers', 'name',
existing_type=sa.VARCHAR(length=100),
nullable=False)
op.alter_column('microsoftservers', 'type',
existing_type=postgresql.ENUM('region', 'update', name='server_type'),
nullable=False)
op.alter_column('microsoftservers', 'name',
existing_type=sa.VARCHAR(length=100),
nullable=False)
# ### end Alembic commands ###


def downgrade():
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above; we can define the ENUM once, and reference it in all the statements.

# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('microsoftservers', 'name',
existing_type=sa.VARCHAR(length=100),
nullable=True)
op.alter_column('microsoftservers', 'type',
existing_type=postgresql.ENUM('region', 'update', name='server_type'),
nullable=True)
op.alter_column('googleservers', 'name',
existing_type=sa.VARCHAR(length=100),
nullable=True)
op.alter_column('googleservers', 'type',
existing_type=postgresql.ENUM('region', 'update', name='server_type'),
nullable=True)
op.alter_column('amazonservers', 'name',
existing_type=sa.VARCHAR(length=100),
nullable=True)
op.alter_column('amazonservers', 'type',
existing_type=postgresql.ENUM('region', 'update', name='server_type'),
nullable=True)
# ### end Alembic commands ###