-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Cannot test migrations if there is a collation in the migrations #343
Comments
I found this workaround: class TestMyMigration(MigratorTestCase):
databases = ("default", "my_db",)
database_name = "my_db"
# ...
def setUp(self) -> None:
sql.drop_models_tables(self.database_name)
sql.flush_django_migrations_table(self.database_name)
with connections["my_db"].cursor() as cursor:
cursor.execute("DROP COLLATION french")
super().setUp()
def test_my_migration(self):
pass |
hi 👋 Creating a collation is tricky because it's not a data migration, it's just changing the DB configuration/metadata. Probably the best solution will be to add some hook (something like, |
Yes, seems like a good idea. Something like |
Sounds great! |
@jrobichaud would you like to send a PR? :) |
I could give it a try. I have trouble finding meaningful names. For the TestCase it could work:
For the migrator:
In theory someone could want to run 4 different things depending if its before/after apply in forward/reverse migration. I only need before apply in forward migration. Any thoughts about this? |
Is anything needed for the migrator at all considering the user call it himself directly? He could just add the just before the function. I believe only the TestCase needs new functions. |
yes, that's true that when the developers are using the So I would add following arguments to
and for the
Optionally also |
I am also having problems using Procrastinate (see mention above) because it creates some custom tables, functions and types in PostgreSQL. I wonder why only the Django models are dropped and not the whole database itself is reset (by dropping and recreating). It would be at least nice to have the option. |
PR is welcome. |
Sure, I can look into it (it will take some days to work on it). As you are deeper into it, what was the initial reason not to drop the whole database and then start from scratch but instead drop the model tables?
EDIT: @pytest.mark.django_db
def test_foobar(migrator: Migrator):
close_old_connections()
call_command("reset_db", "--noinput")
assert True So, does anything speak against dropping the whole database and integrating something like the code of |
I have a migration with a collation:
Ex:
When running the migration tests I have this error:
The text was updated successfully, but these errors were encountered: