ryangooch
ryangooch

Reputation: 54

How do I drop geospatial metadata tables in SpatiaLite SQLite database?

SpatiaLite includes a function for standing up geospatial functionality in an existing SQLite database, namely, InitSpatialMetaData().

I'm seeking a similar method for tearing down geospatial metadata tables, and associated triggers and views, specifically as a way of implementing the downgrade() function in an alembic migration context for my database. Currently, the only way seems to be to specifically call out each piece of metadata by hand and remove them individually. Is this the best method or is there a better way to remove these metadata tables, etc?

Relevant Version Information:
OS: Debian Buster
SQLite: 3.27.2
SpatiaLite: 4.3

Code to Generate Spatial Tables (from GeoAlchemy2 SpatiaLite Tutorial):

from sqlalchemy import create_engine
from sqlalchemy.event import listen
from sqlalchemy.sql import select, func

def load_spatialite(dbapi_conn, connection_record):
    dbapi_conn.enable_load_extension(True)
    dbapi_conn.load_extension('/usr/lib/x86_64-linux-gnu/mod_spatialite.so')


engine = create_engine('sqlite:///gis.db', echo=True)
listen(engine, 'connect', load_spatialite)

conn.execute(select([func.InitSpatialMetaData()]))

tldr; Does SpatiaLite have an analog for the opposite of the function InitSpatialMetaData() ?

Upvotes: 0

Views: 361

Answers (1)

Sawan Meshram
Sawan Meshram

Reputation: 523

I didn't found any approach to remove all metadata tables.

But, you can do the most effective way to clean up SpatialTables that are no longer needed is

SELECT DropGeoTable(table_name);

This will have the same effect as a DROP TABLE IF EXISTS table_name;

This will removing any entries in the geometry_columns TABLE and the created TRIGGERs and removing any other dependencies (such as any registered SpatialViews)

Upvotes: 1

Related Questions