Skip to content

Commit

Permalink
fix: migrations default values
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Aug 5, 2021
1 parent 60008c3 commit 40651b8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,17 @@ jobs:
with:
user: __token__
password: ${{ secrets.pypi }}

notify:
runs-on: ubuntu-latest
needs: release
steps:

- name: Notify Success
uses: archive/github-actions-slack@master
with:
slack-channel: C2CRL4C4V
slack-text: "*[${{ github.repository }}]* package is published *(${{ github.ref }})* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-optional-as_user: false
slack-optional-icon_emoji: ":white_check_mark:"
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ jobs:
run: |
pytest tests
notify:
runs-on: ubuntu-latest
needs: tests
steps:

- name: Notify Success
uses: archive/github-actions-slack@master
with:
slack-channel: C2CRL4C4V
slack-text: "*[${{ github.repository }}]* tests are passed *(${{ github.ref }})* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-optional-as_user: false
slack-optional-icon_emoji: ":white_check_mark:"
6 changes: 6 additions & 0 deletions peewee_migrate/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def get_field(self, space=' '):
return '{name}{space}={space}{module}.{field}'.format(
name=name, field=field, space=space, module=module)

def get_field_parameters(self):
params = super(Column, self).get_field_parameters()
if self.default is not None:
params['default'] = self.default
return params


def diff_one(model1, model2, **kwargs):
"""Find difference between given peewee models."""
Expand Down
2 changes: 2 additions & 0 deletions tests/migrations/003_tespy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def migrate(migrator, database, **kwargs):
"""
migrator.rename_field('tag', 'created_at', 'updated_at')
migrator.add_fields('person', is_deleted=pw.BooleanField(default=False))


def rollback(migrator, database, **kwargs):
migrator.rename_field('tag', 'updated_at', 'created_at')
migrator.remove_fields('person', 'is_deleted')
1 change: 1 addition & 0 deletions tests/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Person(pw.Model):
first_name = pw.IntegerField()
last_name = pw.CharField(max_length=1024, null=True, unique=True)
email = pw.CharField(index=True, unique=True)
is_deleted = pw.BooleanField(default=False)


class Color(pw.Model):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Person(pw.Model):
dob = pw.DateField(null=True)
birthday = pw.DateField(default=dt.datetime.now)
email = pw.CharField(index=True, unique=True)
is_deleted = pw.BooleanField(default=False)

changes = diff_one(Person_, Person, migrator=migrator)
assert not changes
Expand Down Expand Up @@ -120,3 +121,11 @@ class EmployeeNew(pw.Model):
changes = diff_one(EmployeeNew, Employee)
assert "migrator.add_fields" in changes[0]
assert "model='self'" in changes[0]


def test_column_default():
from peewee_migrate.auto import field_to_code
from .models import Person

code = field_to_code(Person.is_deleted)
assert code == 'is_deleted = pw.BooleanField(constraints=[SQL("DEFAULT False")], default=False)' # noqa

0 comments on commit 40651b8

Please sign in to comment.