|
| 1 | +# Regression test for false positives like this due to incomplete `Field` annotations. |
| 2 | +# Type annotations must provide the type vars otherwise they get inferred as `Field[Any, Any, Literal[False]]` in some |
| 3 | +# contexts, which is usually wrong. Annotations accepting any field should use `Field[Any, Any, Any]` |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +from typing import TYPE_CHECKING |
| 7 | + |
| 8 | +import django.db.models.deletion |
| 9 | +from django.db import migrations, models |
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + from django.db.backends.base.schema import BaseDatabaseSchemaEditor |
| 13 | + from django.db.migrations.state import StateApps |
| 14 | + |
| 15 | + |
| 16 | +def forwards(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: |
| 17 | + pass |
| 18 | + |
| 19 | + |
| 20 | +def backwards(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: |
| 21 | + pass |
| 22 | + |
| 23 | + |
| 24 | +class Migration(migrations.Migration): |
| 25 | + dependencies = [ |
| 26 | + ("corporate", "0037_customerplanoffer"), |
| 27 | + ] |
| 28 | + |
| 29 | + operations = [ |
| 30 | + migrations.AddField( |
| 31 | + model_name="customerplanoffer", |
| 32 | + name="sent_invoice_id", |
| 33 | + field=models.CharField(max_length=255, null=True), |
| 34 | + ), |
| 35 | + migrations.AlterField( |
| 36 | + model_name="customerplanoffer", |
| 37 | + name="sent_invoice_id", |
| 38 | + field=models.CharField(max_length=512, null=True), |
| 39 | + preserve_default=False, |
| 40 | + ), |
| 41 | + migrations.RenameField( |
| 42 | + model_name="customerplanoffer", |
| 43 | + old_name="sent_invoice_id", |
| 44 | + new_name="invoice_id", |
| 45 | + ), |
| 46 | + migrations.RemoveField( |
| 47 | + model_name="customerplanoffer", |
| 48 | + name="invoice_id", |
| 49 | + ), |
| 50 | + migrations.CreateModel( |
| 51 | + name="Invoice", |
| 52 | + fields=[ |
| 53 | + ( |
| 54 | + "id", |
| 55 | + models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"), |
| 56 | + ), |
| 57 | + ("stripe_invoice_id", models.CharField(max_length=255, unique=True)), |
| 58 | + ("status", models.SmallIntegerField()), |
| 59 | + ( |
| 60 | + "customer", |
| 61 | + models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="corporate.customer"), |
| 62 | + ), |
| 63 | + ], |
| 64 | + options={"db_table": "invoice"}, |
| 65 | + ), |
| 66 | + migrations.RenameModel(old_name="Invoice", new_name="StripeInvoice"), |
| 67 | + migrations.AlterModelTable(name="stripeinvoice", table="billing_stripe_invoice"), |
| 68 | + migrations.AlterModelTableComment(name="stripeinvoice", table_comment="Stripe invoices"), |
| 69 | + migrations.AlterModelOptions( |
| 70 | + name="stripeinvoice", |
| 71 | + options={"ordering": ["-id"], "verbose_name": "Stripe invoice"}, |
| 72 | + ), |
| 73 | + migrations.AlterModelManagers( |
| 74 | + name="stripeinvoice", |
| 75 | + managers=[("objects", models.Manager())], |
| 76 | + ), |
| 77 | + migrations.AlterUniqueTogether( |
| 78 | + name="stripeinvoice", |
| 79 | + unique_together={("stripe_invoice_id", "customer")}, |
| 80 | + ), |
| 81 | + migrations.AlterIndexTogether( |
| 82 | + name="stripeinvoice", |
| 83 | + index_together={("status", "customer")}, |
| 84 | + ), |
| 85 | + migrations.AlterOrderWithRespectTo( |
| 86 | + name="stripeinvoice", |
| 87 | + order_with_respect_to="customer", |
| 88 | + ), |
| 89 | + migrations.AddIndex( |
| 90 | + model_name="stripeinvoice", |
| 91 | + index=models.Index(fields=["stripe_invoice_id"], name="invoice_stripe_idx"), |
| 92 | + ), |
| 93 | + migrations.RenameIndex( |
| 94 | + model_name="stripeinvoice", |
| 95 | + new_name="invoice_stripe_id_idx", |
| 96 | + old_name="invoice_stripe_idx", |
| 97 | + ), |
| 98 | + migrations.RemoveIndex( |
| 99 | + model_name="stripeinvoice", |
| 100 | + name="invoice_stripe_id_idx", |
| 101 | + ), |
| 102 | + migrations.AddConstraint( |
| 103 | + model_name="stripeinvoice", |
| 104 | + constraint=models.UniqueConstraint(fields=["stripe_invoice_id"], name="invoice_stripe_id_uniq"), |
| 105 | + ), |
| 106 | + migrations.AlterConstraint( |
| 107 | + model_name="stripeinvoice", |
| 108 | + name="invoice_stripe_id_uniq", |
| 109 | + constraint=models.UniqueConstraint(fields=["stripe_invoice_id", "customer"], name="invoice_stripe_id_uniq"), |
| 110 | + ), |
| 111 | + migrations.RemoveConstraint( |
| 112 | + model_name="stripeinvoice", |
| 113 | + name="invoice_stripe_id_uniq", |
| 114 | + ), |
| 115 | + migrations.RunSQL( |
| 116 | + sql="UPDATE billing_stripe_invoice SET status = 0 WHERE status IS NULL", |
| 117 | + reverse_sql=migrations.RunSQL.noop, |
| 118 | + ), |
| 119 | + migrations.RunPython( |
| 120 | + code=forwards, |
| 121 | + reverse_code=backwards, |
| 122 | + ), |
| 123 | + migrations.SeparateDatabaseAndState( |
| 124 | + database_operations=[ |
| 125 | + migrations.RunSQL("CREATE INDEX legacy_idx ON billing_stripe_invoice(status)"), |
| 126 | + ], |
| 127 | + state_operations=[ |
| 128 | + migrations.AddIndex( |
| 129 | + model_name="stripeinvoice", |
| 130 | + index=models.Index(fields=["status"], name="legacy_idx"), |
| 131 | + ), |
| 132 | + ], |
| 133 | + ), |
| 134 | + migrations.DeleteModel(name="StripeInvoice"), |
| 135 | + ] |
0 commit comments