@@ -137,6 +137,14 @@ This will take all fields on `myapp.Customer` and apply them to
137
137
138
138
## Features
139
139
140
+ ### Configuration
141
+ ` MATERIALIZED_VIEWS_DISABLE_SYNC_ON_MIGRATE `
142
+
143
+ When set to True, it skips running ` sync_pgview ` during migrations, which can be useful if you want to control the synchronization manually or avoid potential overhead during migrations. (default: False)
144
+ ```
145
+ MATERIALIZED_VIEWS_DISABLE_SYNC_ON_MIGRATE = True
146
+ ```
147
+
140
148
### Updating Views
141
149
142
150
Sometimes your models change and you need your Database Views to reflect the new
@@ -215,9 +223,9 @@ def customer_saved(sender, action=None, instance=None, **kwargs):
215
223
216
224
Postgres 9.4 and up allow materialized views to be refreshed concurrently, without blocking reads, as long as a
217
225
unique index exists on the materialized view. To enable concurrent refresh, specify the name of a column that can be
218
- used as a unique index on the materialized view. Unique index can be defined on more than one column of a materialized
219
- view. Once enabled, passing ` concurrently=True ` to the model's refresh method will result in postgres performing the
220
- refresh concurrently. (Note that the refresh method itself blocks until the refresh is complete; concurrent refresh is
226
+ used as a unique index on the materialized view. Unique index can be defined on more than one column of a materialized
227
+ view. Once enabled, passing ` concurrently=True ` to the model's refresh method will result in postgres performing the
228
+ refresh concurrently. (Note that the refresh method itself blocks until the refresh is complete; concurrent refresh is
221
229
most useful when materialized views are updated in another process or thread.)
222
230
223
231
Example:
@@ -245,7 +253,7 @@ def customer_saved(sender, action=None, instance=None, **kwargs):
245
253
246
254
#### Indexes
247
255
248
- As the materialized view isn't defined through the usual Django model fields, any indexes defined there won't be
256
+ As the materialized view isn't defined through the usual Django model fields, any indexes defined there won't be
249
257
created on the materialized view. Luckily Django provides a Meta option called ` indexes ` which can be used to add custom
250
258
indexes to models. ` pg_views ` supports defining indexes on materialized views using this option.
251
259
@@ -265,7 +273,7 @@ class PreferredCustomer(pg.MaterializedView):
265
273
266
274
name = models.CharField(max_length = 100 )
267
275
post_code = models.CharField(max_length = 20 , db_index = True )
268
-
276
+
269
277
class Meta :
270
278
managed = False # don't forget this, otherwise Django will think it's a regular model
271
279
indexes = [
@@ -277,7 +285,7 @@ class PreferredCustomer(pg.MaterializedView):
277
285
278
286
Materialized views can be created either with or without data. By default, they are created with data, however
279
287
` pg_views ` supports creating materialized views without data, by defining ` with_data = False ` for the
280
- ` pg.MaterializedView ` class. Such views then do not support querying until the first
288
+ ` pg.MaterializedView ` class. Such views then do not support querying until the first
281
289
refresh (raising ` django.db.utils.OperationalError ` ).
282
290
283
291
Example:
@@ -304,7 +312,7 @@ checks existing materialized view definition in the database (if the mat. view e
304
312
definition with the one currently defined in your ` pg.MaterializedView ` subclass. If the definition matches
305
313
exactly, the re-create of materialized view is skipped.
306
314
307
- This feature is enabled by setting the ` MATERIALIZED_VIEWS_CHECK_SQL_CHANGED ` in your Django settings to ` True ` ,
315
+ This feature is enabled by setting the ` MATERIALIZED_VIEWS_CHECK_SQL_CHANGED ` in your Django settings to ` True ` ,
308
316
which enables the feature when running ` migrate ` . The command ` sync_pgviews ` uses this setting as well,
309
317
however it also has switches ` --enable-materialized-views-check-sql-changed ` and
310
318
` --disable-materialized-views-check-sql-changed ` which override this setting for that command.
@@ -316,14 +324,14 @@ on change of the content but not the name.
316
324
317
325
### Schemas
318
326
319
- By default, the views will get created in the schema of the database, this is usually ` public ` .
320
- The package supports the database defining the schema in the settings by using
327
+ By default, the views will get created in the schema of the database, this is usually ` public ` .
328
+ The package supports the database defining the schema in the settings by using
321
329
options (` "OPTIONS": {"options": "-c search_path=custom_schema"} ` ).
322
330
323
331
The package ` django-tenants ` is supported as well, if used.
324
332
325
333
It is possible to define the schema explicitly for a view, if different from the default schema of the database, like
326
- this:
334
+ this:
327
335
328
336
``` python
329
337
from django_pgviews import view as pg
0 commit comments