I’m connecting Prodigy to an existing Postgres cluster, and I’d like to be able to access the annotations created by users in other parts of our system, ideally in conjunction with other tables that already exist for joins, etc. Currently, the table names used by prodigy (dataset, example, link as I understand) are not yet used, but to be on the safe side I’d like to give Prodigy its own namespace, or somehow add a prefix to the table names (in case we ever need those table names to mean something else). Is there any way to do this?
The source of the database model (using
peewee) is included with Prodigy in
components/db.py, so you can check out how it is set up there. For 100% flexibility, you can also implement your own custom
Database class – see here for more details:
As long as the database methods exist and do the right thing, it's then fully up to you how you implement the logic and how the data is stored or retrieved.
Thanks @ines - I ended up finding a simple solution, it’s possible to set a default schema using the search_path setting:
_db = PostgresqlExtDatabase( params["database"], user=params["user"], password=params["password"], host=params["host"], options='-c search_path="prodigy"' # use schema to separate data from core app )
Tables are then created as
Where do you get
params from and how do you make sure that you use
_db and how does your
prodigy.json look like?
I'm having this
from playhouse.postgres_ext import PostgresqlExtDatabase from prodigy.components.db import Database class CustomDatabase(Database): def __init__(self, display_id="custom", display_name=None): super().__init__( PostgresqlExtDatabase( "postgres", user="postgres", password="pass", host="localhost", options='-c search_path="prodigy"', ), display_id, display_name, )
and point to
prodigy_db entry point. Then I have my
prodigy.json db to point to that entry point but I get the following error
AttributeError: type object 'CustomDatabase' has no attribute 'db_name'
which is odd since I extend
Turns out I have to point to an instance of
Database instead. So the following works by having entry point to
from playhouse.postgres_ext import PostgresqlExtDatabase from prodigy.components.db import Database _db = PostgresqlExtDatabase( "postgres", user="postgres", password="pass", host="localhost" ) db = Database(_db, "db", "DB")
However if I add the following to
then I get an error when running
peewee.ProgrammingError: no schema has been selected to create in LINE 1: CREATE TABLE IF NOT EXISTS "example" ("id" SERIAL NOT NULL P.
I've created a
prodigy schema in the database that I connect to...