django-tenants / django-tenants

Django tenants using PostgreSQL Schemas
MIT License
1.49k stars 339 forks source link

Progress and organisation information from migrate_schemas is missing from redirected output #755

Open mikicz opened 2 years ago

mikicz commented 2 years ago

Hi, I noticed something when reviewing logs from our migrations when deployed to AWS using docker, the progress and organisation information is missing. This is quite annoying as progress is then really hard to watch. I managed to reproduce locally. Is there some setting which could fix this, or some environment variable? I tried setting DJANGO_COLORS=nocolor but that didn't help.

Regular behaviour:

$ python manage.py migrate_schemas
[standard:public] === Starting migration
[standard:public] Operations to perform:
[standard:public]   Apply all migrations: [REDACTED]
[standard:public] Running migrations:
[standard:public]   No migrations to apply.
[1/2 (50%) standard:org_chavez_sanchez] === Starting migration
[1/2 (50%) standard:org_chavez_sanchez] Operations to perform:
[1/2 (50%) standard:org_chavez_sanchez]   Apply all migrations: [REDACTED]
[1/2 (50%) standard:org_chavez_sanchez] Running migrations:
[1/2 (50%) standard:org_chavez_sanchez]   No migrations to apply.
[2/2 (100%) standard:org_test] === Starting migration
[2/2 (100%) standard:org_test] Operations to perform:
[2/2 (100%) standard:org_test]   Apply all migrations: [REDACTED]
[2/2 (100%) standard:org_test] Running migrations:
[2/2 (100%) standard:org_test]   No migrations to apply.

With redirection:

$ python manage.py migrate_schemas >out.txt 2>&1
$ cat out.txt
=== Starting migration
Operations to perform:
  Apply all migrations: [REDACTED]
Running migrations:
  No migrations to apply.
=== Starting migration
Operations to perform:
  Apply all migrations: [REDACTED]
Running migrations:
  No migrations to apply.
=== Starting migration
Operations to perform:
  Apply all migrations: [REDACTED]
Running migrations:
  No migrations to apply.
tomturner commented 2 years ago

I got to say I was unware of that. However there is a singal that gets called when a message is displayed.

@receiver(schema_migrate_message, sender=run_migrations)
def handle_schema_migrate_message(**kwargs):
    message = kwargs['message']
    # recreate materialized views in the schema
prince-tanapong commented 1 year ago

Same problem any suggestion on this? Seem like it quite serious when we have a migration problem and try to debug

johnernaut commented 4 months ago

Just chiming in here to say we're seeing this issue as well, and as @prince-tanapong mentioned, it's super difficult to debug issues that pop up during migrations without knowing the tenant that's experiencing the issue 😢