
# revision identifiers, used by Alembic.
revision = '4ef20b76cab1'
down_revision = '55004b0f00d6'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.execute("CREATE EXTENSION postgis;")
    op.execute("CREATE EXTENSION postgis_topology;")

def downgrade():
    op.execute("DROP EXTENSION postgis_topology;")
    op.execute("DROP EXTENSION postgis;")


# revision identifiers, used by Alembic.
revision = '4ef20b76cab1'
down_revision = '55004b0f00d6'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.execute("CREATE EXTENSION IF NOT EXISTS postgis;")
    op.execute("CREATE EXTENSION IF NOT EXISTS postgis_topology;")

def downgrade():
    op.execute("DROP EXTENSION IF EXISTS postgis_topology;")
    op.execute("DROP EXTENSION IF EXISTS postgis;")

Add extra code to PostGIS migration to only create extensions if they're not already there. Drop on rollback only if extensions exist.
Add extra code to PostGIS migration to only create extensions if they're not already there. Drop on rollback only if extensions exist.

  
  # revision identifiers, used by Alembic.
  revision = '4ef20b76cab1'
  down_revision = '55004b0f00d6'
  
  from alembic import op
  import sqlalchemy as sa
  
  
  def upgrade():
-     op.execute("CREATE EXTENSION postgis;")
+     op.execute("CREATE EXTENSION IF NOT EXISTS postgis;")
-     op.execute("CREATE EXTENSION postgis_topology;")
+     op.execute("CREATE EXTENSION IF NOT EXISTS postgis_topology;")
  
  def downgrade():
-     op.execute("DROP EXTENSION postgis_topology;")
+     op.execute("DROP EXTENSION IF EXISTS postgis_topology;")
-     op.execute("DROP EXTENSION postgis;")
+     op.execute("DROP EXTENSION IF EXISTS postgis;")
  
Add extra code to PostGIS migration to only create extensions if they're not already there. Drop on rollback only if extensions exist.
## Code Before:

# revision identifiers, used by Alembic.
revision = '4ef20b76cab1'
down_revision = '55004b0f00d6'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.execute("CREATE EXTENSION postgis;")
    op.execute("CREATE EXTENSION postgis_topology;")

def downgrade():
    op.execute("DROP EXTENSION postgis_topology;")
    op.execute("DROP EXTENSION postgis;")

## Instruction:
Add extra code to PostGIS migration to only create extensions if they're not already there. Drop on rollback only if extensions exist.
## Code After:

# revision identifiers, used by Alembic.
revision = '4ef20b76cab1'
down_revision = '55004b0f00d6'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.execute("CREATE EXTENSION IF NOT EXISTS postgis;")
    op.execute("CREATE EXTENSION IF NOT EXISTS postgis_topology;")

def downgrade():
    op.execute("DROP EXTENSION IF EXISTS postgis_topology;")
    op.execute("DROP EXTENSION IF EXISTS postgis;")
