toluaina / pgsync

Postgres to Elasticsearch/OpenSearch sync
https://pgsync.com
MIT License
1.18k stars 182 forks source link

Is there support currently for polymorphic relationships? #283

Open PorterK opened 2 years ago

PorterK commented 2 years ago

For example, I have inventory space that can be owned by an individual or an organization, the table looks something like this:

space_id owner_type owner_id
1234 user 5554
1235 organization 5554

Is this type of relationship currently supported in pgsync?

If not I would propose adding a scope parameter. Something like below would work but could be handled by separate fields for the column name & the column value.

"children": [
   {
      "table": "user"
      "through_tables": [
         {
            "table": "inventory_space_map",
            "scope": {
               "owner_type": "user",
            },
            "foreignKey": "owner_id",
         }
      ]
   }
]

I looked through the open & closed issues for polymorphic, scope, etc but didn't find anything.

I don't write python very often but would be willing to help out to get this feature added if it's something worth adding.

toluaina commented 2 years ago
toluaina commented 2 years ago

PS: I do like the scope and idea of including this in the schema. I just wondered if there was already an existing solution before adding more code which is increasing in complexity these days.

PorterK commented 2 years ago
  • polymorphic tables are not supported in the schema.
  • However, I think this is something that can be acheived with the plugin.
  • This is effectively applying a WHERE clause on the result set.
  • There is a plugins example described here and I am happy to write one for your use case if you want.

I would appreciate if you could write a plugin - is there a repository of "supported" plugins to add it to maybe?

toluaina commented 2 years ago

I'll be honest. I don't understand enough of your use case to write a plugin. Do you have a repo somewhere I can contribute to?