Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion django_pgviews/management/commands/makemigrations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
from django.apps import apps
from django.core.management import load_command_class
from django.core.management.commands.makemigrations import Command as MakeMigrationsCommand

from django_pgviews.db.migrations.autodetector import PGViewsAutodetector


class Command(MakeMigrationsCommand):
def get_base_makemigrations_command():
"""
Find the makemigrations command from apps loaded before django_pgviews.

This ensures compatibility with other packages that override makemigrations
(e.g., django-linear-migrations) by inheriting from their command instead
of Django's base command directly.
"""
for app_config in apps.get_app_configs():
# Stop when we reach django_pgviews to avoid circular dependency
if app_config.name == "django_pgviews":
break
try:
# Try to load makemigrations command from this app
return load_command_class(app_config.name, "makemigrations")
except (ImportError, AttributeError):
# This app doesn't have a custom makemigrations command
continue
# No custom command found, use Django's default
return MakeMigrationsCommand


class Command(get_base_makemigrations_command()):
"""Django 6.0 compatible makemigrations with PGViewsAutodetector."""

autodetector = PGViewsAutodetector
27 changes: 26 additions & 1 deletion django_pgviews/management/commands/migrate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
from django.apps import apps
from django.core.management import load_command_class
from django.core.management.commands.migrate import Command as MigrateCommand

from django_pgviews.db.migrations.autodetector import PGViewsAutodetector


class Command(MigrateCommand):
def get_base_migrate_command():
"""
Find the migrate command from apps loaded before django_pgviews.

This ensures compatibility with other packages that override migrate
by inheriting from their command instead of Django's base command directly.
"""
for app_config in apps.get_app_configs():
# Stop when we reach django_pgviews to avoid circular dependency
if app_config.name == "django_pgviews":
break
try:
# Try to load migrate command from this app
return load_command_class(app_config.name, "migrate")
except (ImportError, AttributeError):
# This app doesn't have a custom migrate command
continue
# No custom command found, use Django's default
return MigrateCommand


class Command(get_base_migrate_command()):
"""Django 6.0 compatible migrate with PGViewsAutodetector."""

autodetector = PGViewsAutodetector
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-pgviews-redux"
version = "1.0.1"
version = "1.1.0"
description = "Create and manage Postgres SQL Views in Django"
authors = ["Mikuláš Poul <mikulas.poul@xelix.com>"]
readme = "README.md"
Expand Down
Loading