SectorLabs/django-postgres-extra

Composite primary keys?

onecrayon opened this issue · 3 comments

We are currently evaluating partitioned tables in Postgres for use with our logging database backing a Django application (large volume of log entries that are typically filtered by date, but we only keep six months worth of data). However, one of our requirements is being able to filter log entries out based on user access (users can share access with other users), and doing a many-to-many lookup table alongside the partitioned table seemed like a sensible approach to support this.

However, if we are understanding the Postgres documentation correctly, in order to make foreign key relationships into a partitioned table, the table needs to have a composite primary key that includes the date column used to establish the partition ranges. This is problematic because Django does not support composite primary keys.

Are there any known workarounds to allow this with django-postgres-extra?

I reviewed the documentation and checked other issues, but didn't find anything specifically relevant to this (#178 was the closest related issue I located), so any guidance is appreciated!

Django does not support composite primary keys. You can create them manually in a migration using migrations.RunSQL.

@onecrayon Were you able to implement partitioning? I'm facing the same issue but getting error #210