Source

django-lfs / lfs / core / management / commands / lfs_migrate.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# python imports
from copy import deepcopy

# django imports
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import connection
from django.db import transaction
from django.db import models
from django.utils.translation import ugettext_lazy as _

# lfs imports
import lfs.core.settings as lfs_settings
from lfs.voucher.models import Voucher

# south imports
from south.db import db


class Command(BaseCommand):
    args = ''
    help = 'Migrations for LFS'

    def handle(self, *args, **options):
        """
        """
        from lfs.core.models import Application
        try:
            application = Application.objects.get(pk=1)
        except Application.DoesNotExist:
            application = Application.objects.create(version="0.5")

        version = application.version
        print "Detected version: %s" % version

        if version == "0.5":
            self.migrate_to_06(application, version)
            self.migrate_to_07(application, version)
            self.migrate_to_08(application, version)
            print "Your database has been migrated to version 0.8."
        elif version == "0.6":
            self.migrate_to_07(application, version)
            self.migrate_to_08(application, version)
            print "Your database has been migrated to version 0.8."
        elif version == "0.7":
            self.migrate_to_08(application, version)
            print "Your database has been migrated to version 0.8."
        elif version == "0.8":
            print "You are up-to-date"

    def migrate_to_08(self, application, version):
        from django.contrib.contenttypes.models import ContentType
        from lfs.criteria.models import CartPriceCriterion
        from lfs.criteria.models import CombinedLengthAndGirthCriterion
        from lfs.criteria.models import CountryCriterion
        from lfs.criteria.models import HeightCriterion
        from lfs.criteria.models import LengthCriterion
        from lfs.criteria.models import WidthCriterion
        from lfs.criteria.models import WeightCriterion
        from lfs.criteria.models import ShippingMethodCriterion
        from lfs.criteria.models import PaymentMethodCriterion


        # Delete locale from shop
        db.delete_column("core_shop", "default_locale")

        # Migrate Criteria #####################################################

        cursor1 = connection.cursor()
        cursor2 = connection.cursor()
        cursor3 = connection.cursor()
        cursor4 = connection.cursor()

        db.add_column("criteria_cartpricecriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_combinedlengthandgirthcriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_heightcriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_lengthcriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_widthcriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_weightcriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_countrycriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_shippingmethodcriterion", "criterion_ptr_id", models.IntegerField(null=True))
        db.add_column("criteria_paymentmethodcriterion", "criterion_ptr_id", models.IntegerField(null=True))

        # CartPriceCriterion
        db.add_column("criteria_cartpricecriterion", "value", models.FloatField(default=0.0))

        cursor1.execute("""SELECT id FROM criteria_cartpricecriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(CartPriceCriterion)
        cursor2.execute("""SELECT id, operator, price FROM criteria_cartpricecriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            CartPriceCriterion.objects.create(operator=row[1], value=row[2], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

        cursor1.execute("""DELETE FROM criteria_cartpricecriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        db.delete_column("criteria_cartpricecriterion", "price")

        # CombinedLengthAndGirthCriterion
        db.add_column("criteria_combinedlengthandgirthcriterion", "value", models.FloatField(default=0.0))

        cursor1.execute("""SELECT id FROM criteria_combinedlengthandgirthcriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(CombinedLengthAndGirthCriterion)
        cursor2.execute("""SELECT id, operator, clag FROM criteria_combinedlengthandgirthcriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            CombinedLengthAndGirthCriterion.objects.create(operator=row[1], value=row[2], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

        cursor1.execute("""DELETE FROM criteria_combinedlengthandgirthcriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        # HeightCriterion
        db.add_column("criteria_heightcriterion", "value", models.FloatField(default=0.0))

        cursor1.execute("""SELECT id FROM criteria_heightcriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(HeightCriterion)
        cursor2.execute("""SELECT id, operator, height FROM criteria_heightcriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            HeightCriterion.objects.create(operator=row[1], value=row[2], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

        cursor1.execute("""DELETE FROM criteria_heightcriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()
        db.delete_column("criteria_heightcriterion", "height")

        # LengthCriterion
        db.add_column("criteria_lengthcriterion", "value", models.FloatField(default=0.0))

        cursor1.execute("""SELECT id FROM criteria_lengthcriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(LengthCriterion)
        cursor2.execute("""SELECT id, operator, length FROM criteria_lengthcriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            LengthCriterion.objects.create(operator=row[1], value=row[2], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

        cursor1.execute("""DELETE FROM criteria_lengthcriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        db.delete_column("criteria_lengthcriterion", "length")

        # WidthCriterion
        db.add_column("criteria_widthcriterion", "value", models.FloatField(default=0.0))

        cursor1.execute("""SELECT id FROM criteria_widthcriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(WidthCriterion)
        cursor2.execute("""SELECT id, operator, width FROM criteria_widthcriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            WidthCriterion.objects.create(operator=row[1], value=row[2], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

        cursor1.execute("""DELETE FROM criteria_widthcriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        db.delete_column("criteria_widthcriterion", "width")

        # WeightCriterion
        db.add_column("criteria_weightcriterion", "value", models.FloatField(default=0.0))

        cursor1.execute("""SELECT id FROM criteria_weightcriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(WeightCriterion)
        cursor2.execute("""SELECT id, operator, weight FROM criteria_weightcriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            WeightCriterion.objects.create(operator=row[1], value=row[2], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

        cursor1.execute("""DELETE FROM criteria_weightcriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        db.delete_column("criteria_weightcriterion", "weight")

        # CountryCriterion
        from lfs.core.models import Country
        db.create_table('criteria_countrycriterion_value', (
            ('id', models.AutoField(primary_key=True)),
            ('countrycriterion', models.ForeignKey(CountryCriterion)),
            ('country', models.ForeignKey(Country)),
        ))

        cursor1.execute("""SELECT id FROM criteria_countrycriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(CountryCriterion)
        cursor2.execute("""SELECT id, operator FROM criteria_countrycriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            cc = CountryCriterion.objects.create(operator=row[1], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

            cursor4.execute("""Select country_id FROM criteria_countrycriterion_countries WHERE id=%s""" %  row[0])
            for row_2 in cursor4.fetchall():
                cc.value.add(row_2[0])

        cursor1.execute("""DELETE FROM criteria_countrycriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        db.delete_table("criteria_countrycriterion_countries")

        # PaymentMethodCriterion
        from lfs.payment.models import PaymentMethod
        db.create_table('criteria_paymentmethodcriterion_value', (
            ('id', models.AutoField(primary_key=True)),
            ('paymentmethodcriterion', models.ForeignKey(PaymentMethodCriterion)),
            ('paymentmethod', models.ForeignKey(PaymentMethod)),
        ))

        cursor1.execute("""SELECT id FROM criteria_paymentmethodcriterion""")
        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(PaymentMethodCriterion)
        cursor2.execute("""SELECT id, operator FROM criteria_paymentmethodcriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            pmc = PaymentMethodCriterion.objects.create(operator=row[1], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

            cursor4.execute("""Select paymentmethod_id FROM criteria_paymentmethodcriterion_payment_methods WHERE id=%s""" %  row[0])
            for row_2 in cursor4.fetchall():
                pmc.value.add(row_2[0])

        cursor1.execute("""DELETE FROM criteria_paymentmethodcriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        db.delete_table("criteria_paymentmethodcriterion_payment_methods")

        # ShippingMethodCriterion
        from lfs.shipping.models import ShippingMethod
        db.create_table('criteria_shippingmethodcriterion_value', (
            ('id', models.AutoField(primary_key=True)),
            ('shippingmethodcriterion', models.ForeignKey(PaymentMethodCriterion)),
            ('shippingmethod', models.ForeignKey(ShippingMethod)),
        ))

        old_criteria = ", ".join([str(row[0]) for row in cursor1.fetchall()])

        content_type = ContentType.objects.get_for_model(ShippingMethodCriterion)
        cursor2.execute("""SELECT id, operator FROM criteria_shippingmethodcriterion""")
        for row in cursor2.fetchall():
            cursor3.execute("""Select content_type_id, content_id, position FROM criteria_criteriaobjects WHERE criterion_type_id=%s and criterion_id=%s""" % (content_type.id, row[0]))
            criterion_object = cursor3.fetchone()
            smc = ShippingMethodCriterion.objects.create(operator=row[1], content_type_id=criterion_object[0], content_id=criterion_object[1], position=criterion_object[2])

            cursor4.execute("""Select shippingmethod_id FROM criteria_shippingmethodcriterion_shipping_methods WHERE id=%s""" %  row[0])
            for row_2 in cursor4.fetchall():
                smc.value.add(row_2[0])

        cursor1.execute("""DELETE FROM criteria_shippingmethodcriterion WHERE id in (%s)""" % old_criteria)
        transaction.commit_unless_managed()

        db.delete_table("criteria_shippingmethodcriterion_shipping_methods")

    def migrate_to_07(self, application, version):
        from lfs.catalog.models import Product
        from lfs.catalog.settings import VARIANT
        from lfs.core.utils import get_default_shop
        from lfs.customer.models import Address
        from lfs.page.models import Page
        from lfs.shipping.models import ShippingMethod
        from lfs_order_numbers.models import OrderNumberGenerator

        # Product
        from lfs.catalog.settings import QUANTITY_FIELD_INTEGER
        from lfs.catalog.settings import QUANTITY_FIELD_TYPES

        db.add_column("catalog_product", "type_of_quantity_field", models.PositiveSmallIntegerField(_(u"Type of quantity field"), null=True, blank=True, choices=QUANTITY_FIELD_TYPES))
        db.add_column("catalog_product", "category_variant", models.SmallIntegerField(_(u"Category variant"), blank=True, null=True))
        db.add_column("catalog_product", "active_base_price", models.PositiveSmallIntegerField(_(u"Active base price"), default=0))
        db.add_column("catalog_product", "base_price_unit", models.CharField(_(u"Base price unit"), blank=True, null=True, max_length=30, choices=settings.LFS_BASE_PRICE_UNITS))
        db.add_column("catalog_product", "base_price_amount", models.FloatField(_(u"Base price amount"), default=0.0, blank=True, null=True))

        if db.backend_name == "postgres":
            db.execute('ALTER TABLE catalog_product ALTER active_packing_unit TYPE smallint USING CASE WHEN active_packing_unit=FALSE THEN 0 ELSE 1 END;')
        else:
            db.alter_column('catalog_product', 'active_packing_unit', models.PositiveSmallIntegerField(_(u"Active packing"), default=0))
            for product in Product.objects.all():
                if product.active_packing_unit != 0:
                    product.active_packing_unit = 1
                    product.save()

        # Pages
        print "Migrating to 0.7"
        db.add_column("page_page", "meta_title", models.CharField(_(u"Meta title"), blank=True, default="<title>", max_length=80))
        db.add_column("page_page", "meta_keywords", models.TextField(_(u"Meta keywords"), null=True, blank=True))
        db.add_column("page_page", "meta_description", models.TextField(_(u"Meta description"), null=True, blank=True))
        for page in Page.objects.all():
            page.meta_title = "<title>"
            page.meta_keywords = ""
            page.meta_description = ""
            page.save()

        # Copy the old page with id=1 and create a new one with id=1, which
        # will act as the root of all pages.
        try:
            page = Page.objects.get(pk=1)
        except Page.DoesNotExist:
            pass
        else:
            new_page = deepcopy(page)
            new_page.id = None
            new_page.save()
            page.delete()

        Page.objects.create(id=1, title="Root", slug="", active=1, exclude_from_navigation=1)

        # Shop
        db.add_column("core_shop", "meta_title", models.CharField(_(u"Meta title"), blank=True, default="<name>", max_length=80))
        db.add_column("core_shop", "meta_keywords", models.TextField(_(u"Meta keywords"), null=True, blank=True))
        db.add_column("core_shop", "meta_description", models.TextField(_(u"Meta description"), null=True, blank=True))

        shop = get_default_shop()
        shop.meta_keywords = ""
        shop.meta_description = ""
        shop.save()

        # Order
        db.add_column("order_order", "number", models.CharField(max_length=30, unique=True, null=True))
        OrderNumberGenerator.objects.create(pk="1", last=0)

        # Add new lines
        db.add_column("order_order", "invoice_company_name", models.CharField(null=True, blank=True, max_length=100))
        db.add_column("order_order", "shipping_company_name", models.CharField(null=True, blank=True, max_length=100))

        # Shipping Method
        db.add_column("shipping_shippingmethod", "price_calculator", models.CharField(max_length=200, choices=settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS, default=settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS[0][0]))
        for shipping_method in ShippingMethod.objects.all():
            shipping_method.price_calculator = settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS[0][0]
            shipping_method.save()

        # Static Block
        db.add_column("catalog_staticblock", "position", models.PositiveSmallIntegerField(_(u"Position"), default=999))

        # Addresses
        db.add_column("customer_address", "line1", models.CharField(_("Line 1"), max_length=100, blank=True, null=True))
        db.add_column("customer_address", "line2", models.CharField(_("Line 2"), max_length=100, blank=True, null=True))

        cursor = connection.cursor()
        cursor.execute("""SELECT id, street FROM customer_address""")
        for row in cursor.fetchall():
            address = Address.objects.get(pk=row[0])
            address.line1 = row[1]
            address.save()

        db.delete_column("customer_address", "street")

        application.version = "0.7"
        application.save()

    def migrate_to_06(self, application, version):
        from lfs.core.models import Shop
        print "Migrating to 0.6"

        # Vouchers ###########################################################
        db.add_column("voucher_voucher", "used_amount", models.PositiveSmallIntegerField(default=0))
        db.add_column("voucher_voucher", "last_used_date", models.DateTimeField(blank=True, null=True))
        db.add_column("voucher_voucher", "limit", models.PositiveSmallIntegerField(default=1))

        for voucher in Voucher.objects.all():
            voucher.limit = 1
            voucher.save()

        # This mus be done with execute because the old fields are not there
        # anymore (and therefore can't be accessed via attribute) after the user
        # has upgraded to the latest version.
        db.execute("update voucher_voucher set used_amount = 1 where used = 1")
        db.execute("update voucher_voucher set used_amount = 0 where used = 0")
        db.execute("update voucher_voucher set last_used_date = used_date")

        db.delete_column('voucher_voucher', 'used')
        db.delete_column('voucher_voucher', 'used_date')

        # Price calculator ###################################################
        db.add_column("catalog_product", "price_calculator", models.CharField(
            null=True, blank=True, choices=settings.LFS_PRICE_CALCULATORS, max_length=255))

        db.add_column("core_shop", "price_calculator",
            models.CharField(choices=lfs_settings.LFS_PRICE_CALCULATORS, default="lfs.gross_price.GrossPriceCalculator", max_length=255))

        # Locale and currency settings #######################################
        db.add_column("core_shop", "default_locale",
            models.CharField(_(u"Default Shop Locale"), max_length=20, default="en_US.UTF-8"))
        db.add_column("core_shop", "use_international_currency_code",
            models.BooleanField(_(u"Use international currency codes"), default=False))
        db.delete_column('core_shop', 'default_currency')

        db.add_column("catalog_product", "supplier_id", models.IntegerField(_(u"Supplier"), blank=True, null=True))

        # Invoice/Shipping countries
        try:
            shop = Shop.objects.only("id").get(pk=1)
        except Shop.DoesNotExist, e:  # No guarantee that our shop will have pk=1 in postgres
            shop = Shop.objects.only("id").all()[0]

        db.create_table("core_shop_invoice_countries", (
            ("id", models.AutoField(primary_key=True)),
            ("shop_id", models.IntegerField("shop_id")),
            ("country_id", models.IntegerField("country_id")),
        ))
        db.create_index("core_shop_invoice_countries", ("shop_id", ))
        db.create_index("core_shop_invoice_countries", ("country_id", ))
        db.create_unique("core_shop_invoice_countries", ("shop_id", "country_id"))

        db.create_table("core_shop_shipping_countries", (
            ("id", models.AutoField(primary_key=True)),
            ("shop_id", models.IntegerField("shop_id")),
            ("country_id", models.IntegerField("country_id")),
        ))
        db.create_index("core_shop_shipping_countries", ("shop_id", ))
        db.create_index("core_shop_shipping_countries", ("country_id", ))
        db.create_unique("core_shop_shipping_countries", ("shop_id", "country_id"))

        cursor = connection.cursor()
        cursor.execute("""SELECT country_id FROM core_shop_countries""")
        for row in cursor.fetchall():
            shop.invoice_countries.add(row[0])
            shop.shipping_countries.add(row[0])

        db.delete_table("core_shop_countries")

        # Orders #############################################################

        # Add new lines
        db.add_column("order_order", "invoice_line1", models.CharField(null=True, blank=True, max_length=100))
        db.add_column("order_order", "shipping_line1", models.CharField(null=True, blank=True, max_length=100))
        db.add_column("order_order", "invoice_line2", models.CharField(null=True, blank=True, max_length=100))
        db.add_column("order_order", "shipping_line2", models.CharField(null=True, blank=True, max_length=100))
        db.add_column("order_order", "invoice_code", models.CharField(null=True, blank=True, max_length=100))
        db.add_column("order_order", "shipping_code", models.CharField(null=True, blank=True, max_length=100))

        # Migrate data
        cursor.execute("""SELECT id, invoice_zip_code, shipping_zip_code, invoice_street, shipping_street FROM order_order""")
        for row in cursor.fetchall():
            order = Order.objects.get(pk=row[0])
            order.invoice_code = row[1]
            order.shipping_code = row[2]
            order.invoice_line1 = row[3]
            order.shipping_line1 = row[4]
            order.invoice_line2 = ""
            order.shipping_line2 = ""
            order.save()

        # Remove old code fields
        db.delete_column('order_order', 'invoice_zip_code')
        db.delete_column('order_order', 'shipping_zip_code')
        db.delete_column('order_order', 'invoice_street')
        db.delete_column('order_order', 'shipping_street')

        application.version = "0.6"
        application.save()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.