Skip to content

It's impossible to revert migrations #1295

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

Closed
2 tasks done
yurasavin opened this issue Jun 30, 2023 · 7 comments
Closed
2 tasks done

It's impossible to revert migrations #1295

yurasavin opened this issue Jun 30, 2023 · 7 comments
Labels

Comments

@yurasavin
Copy link
Contributor

Describe the bug
I've faced with problem that it's impossible to revert migrations because migration 0006_alter_application_client_secret has no revert action

To Reproduce

  1. Apply migrations python manage.py migrate oauth2_provider
  2. Try to revert migrations python manage.py migrate oauth2_provider zero

Expected behavior
Migrations are reverted

Version
2.2.0

  • I have tested with the latest published release and it's still a problem.
  • I have tested with the master branch and it's still a problem.

Additional context

@yurasavin yurasavin added the bug label Jun 30, 2023
@yurasavin
Copy link
Contributor Author

This issue is not a big deal so I've created a PR with fix #1296

I hope I haven't break any rules for the issues and PR's

@n2ygk
Copy link
Member

n2ygk commented Jul 7, 2023

Per #1093 (see CHANGELOG for 2.0.0 migration 0006 is not reversible because it performs a one-way hash of any cleartext secrets.

I'm not sure what the right answer is here.

@yurasavin
Copy link
Contributor Author

Oh, I see now. OK we can't revert migrations without loosing the data, but how about to check in forwards_func if data has already hashed by prefix pbkdf2_sha256$ and skip hashing in case we reapply the migration?

@n2ygk
Copy link
Member

n2ygk commented Jul 11, 2023

@yura-savin
Copy link

I mean in some cases you need to roll back migrations, I've faced this situation in my development. I don't care about is my secrets hashed or not in this case, I just need to roll back this migration from django migrations table, but without revert function it's become unpossible by applying manage.py migrate oauth2_provider 0005 for example.

@n2ygk
Copy link
Member

n2ygk commented Jul 11, 2023

Agreed. Maybe add the reverse migration to 0006 like you did in #1296 but have it print a warning or something.

@dopry
Copy link
Contributor

dopry commented Oct 4, 2023

This was resolved in #1296. However I would like to say that reverse migrations are not something we can guaranteed. I feel we should avoid allowing reversing where it would lead to a broken site. Best practice is to test migrations in UAT environments, and to back up production data before apply migrations to minimize data loss in case an unreversible migration is applied and someone must revert their code.

If someone were to reverse over migration 006 and revert the code, then auth would fail since client_id lookups would no longer work.

@dopry dopry closed this as completed Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants