-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ewen
committed
Aug 19, 2022
1 parent
13a947d
commit bf85d09
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Generated by Django 3.2.15 on 2022-08-18 12:12 | ||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
def change_certificate_model(new_model, old_model): | ||
OldCertificate = old_model | ||
NewCertificate = new_model | ||
|
||
old_certs = OldCertificate.objects.all() | ||
|
||
for old_cert in old_certs: | ||
new_cert = NewCertificate( | ||
id=old_cert.id, | ||
label=old_cert.label, | ||
type=old_cert.type, | ||
public_certificate=old_cert.public_certificate, | ||
private_key=old_cert.private_key, | ||
) | ||
new_cert.save() | ||
|
||
|
||
def migrate_certificate_forward(apps, _): | ||
change_certificate_model( | ||
new_model=apps.get_model("simple_certmanager", "Certificate"), | ||
old_model=apps.get_model("zgw_consumers", "Certificate"), | ||
) | ||
|
||
|
||
def migrate_certificate_backward(apps, _): | ||
change_certificate_model( | ||
new_model=apps.get_model("zgw_consumers", "Certificate"), | ||
old_model=apps.get_model("simple_certmanager", "Certificate"), | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("simple_certmanager", "0001_initial"), | ||
("zgw_consumers", "0015_auto_20220307_1522"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_certificate_forward, migrations.RunPython.noop), | ||
migrations.AlterField( | ||
model_name="service", | ||
name="client_certificate", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="The SSL/TLS certificate of the client", | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="service_client", | ||
to="simple_certmanager.certificate", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="service", | ||
name="server_certificate", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="The SSL/TLS certificate of the server", | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="service_server", | ||
to="simple_certmanager.certificate", | ||
), | ||
), | ||
migrations.RunPython(migrations.RunPython.noop, migrate_certificate_backward), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# # Generated by Django 3.2.15 on 2022-08-18 12:10 | ||
|
||
# import django.db.models.deletion | ||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_consumers", "0016_auto_20220818_1412"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="Certificate", | ||
), | ||
] |