mercredi 28 août 2019

Enable PSQL hstore extension in Django test db during CI

Context

Some steps of my Continuos Integration procedure are:

  • start Postgres docker container
  • run Django tests

When manage.py test --noinput command is runned it:

  • creates a new test_xxx database (drop if exists)
  • runs the founded migrations against it
  • runs the founded set of tests

Into the tests that need to fetch data from the database are configured a set of fixtures that will be loaded automatically in the test_xxx db.

Problem

Some migrations need the Postgres hstore extension, in fact i'm getting this error:

django.db.utils.ProgrammingError: type "hstore" does not exist

Question

How can i enable the hstore extension?

In development and other envs it was set up with CREATE EXTENSION IF NOT EXISTS hstore; but here can't be manually set.

Is possible to define a "migration zero" with the hstore creation? Anyway i don't like this approach.

I've found that it should be theorically possible to listen to the pre_migrate signal, and it will be the sweet spot, but before make things more complex i'd like to search for an easier, more direct solution.

Aucun commentaire:

Enregistrer un commentaire