<div dir="ltr">Hi Jay,<div><br></div><div><br></div><div>When I started working around unique keys, I tried to use deleted_at column. so answer about why we don't use deleted_at column you could read in Devananda's comment on my patch <a href="https://review.openstack.org/#/c/16162/">https://review.openstack.org/#/c/16162/</a> .<br>
</div><div><br></div><div>Also I should mention that this is really huge change and it will take a lot of time to implement it.  E.g. I started working around unique keys at begin of the Grizzly and we still didn't finish this work in OpenStack projects (except Nova where we have last the patch on review <a href="https://review.openstack.org/#/c/36880/">https://review.openstack.org/#/c/36880/</a>).<br>
</div><div><br></div><div><br></div><div>Best regards,</div><div>Boris Pavlovic</div><div>--</div><div>Mirantis Inc. </div><div> </div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Aug 19, 2013 at 11:39 AM, Jay Pipes <span dir="ltr"><<a href="mailto:jaypipes@gmail.com" target="_blank">jaypipes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm throwing this up here to get some feedback on something that's always bugged me about the model base used in many of the projects.<br>
<br>
There's a mixin class that looks like so:<br>
<br>
class SoftDeleteMixin(object):<br>
    deleted_at = Column(DateTime)<br>
    deleted = Column(Integer, default=0)<br>
<br>
    def soft_delete(self, session=None):<br>
        """Mark this object as deleted."""<br>
        self.deleted = <a href="http://self.id" target="_blank">self.id</a><br>
        self.deleted_at = timeutils.utcnow()<br>
        self.save(session=session)<br>
<br>
Once mixed in to a concrete model class, the primary join is typically modified to include the deleted column, like so:<br>
<br>
class ComputeNode(BASE, NovaBase):<br>
    <snip>...<br>
    service = relationship(Service,<br>
                           backref=backref('compute_node'<u></u>),<br>
                           foreign_keys=service_id,<br>
                           primaryjoin='and_('<br>
                                'ComputeNode.service_id == Service.id,'<br>
                                'ComputeNode.deleted == 0)')<br>
<br>
My proposal is to get rid of the deleted column in the SoftDeleteMixin class entirely, as it is redundant with the deleted_at column. Instead of doing a join condition on deleted == 0, one would instead just do the join condition on deleted_at is None, which translates to the SQL: AND deleted_at IS NULL.<br>

<br>
There isn't much of a performance benefit -- you're only reducing the row size by 4 bytes. But, you'd remove the redundant data from all the tables, which would make the normal form freaks like myself happy ;)<br>

<br>
Thoughts?<br>
<br>
-jay<br>
<br>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
</blockquote></div><br></div>