[How to use] SRIDs with multitenancy
### Describe the problem
We are using multitenancy in our database with postgis extension, geoalchemy2 types and sqlalchemy ORM.
There is a shared schema with a table that contains information about the tenants like the schema name and their SRIDs. Each schema looks the same structurally, so they have the same tables, types, columns in the tables. The only difference where this is problematic is when we define the ORM tables that have Geometry columns.
What would be the best practice in this case? Should we just set all SRIDs to -1 and not check them, or use some dynamic way to define these tables so they would use their tenant specific SRID, use CheckConstraints to disallow inserting geometries with non-matching SRID, wrap the insert/updates with ST_SetSRID/ST_Transform?
### Show what you tried to do.
```Python
from sqlalchemy import Integer
from geoalchemy2 import Geometry
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass
class Object(Base):
__tablename__ = "objects"
id = Column(Integer, primary_key=True)
origin = Column(
Geometry(
"POINTZ",
32632, # should this be set to -1?
3,
from_text="ST_GeomFromEWKT",
name="geometry",
nullable=False,
spatial_index=True,
),
nullable=False,
)
```
### Describe what you expected.
I'd like to have different SRID in different tenants based on the main.tenants table records
### Error
```Python traceback
```
### Additional context
_No response_
### GeoAlchemy 2 Version in Use
0.17.1
关闭于 2025-05-26 3 条评论