[Cubicweb] [postgis] Enable Postgis extension the right way

Christophe de Vienne christophe at unlish.com
Mon Jun 8 16:17:27 CEST 2015


Hi,

Let's says it is a very expected missing feature in cubicweb, which is
to allow cubes to define post-creation & pre-init hooks.

There are no plan I know of to address this issue, but I guess a patch
would receive all the attention it deserves.

Cheers,

Christophe

Le 08/06/2015 15:11, Yann Vote a écrit :
> Hello list,
> 
> As a trainee at Logilab working with geospatial data in the datacat cube
> (https://www.cubicweb.org/project/cubicweb-datacat), I'm relying on the
> postgis cube.
> 
> However, bootstrapping is fairly problematic right now: Postgis
> extension is never enabled, I have to do it manually. I would expect the
> following steps to work flawlessly:
> 
> * create a new cube,
> * add a dependency on cubicweb-postgis,
> * defines a schema that hold Geometry or Geography attributes,
> * create an instance: tadam! I have some tables with geometry/geography
> columns in Postgres.
> 
> Currently this last step crash with an exception "execution of the sql
> schema failed, you should check your schema", and this is because
> Postgis extension has not been enabled before the tables are created.
> 
> Does this looks like a bug to everyone or just to me ?
> 
> There's a commented line in migration/precreate.py in the postgis cube,
> but to uncomment this line doesn't help. For some reason, precreate is
> executed *after* table creation (another bug ?)
> 
> So the only solution known to me right know is a monkeypatch suggested
> by Rémi:
> 
> ----
> from cubicweb.server.sources.native import NativeSQLSource
> 
> _init_creating = NativeSQLSource.init_creating
> 
> @monkeypatch(NativeSQLSource)
> def init_creating(self, cnxset=None):
>     # Enable Postgis first
>     if cnxset is None:
>         _cnxset = self.repo._get_cnxset()
>     else:
>         _cnxset = cnxset
>     _cnxset.cu.execute('CREATE EXTENSION IF NOT EXISTS postgis')
>     _cnxset.commit()
>     if cnxset is None:
>         _cnxset.cnxset_freed()
>         self.repo._free_cnxset(_cnxset)
>     # Now do the job
>     _init_creating(self, cnxset=cnxset)
> 
> ----
> 
> If I put this in site_cubicweb.py in postgis cube, then everything works
> as expected.
> 
> What do you think about it ? Is there a better way to enable Postgis
> than a monkeypatch ?
> 
> Also note that, as a side effect of using 'CREATE EXTENSION', the
> minimal required version for Postgres will be 9.1. I don't think this is
> a problem nowadays.
> 
> Thank you for your comments.
> 
> Regards.
> 
> Yann
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> https://lists.cubicweb.org/mailman/listinfo/cubicweb



More information about the Cubicweb mailing list