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

Fix building a list of upgrade operations for model classes by using case insensitive field type names #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vladbelousoff
Copy link

Before the change, the library generated migration files using field_type from peewee, for example, UUIDField and IntegerField have uppercased field_type values:

class UUIDField(Field):
    field_type = 'UUID'
    ...
class IntegerField(Field):
    field_type = 'INT'
    ...

Using this field will generate the following migration file:

def upgrade(migrator):
    with migrator.create_table('performance_report_stat_unit') as table:
        table.foreign_key('UUID', 'session_uid', on_delete=None, on_update=None, references='performance_report_session.uid')

However, when applying migration, the type is searched using the values from FIELD_TO_PEEWEE that only contains lowercase values:

PEEWEE_TO_FIELD = {
    peewee.BareField: 'bare',
    peewee.BigIntegerField: 'biginteger',
    peewee.BlobField: 'blob',
    peewee.BooleanField: 'bool',
    peewee.CharField: 'char',
    peewee.DateField: 'date',
    peewee.DateTimeField: 'datetime',
    peewee.DecimalField: 'decimal',
    peewee.DoubleField: 'double',
    peewee.FixedCharField: 'fixed',
    peewee.FloatField: 'float',
    peewee.ForeignKeyField: 'foreign_key',
    peewee.IntegerField: 'int',
    peewee.AutoField: 'primary_key',
    peewee.SmallIntegerField: 'smallint',
    peewee.TextField: 'text',
    peewee.TimeField: 'time',
    peewee.TimestampField: 'int',
    peewee.UUIDField: 'uuid',
}

# Only available on peewee >= 3.3.4
if hasattr(peewee, 'BinaryUUIDField'):
    PEEWEE_TO_FIELD[peewee.BinaryUUIDField] = 'bin_uuid'

FIELD_TO_PEEWEE = {value: key for key, value in PEEWEE_TO_FIELD.items()}

Thus, we try to get a value using an incorrect key.
I suggest using casting to lowercase when searching and generating values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant