Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Pl/Python PostgreSQL procedures with Travis CI?

I'm trying to set up CI for some PL/Python PostgreSQL procedures in Travis CI.

I've tried several ways:
1) With the legacy infrastructure I've tried to just assume, that PL/Python is already installed, but it had not succeed:

The command "psql -U postgres -c 'CREATE EXTENSION plpythonu;'" exited with 1.
0.01s$ psql -U postgres -d test -c 'CREATE LANGUAGE plpythonu;'
ERROR:  could not access file "$libdir/plpython2": No such file or directory  

2) Have tried to add sudo apt-get update && sudo apt-get -y install postgresql-plpython-9.4 commands in the beginning. And it was also failed, because this command initiated replacement of PostgresSQL 9.4, that comes already installed in the Travis environment.

Travis build.

3) Also tried to use container-based infrastructure with this lines in the config:

addons:
  postgresql: "9.4"
  apt:
    packages:
      - postgresql-plpython-9.4

No success too.

What is the good way to test PL/Python procedure in Travis CI?

like image 449
Gill Bates Avatar asked Jul 30 '15 07:07

Gill Bates


3 Answers

I was able to get the python-tempo build working with the following .travis.yml:

sudo: required
language: python
before_install:
  - sudo apt-get -qq update
  - sudo /etc/init.d/postgresql stop
  - sudo apt-get install -y postgresql-9.4
  - sudo apt-get install -y postgresql-contrib-9.4 postgresql-plpython-9.4
  - sudo -u postgres createdb test
  - sudo -u postgres createlang plpython2u test
  - sudo pip install jinja2
script:
  - >
      sudo -u postgres psql -d test -c 'CREATE OR REPLACE FUNCTION py_test()
                                   RETURNS void LANGUAGE plpython2u AS $$
                                     import jinja2
                                   $$;'
  - sudo -u postgres psql -d test -c 'SELECT py_test();'

Your legacy configuration attempts had a variety of issues including not stopping the existing PostgreSQL 9.1 instance before installing 9.4 and not specifying the plpython language properly. I believe some commands were also not being run as the correct user. All of the issues are resolved by the above configuration. There may be ways in which this configuration can be improved, but I stopped once I got it working.

The container-based configuration won't work because postgresql-plpython-9.4 is not currently in the whitelist of pre-approved packages. However, postgresql-plpython-9.5 is, so if you want to migrate to a container-based configuration, you can either try following the package approval process for postgresql-plpython-9.4 or wait for the GA release of PostgreSQL 9.5 and try migrating then.

like image 185
heenenee Avatar answered Nov 15 '22 01:11

heenenee


Converting my previous comments to an answer now that it has been confirmed...

As documented in the Travis docs, the right way to install this is to update your dependencies at the before_install stage (much like option 2 in your list).

The only problem appears to be that you did not stop Postgres before the upgrade.

like image 4
Peter Brittain Avatar answered Nov 15 '22 00:11

Peter Brittain


I don't know the details exactly, but, if you put the files in the right place, you can call it from the procedure itself

import fileName.className

or

import methodName from fileName.className

Edit: I looked it up, just put it in the same directory as the program you're running (cmd, idle, ect.) and call it, or put it in a folder and add the folder name to the code

eg.

import folder/fileName.ClassName
like image 2
Bailey Avatar answered Nov 15 '22 01:11

Bailey