What’s the best way to do primary keys/constraints...
# ask-community
What’s the best way to do primary keys/constraints/etc for dagster created tables? So we have made a simple iomanager for postgres, and are using pandas/sqlalchemy. Right now it simply selects or inserts based on the model name and the partition information Is it best practice to put the constraints within the iomanager? Or within the asset? Or create manually each table as we want it, and have dagster just populate it?
hi @Austin! I'd recommend putting this code in the IOManager, just for ease of maintenance. One pattern that I'd recommend is putting the desired primary keys etc in the metadata of the asset, then reading that inside the body of the IOManager to decide how to create the table, i.e.:
Copy code
@asset(metadata={"primary_key": ...})
def foo():
then in the IOManager:
Copy code
def handle_output(self, context, obj):
    primary_key = context.metadata.get("primary_key")