2015-01-13 04:20:40 +08:00
|
|
|
from django.db.backends.base.base import NO_DB_ALIAS
|
2017-06-02 01:23:48 +08:00
|
|
|
from django.db.backends.postgresql.base import (
|
|
|
|
DatabaseWrapper as Psycopg2DatabaseWrapper,
|
|
|
|
)
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2015-01-13 04:20:40 +08:00
|
|
|
from .features import DatabaseFeatures
|
|
|
|
from .introspection import PostGISIntrospection
|
|
|
|
from .operations import PostGISOperations
|
|
|
|
from .schema import PostGISSchemaEditor
|
2014-08-18 01:06:25 +08:00
|
|
|
|
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
class DatabaseWrapper(Psycopg2DatabaseWrapper):
|
2014-09-26 01:59:03 +08:00
|
|
|
SchemaEditorClass = PostGISSchemaEditor
|
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(*args, **kwargs)
|
2013-11-09 18:21:53 +08:00
|
|
|
if kwargs.get('alias', '') != NO_DB_ALIAS:
|
2014-08-18 01:06:25 +08:00
|
|
|
self.features = DatabaseFeatures(self)
|
2013-11-09 18:21:53 +08:00
|
|
|
self.ops = PostGISOperations(self)
|
|
|
|
self.introspection = PostGISIntrospection(self)
|
2014-12-06 22:11:20 +08:00
|
|
|
|
|
|
|
def prepare_database(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
super().prepare_database()
|
2015-03-17 23:16:50 +08:00
|
|
|
# Check that postgis extension is installed.
|
|
|
|
with self.cursor() as cursor:
|
|
|
|
cursor.execute("CREATE EXTENSION IF NOT EXISTS postgis")
|