Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration 0002 in OI app breaks clearing database #352

Closed
dawidratynski opened this issue Mar 20, 2024 · 3 comments
Closed

Migration 0002 in OI app breaks clearing database #352

dawidratynski opened this issue Mar 20, 2024 · 3 comments
Assignees

Comments

@dawidratynski
Copy link
Contributor

Migration 0002 in OI app causes db clearing to not work, by breaking the python manage.py flush command (and by extension: ./easytoolbox.py flush-db), which is needed for running cypress tests locally.

File: https://github.com/sio2project/oioioi/blob/c3c399b02312dc1420aa43b474b9c01d10e9463e/oioioi/oi/migrations/0002_auto_20160412_1720.py

This migration removes Region and OIOnsiteRegistration models from the OI app, but does not delete their tables from the database (migrations.SeparateDatabaseAndState). Said tables contain non-nullable foreign key fields to other tables, causing an error when trying to clear the db, as Django only clears tables related to existing objects.

Depending on whether deleting these tables is acceptable, I found two possible solutions:

  1. If we can't delete the tables, we can make the foreign key fields nullable:
database_operations = [
        migrations.AlterField(
            model_name='oionsiteregistration',
            name='region',
            field=models.IntegerField(verbose_name='region', null=True),
        ),
        migrations.AlterField(
            model_name='oionsiteregistration',
            name='participant',
            field=oioioi.participants.fields.OneToOneBothHandsCascadingParticipantField(related_name='oi_oionsiteregistration', to='participants.Participant', on_delete=models.CASCADE, null=True),
        ),
        migrations.AlterField(
            model_name='region',
            name='contest',
            field=models.ForeignKey(to='contests.Contest', on_delete=models.CASCADE, null=True),
        )
    ]

    state_operations = [
        migrations.DeleteModel('oionsiteregistration'),
        migrations.DeleteModel('region'),
    ]

    operations = [
        migrations.SeparateDatabaseAndState(
            database_operations=database_operations,
            state_operations=state_operations)
    ]
  1. If we can delete said tables:
operations = [
        migrations.DeleteModel(
            name='OIOnsiteRegistration',
        ),
        migrations.DeleteModel(
            name='Region',
        ),
    ]

Both solutions fix the issue and pass all tests (as of 19.03.2024 / commit 056caf6).

@dawidratynski dawidratynski self-assigned this Mar 20, 2024
@A-dead-pixel
Copy link
Contributor

This is probably caused by f55acf6.

@dawidratynski
Copy link
Contributor Author

Created branches with implemented solutions for testing:

With deleting tables:
https://github.com/dawidratynski/oioioi/tree/fix-oi-migration-v1

Without deleting tables:
https://github.com/dawidratynski/oioioi/tree/fix-oi-migration-v2

@twalen
Copy link
Contributor

twalen commented Apr 10, 2024

I prefer solution without removing tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants