mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Refs #29722 -- Added introspection of materialized views for PostgreSQL.
This commit is contained in:
parent
45ef3df7d0
commit
bf8b625a3b
4 changed files with 50 additions and 12 deletions
|
@ -310,6 +310,30 @@ class InspectDBTransactionalTests(TransactionTestCase):
|
|||
with connection.cursor() as cursor:
|
||||
cursor.execute('DROP VIEW inspectdb_people_view')
|
||||
|
||||
@skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific SQL')
|
||||
def test_include_materialized_views(self):
|
||||
"""inspectdb --include-views creates models for database materialized views."""
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
'CREATE MATERIALIZED VIEW inspectdb_people_materialized_view AS '
|
||||
'SELECT id, name FROM inspectdb_people'
|
||||
)
|
||||
out = StringIO()
|
||||
view_model = 'class InspectdbPeopleMaterializedView(models.Model):'
|
||||
view_managed = 'managed = False # Created from a view.'
|
||||
try:
|
||||
call_command('inspectdb', table_name_filter=inspectdb_tables_only, stdout=out)
|
||||
no_views_output = out.getvalue()
|
||||
self.assertNotIn(view_model, no_views_output)
|
||||
self.assertNotIn(view_managed, no_views_output)
|
||||
call_command('inspectdb', table_name_filter=inspectdb_tables_only, include_views=True, stdout=out)
|
||||
with_views_output = out.getvalue()
|
||||
self.assertIn(view_model, with_views_output)
|
||||
self.assertIn(view_managed, with_views_output)
|
||||
finally:
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute('DROP MATERIALIZED VIEW IF EXISTS inspectdb_people_materialized_view')
|
||||
|
||||
@skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific SQL')
|
||||
def test_foreign_data_wrapper(self):
|
||||
with connection.cursor() as cursor:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue