﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24918	Using SchemaEditor to create materialized views in PostgreSQL	Andreas Madsack	nobody	"We use the schemaeditor to create not only tables in the database, but also materialized views.
This is working for us on Django 1.7, but we use the somehow private API of Django migrations.

Our solution:

* Subclassing the Postgresql-DatabaseWrapper to change the schema_editor to our own:

{{{
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper as PGDatabaseWrapper

class DatabaseWrapper(PGDatabaseWrapper):
    def __init__(self, *args, **kwargs):
        self.SchemaEditorClass = OurDatabaseSchemaEditor
        super(DatabaseWrapper, self).__init__(*args, **kwargs)
}}}

* in ''OurDatabaseSchemaEditor'' we overwrite every action method we need changed.
For example:

{{{
    def create_model(self, model):
        if check_if_materialized(model):
            from materialized.helpers import create_model
            create_model(model)
            return
        super(OurDatabaseSchemaEditor, self).create_model(model)
}}}

The same way for ''delete_model'', ''add_field'', ''alter_field'', ''remove_field'', ...

Purpose of this ticket is the discussion about custom changes to schemaeditor methods like we do.
**Is this the way to go or should it be done in another way?**

I'm in Cardiff at the sprints today and on freenode as mfandreas. 
"	New feature	closed	Migrations	1.8	Normal	wontfix	postgresql, schemaeditor		Unreviewed	0	0	0	0	0	0
