|
11 | 11 | from django.core import exceptions
|
12 | 12 | from django.db import connection, transaction
|
13 | 13 | from django.db import models
|
| 14 | +from django.db.models import Index |
14 | 15 | from django.db.models.query import QuerySet
|
15 | 16 |
|
16 | 17 | from django_pgviews.db import get_fields_by_name
|
@@ -95,6 +96,10 @@ def _drop_mat_view(cursor, view_name):
|
95 | 96 | cursor.execute("DROP MATERIALIZED VIEW IF EXISTS {0} CASCADE;".format(view_name))
|
96 | 97 |
|
97 | 98 |
|
| 99 | +def _concurrent_index_name(view_name, concurrent_index): |
| 100 | + return view_name + "_" + "_".join([s.strip() for s in concurrent_index.split(",")]) + "_index" |
| 101 | + |
| 102 | + |
98 | 103 | @transaction.atomic()
|
99 | 104 | def create_materialized_view(connection, view_cls, check_sql_changed=False):
|
100 | 105 | """
|
@@ -160,9 +165,12 @@ def create_materialized_view(connection, view_cls, check_sql_changed=False):
|
160 | 165 | log.info("pgview created materialized view %s (%s)", view_name, schema_name_log)
|
161 | 166 |
|
162 | 167 | if concurrent_index is not None:
|
163 |
| - index_sub_name = "_".join([s.strip() for s in concurrent_index.split(",")]) |
164 | 168 | cursor.execute(
|
165 |
| - "CREATE UNIQUE INDEX {0}_{1}_index ON {0} ({2})".format(view_name, index_sub_name, concurrent_index) |
| 169 | + "CREATE UNIQUE INDEX {index_name} ON {view_name} ({concurrent_index})".format( |
| 170 | + view_name=view_name, |
| 171 | + index_name=_concurrent_index_name(view_name, concurrent_index), |
| 172 | + concurrent_index=concurrent_index, |
| 173 | + ) |
166 | 174 | )
|
167 | 175 | log.info("pgview created concurrent index on view %s (%s)", view_name, schema_name_log)
|
168 | 176 |
|
|
0 commit comments