pyeventsourcing / eventsourcing

A library for event sourcing in Python.
https://eventsourcing.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.41k stars 129 forks source link

Postgres schema change possibility #237

Closed marcinmigda-talentalpha closed 2 years ago

marcinmigda-talentalpha commented 2 years ago

It would be nice to be able to choose a schema other than the default one for Postgres eventstore. Are you planning to add support for it?

johnbywater commented 2 years ago

Hi @marcinmigda-talentalpha! Thanks for your question, sorry for the delay in responding. There aren't currently any plans to do this, but I'm open to the idea. I suppose the limitation is that the SQL in the recorders depends on the schema. How would you like support for an alternative schema to work? Did you want something in particular from an alternative scheme? Is there something you would like to do that you currently can't? Just curious about your thoughts, experience, and requirements. Hope to hear more about this from you soon!

teves-castro commented 2 years ago

I believe the question was around using a POSTGRES schema (as a namespace concept) other than public (the default one) not in changing how event data is stored. I was wondering the same today, as the db instance we are using is also used for something other than event store, and we would like to keep the two sets of tables segregated.

johnbywater commented 2 years ago

Thank you for clarifying this. How would you like this to work? Specify the schema in an environment variable, and then have the tables created in that schema? Would that work? Sorry for my misunderstanding.

teves-castro commented 2 years ago

I'm still quite new to using this library so I'm still learning the entry points for its functionality, but that being said having an environment variable seems like a reasonable choice to indicate which Schema the tables should be created in.

johnbywater commented 2 years ago

@marcinmigda-talentalpha @teves-castro

I added this today. Thanks for raising and explaining. Sorry for delay. Let me know what you think?

"The optional environment variable POSTGRES_SCHEMA may be used to configure the table names used by the recorders to be qualified with a schema name. Setting this will create tables in a specific PostgreSQL schema. See the PostgreSQL Schemas documentation for more information about creating and using PostgreSQL schemas safely."

See docs: https://eventsourcing.readthedocs.io/en/latest/topics/persistence.html#postgresql

Changeset: https://github.com/pyeventsourcing/eventsourcing/commit/0967e025ca819335e7b154320c841bc6041cad18