Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
feat: add data migration to make voucher names unique
Browse files Browse the repository at this point in the history
  • Loading branch information
mumarkhan999 committed Nov 14, 2023
1 parent 6f0b745 commit ddbfe3e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 3.2.20 on 2023-11-14 11:20

from django.core.paginator import Paginator
from django.db import migrations

Check warning on line 4 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L3-L4

Added lines #L3 - L4 were not covered by tests


def make_voucher_names_unique(apps, schema_editor):

Check warning on line 7 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L7

Added line #L7 was not covered by tests
"""
Appends a number to voucher names.
"""
Voucher = apps.get_model('voucher', 'Voucher')
vouchers = Voucher.objects.all()
paginator = Paginator(vouchers, 1000)

Check warning on line 13 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L11-L13

Added lines #L11 - L13 were not covered by tests

for page_number in paginator.page_range:
page = paginator.page(page_number)
updates = []

Check warning on line 17 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L15-L17

Added lines #L15 - L17 were not covered by tests

for obj in page.object_list:
obj.name = '%d - %s' % (obj.id, obj.name)
updates.append(obj)

Check warning on line 21 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L19-L21

Added lines #L19 - L21 were not covered by tests

Voucher.objects.bulk_update(updates, ['name'])

Check warning on line 23 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L23

Added line #L23 was not covered by tests


class Migration(migrations.Migration):

Check warning on line 26 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L26

Added line #L26 was not covered by tests

dependencies = [

Check warning on line 28 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L28

Added line #L28 was not covered by tests
('voucher', '0012_voucher_is_public'),
]

operations = [

Check warning on line 32 in ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py#L32

Added line #L32 was not covered by tests
migrations.RunPython(make_voucher_names_unique, migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Generated by Django 3.2.20 on 2023-11-08 13:55
# Generated by Django 3.2.20 on 2023-11-14 11:56

from django.db import migrations, models

Check warning on line 3 in ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py#L3

Added line #L3 was not covered by tests


class Migration(migrations.Migration):

Check warning on line 6 in ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py#L6

Added line #L6 was not covered by tests

dependencies = [

Check warning on line 8 in ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py#L8

Added line #L8 was not covered by tests
('voucher', '0012_voucher_is_public'),
('voucher', '0013_make_voucher_names_unique'),
]

operations = [

Check warning on line 12 in ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py#L12

Added line #L12 was not covered by tests
Expand Down

0 comments on commit ddbfe3e

Please sign in to comment.