Squash migrations
Re2o is almost 5 years old, it is time that we squash migrations. This is a tedious task. I decided to create three migrations for each app:
- Create all models without foreign keys;
- Create foreign keys;
- Miscellaneous tasks, for everything that is still needed (e.g. specific model creations...)
This will fix #42 (closed). It is also a good occasion to fix #273 (closed).
How to test?
- Check on an existing db that
./manage.py migrate
does nothing except migrating the API - Create a new db and migrate it then check that django does not want to create any new migration with
./manage.py makemigrations
- try to use the API on the newly created database.
- Check that a database that is old enough manages to migrate up to date.
Result
Before :
root@e0332054eb91:/var/www/re2o# time ./manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, authtoken, contenttypes, cotisations, machines, multi_op, preferences, reversion, sessions, tickets, topologie, users
Running migrations:
... lot of stuff here
Applying users.0095_user_theme... OK
real 0m36.545s
user 0m29.962s
sys 0m0.497s
root@e0332054eb91:/var/www/re2o#
After :
root@e0332054eb91:/var/www/re2o# time ./manage.py migrate
Operations to perform:
Apply all migrations: admin, api, auth, authtoken, contenttypes, cotisations, machines, multi_op, preferences, reversion, sessions, tickets, topologie, users
Running migrations:
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying users.0001_model_creation... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying api.0001_initial... OK
Applying authtoken.0001_initial... OK
Applying authtoken.0002_auto_20160226_1747... OK
Applying cotisations.0001_model_creation... OK
Applying cotisations.0002_foreign_keys... OK
Applying machines.0001_model_creation... OK
Applying machines.0002_foreign_keys... OK
Applying topologie.0001_model_creation... OK
Applying preferences.0001_model_creation... OK
Applying topologie.0002_foreign_keys... OK
Applying multi_op.0001_squashed_0003_auto_20200904_1938... OK
Applying reversion.0001_squashed_0004_auto_20160611_1202... OK
Applying preferences.0002_foreign_keys... OK
Applying sessions.0001_initial... OK
Applying tickets.0001_squashed_0007... OK
Applying users.0002_foreign_keys... OK
Applying users.0003_ldapserviceuser_ldapserviceusergroup_ldapuser_ldapusergroup... OK
real 0m27.804s
user 0m12.308s
sys 0m1.300s
root@e0332054eb91:/var/www/re2o#
## Current progress:
Migration 1
I will write down the models I treated here.
-
Preferences: - OptionalUser
- OptionalMachine
- OptionalTopologie
- RadiusKey
- SwitchManagementCred
- Reminder
- GeneralOption
- Service
- AssoOption
- HomeOption
- MailMessageOption
- RadiusAttribute
- RadiusOption
-
Cotisations - BaseInvoice
- Facture
- CustomInvoice
- CostEstimate
- Vente
- Article
- Banque
- Paiement
- Cotisation
- BalancePayment
- ChequePayment
- ComnpayPayment
- FreePayment
-
Machines - Machine
- MachineType
- IpType
- Vlan
- Nas
- SOA
- Extension
- Mx
- Ns
- Txt
- DName
- Srv
- SshFp
- Interface
- Ipv6List
- Domain
- IpList
- Role
- Service
- OuverturePortList
- OuverturePort
-
Multi Op -
Tickets -
Topologie - Stack
- AccessPoint
- Server
- Switch
- ModelSwitch
- ModuleSwitch
- ModuleOnSwitch
- ConstructorSwitch
- SwitchBay
- Dormitory
- Building
- Port
- PortProfile
-
Users - User
- Adherent
- Club
- ServiceUser
- School
- ListRight
- ListShell
- Ban
- Whitelist
- Request
- EmailAddress
Migration 2
I will write down the foreign keys I notice as I prepare migration 1.
-
Preferences -
OptionalUser.shell_default -
OptionalTopologie.switchs_ip_type -
AssoOption.utilisateur_asso -
Mandate.president -
RadiusOption.unknown_machine_vlan -
RadiusOption.unknown_machine_attributes -
RadiusOption.unknown_port_vlan -
RadiusOption.unknown_port_attributes -
RadiusOption.unknown_room_vlan -
RadiusOption.unknown_room_attributes -
RadiusOption.non_member_vlan -
RadiusOption.non_member_attributes -
RadiusOption.banned_vlan -
RadiusOption.banned_attributes -
RadiusOption.vlan_decision_ok -
RadiusOption.ok_attributes -
CotisationsOption.invoice_template -
CotisationsOption.voucher_template
-
-
Cotisations -
Facture.user -
Facture.paiement -
Facture.banque -
CostEstimate.final_invoice -
Vente.facture -
CotisaInterfacetion.vente -
BalancePayment.payment -
ChequePayment.payment -
ComnpayPayment.payment -
FreePayment.payment -
NotePayment.payment
-
-
Machines -
Machine.user -
MachineType.ip_type -
IpType.extension -
IpType.vlan -
IpType.ouverture_ports -
Nas.nas_type -
Nas.machine_type -
Extension.origin -
Extension.soa -
Mx.zone -
Mx.name -
Ns.zone -
Ns.ns -
Txt.zone -
DName.zone -
Srv.extension -
Srv.target -
SshFp.machine -
Interface.ipv4 -
Interface.machine -
Interface.machine_type -
Interface.port_lists -
Ipv6List.interface -
Domain.interface_parent -
Domain.extension -
IpList.ip_type -
Role.servers -
Service.servers -
Service_link.service -
Service_link.server -
OuverturePort.port_list
-
-
Topologie -
Switch.stack -
Switch.model -
Switch.switchbay -
Switch.radius_key -
Switch.management_creds -
ModelSwitch.constructor -
ModuleOnSwitch.module -
ModuleOnSwitch.switch -
SwitchBay.building -
Building.dormitory -
Port.switch -
Port.room -
Port.machine_interface -
Port.related -
Port.custom_profile -
Port.switch -
PortProfile.on_dormitory -
PortProfile.vlan_untagged -
PortProfile.vlan_tagged
-
-
Users -
User.school -
User.shell -
Adherent.room -
Club.room -
Club.administrators -
Club.members -
Ban.user -
Whitelist.user -
Request.user -
EMailAddress.user
-
Migration 3
I will write down here the miscellaneous migrations that are needed and not covered by migrations 1 and 2.
- [x] Users
-
LdapUser -
LdapUserGroup -
LdapServiceUser -
LdapServiceUserGroup
-