I need to reread your code a few more times Mike. But I just realized that the versioning is an example (almost a recipe), but it's not something that ships with the SA package, yes? Meaning that I'll have to copy much of the history_meta.py <https://bitbucket.org/zzzeek/sqlalchemy/src/f7b957b589207cae98b6feec63be84ee6423c3ca/examples/versioned_history/history_meta.py> code over into my own meta.py file?
Jens On Saturday, October 28, 2017 at 9:25:22 AM UTC+10, Mike Bayer wrote: > > > > On Fri, Oct 27, 2017 at 4:39 PM, <jens.t...@gmail.com <javascript:>> > wrote: > >> Thank you Mike! >> >> Yes, indeed you are right and I referred to Single Table Inheritance >> <http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#single-table-inheritance>! >> >> I would like to version just one subclass, i.e. a subset of that single >> table, and it sounds like that will work (source code link >> <https://bitbucket.org/zzzeek/sqlalchemy/src/f7b957b589207cae98b6feec63be84ee6423c3ca/examples/versioned_history/test_versioning.py?at=master&fileviewer=file-view-default#test_versioning.py-449>, >> >> though that example versions the base class). Great 👌 >> >> And if I wanted to walk the versions of a particular row, how would I do >> that? Suppose versioning in the example >> <http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#single-table-inheritance> >> >> on Single Table Inheritance: >> >> # Versioned subclass. >> class Engineer(Versioned, Employee): >> engineer_info = Column(String(50)) >> >> # Retrieve a single Engineer object/row. >> eng = session.query(Engineer).filter(Engineer.id==N).one_or_none() >> # eng.version would give me the current version of the object/row. >> # How can I iterate over previous versions of the object/row? >> >> If I read the history_meta.py >> <https://bitbucket.org/zzzeek/sqlalchemy/src/f7b957b589207cae98b6feec63be84ee6423c3ca/examples/versioned_history/history_meta.py?fileviewer=file-view-default> >> in >> the example correctly, then versioned objects have a version >> <https://bitbucket.org/zzzeek/sqlalchemy/src/f7b957b589207cae98b6feec63be84ee6423c3ca/examples/versioned_history/history_meta.py?at=master&fileviewer=file-view-default#history_meta.py-88> >> and >> a changed >> <https://bitbucket.org/zzzeek/sqlalchemy/src/f7b957b589207cae98b6feec63be84ee6423c3ca/examples/versioned_history/history_meta.py?at=master&fileviewer=file-view-default#history_meta.py-95> >> property, >> but no property that is an iterator over previous versions. I'd have to >> query a history table manually? >> > > > the history table is mapped to a class attached to the versioned class: > > SomeClassHistory = SomeClass.__history_mapper__.class_ > > eq_( > sess.query(SomeClassHistory).filter( > SomeClassHistory.version == 1).all(), > [SomeClassHistory(version=1, name='sc1')] > ) > > > you can add any kind of accessor on the versioned class to return that for > you, like: > > def history_cls(cls): > > return cls.__history_mapper__.class_ > > > hist = sess.query(MyClass.history_cls) > > or whatever you'd like. Or you can set this up within the history_meta > routine > itself, I'm not sure why I made it attach the "mapper" like that and not the > class directly. > > > >> Would that be something like >> >> SELECT * FROM EngineerHistory WHERE id=N SORT BY version; -- >> EmployeeHistory?? >> >> Cheers! >> >> >> On Saturday, October 28, 2017 at 3:50:08 AM UTC+10, Mike Bayer wrote: >>> >>> On Thu, Oct 26, 2017 at 9:35 PM, <jens.t...@gmail.com> wrote: >>> > Hello, >>> > >>> > I'm looking for a way track changes to table rows, very much like >>> described >>> > in this Stackoverflow question. >>> > >>> > SA supports versioning objects as described in the documentation: >>> > >>> http://docs.sqlalchemy.org/en/latest/orm/examples.html#versioning-objects >>> > Does this approach work for inherited classes as well? >>> >>> yes it does, there should be some coverage for joined inheritance in the >>> tests. >>> >>> >>> > I mean: can I version >>> > a class which doesn't have a table but is a subclass of a joined table >>> > inheritance? >>> >>> that would be single table inheritance if it doesn't have a table. >>> the test suite has both a multilevel-joined test and a single >>> inheritance test, doesn't seem to have tested joined inh to single but >>> it's likely it will just work if you try it out. >>> >>> > Or will I need to version the base class which has the table >>> > associated (something I'd like to avoid because I'd version much of >>> what >>> > would not need versioning). >>> >>> I'm not sure if the versioning example tries this but the Versioned >>> mixin can be placed just on the class you care about versioning, and >>> it's likely it will just take effect when that class is present. The >>> Versioned mixin should be able to deal with each class independently >>> of all the rest. You'd need to try it out and see what it does. >>> >>> >>> >>> > >>> > Then there is SA Continuum, which seems more flexible but perhaps a >>> little >>> > too much for my needs. >>> >>> It's possible that Continuum was based on this example in the first >>> place but I would never remember if that detail is real or just made >>> up by my imagination. >>> >>> >>> > With projects like Continuum I'm always a bit worried >>> > about support and maintenance—any experiences with it? Does that >>> support >>> > table inheritance? >>> >>> You could reach out to its maintainer (the username that posts it to >>> pypi, and /or the user that seems to have the most commits). If you >>> don't get a reply, that's a clue :) >>> >>> >>> >>> >>> > >>> > Thanks! >>> > Jens >>> > >>> > -- >>> > SQLAlchemy - >>> > The Python SQL Toolkit and Object Relational Mapper >>> > >>> > http://www.sqlalchemy.org/ >>> > >>> > To post example code, please provide an MCVE: Minimal, Complete, and >>> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full >>> > description. >>> > --- >>> > You received this message because you are subscribed to the Google >>> Groups >>> > "sqlalchemy" group. >>> > To unsubscribe from this group and stop receiving emails from it, send >>> an >>> > email to sqlalchemy+...@googlegroups.com. >>> > To post to this group, send email to sqlal...@googlegroups.com. >>> > Visit this group at https://groups.google.com/group/sqlalchemy. >>> > For more options, visit https://groups.google.com/d/optout. >>> >> -- >> SQLAlchemy - >> The Python SQL Toolkit and Object Relational Mapper >> >> http://www.sqlalchemy.org/ >> >> To post example code, please provide an MCVE: Minimal, Complete, and >> Verifiable Example. See http://stackoverflow.com/help/mcve for a full >> description. >> --- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sqlalchemy+...@googlegroups.com <javascript:>. >> To post to this group, send email to sqlal...@googlegroups.com >> <javascript:>. >> Visit this group at https://groups.google.com/group/sqlalchemy. >> For more options, visit https://groups.google.com/d/optout. >> > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.