mirror of https://github.com/django/django.git
Refs #31196 -- Installed postgis_raster extension on PostGIS 3+.
This commit is contained in:
parent
cc70a0343e
commit
a6b4c07b6e
|
@ -50,6 +50,11 @@ process. An alternative is to use a migration operation in your project::
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
|
|
||||||
|
If you plan to use PostGIS raster functionality on PostGIS 3+, you should also
|
||||||
|
activate the ``postgis_raster`` extension. You can install the extension using
|
||||||
|
the :class:`~django.contrib.postgres.operations.CreateExtension` migration
|
||||||
|
operation, or directly by running ``CREATE EXTENSION postgis_raster;``.
|
||||||
|
|
||||||
GeoDjango does not currently leverage any `PostGIS topology functionality`__.
|
GeoDjango does not currently leverage any `PostGIS topology functionality`__.
|
||||||
If you plan to use those features at some point, you can also install the
|
If you plan to use those features at some point, you can also install the
|
||||||
``postgis_topology`` extension by issuing ``CREATE EXTENSION
|
``postgis_topology`` extension by issuing ``CREATE EXTENSION
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
from django.db import connection, migrations
|
||||||
|
|
||||||
|
if connection.features.supports_raster:
|
||||||
|
from django.contrib.postgres.operations import CreateExtension
|
||||||
|
|
||||||
|
pg_version = connection.ops.postgis_version_tuple()
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
# PostGIS 3+ requires postgis_raster extension.
|
||||||
|
if pg_version[1:] >= (3,):
|
||||||
|
operations = [
|
||||||
|
CreateExtension('postgis_raster'),
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
operations = []
|
||||||
|
else:
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
operations = []
|
|
@ -69,4 +69,7 @@ class Migration(migrations.Migration):
|
||||||
"""
|
"""
|
||||||
Used for gis-specific migration tests.
|
Used for gis-specific migration tests.
|
||||||
"""
|
"""
|
||||||
|
dependencies = [
|
||||||
|
('gis_migrations', '0001_setup_extensions'),
|
||||||
|
]
|
||||||
operations = ops
|
operations = ops
|
|
@ -36,8 +36,8 @@ class MigrateTests(TransactionTestCase):
|
||||||
self.assertTableExists("gis_migrations_family")
|
self.assertTableExists("gis_migrations_family")
|
||||||
if connection.features.supports_raster:
|
if connection.features.supports_raster:
|
||||||
self.assertTableExists("gis_migrations_heatmap")
|
self.assertTableExists("gis_migrations_heatmap")
|
||||||
# Unmigrate everything
|
# Unmigrate models.
|
||||||
call_command("migrate", "gis_migrations", "zero", verbosity=0)
|
call_command("migrate", "gis_migrations", "0001", verbosity=0)
|
||||||
# All tables are gone
|
# All tables are gone
|
||||||
self.assertTableNotExists("gis_migrations_neighborhood")
|
self.assertTableNotExists("gis_migrations_neighborhood")
|
||||||
self.assertTableNotExists("gis_migrations_household")
|
self.assertTableNotExists("gis_migrations_household")
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
from django.db import connection, migrations
|
||||||
|
|
||||||
|
if connection.features.supports_raster:
|
||||||
|
from django.contrib.postgres.operations import CreateExtension
|
||||||
|
|
||||||
|
pg_version = connection.ops.postgis_version_tuple()
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
# PostGIS 3+ requires postgis_raster extension.
|
||||||
|
if pg_version[1:] >= (3,):
|
||||||
|
operations = [
|
||||||
|
CreateExtension('postgis_raster'),
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
operations = []
|
||||||
|
else:
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
operations = []
|
|
@ -0,0 +1,47 @@
|
||||||
|
from django.contrib.gis.db import models
|
||||||
|
from django.db import migrations
|
||||||
|
from django.db.models import deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('rasterapp', '0001_setup_extensions'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RasterModel',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('rast', models.fields.RasterField(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
srid=4326,
|
||||||
|
verbose_name='A Verbose Raster Name',
|
||||||
|
)),
|
||||||
|
('rastprojected', models.fields.RasterField(
|
||||||
|
null=True,
|
||||||
|
srid=3086,
|
||||||
|
verbose_name='A Projected Raster Table',
|
||||||
|
)),
|
||||||
|
('geom', models.fields.PointField(null=True, srid=4326)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'required_db_features': ['supports_raster'],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RasterRelatedModel',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('rastermodel', models.ForeignKey(
|
||||||
|
on_delete=deletion.CASCADE,
|
||||||
|
to='rasterapp.rastermodel',
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'required_db_features': ['supports_raster'],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in New Issue