Skip to content

Column server_default clause erroneously copied to _version table #252

Open

Description

@ms-ai

The _version table for this class produces the wrong modified_at timestamp. The first time an entry is added, it has the correct date, but the second insert, has the datetime of the first, and the first gets the datetime of the second.
I think the reason is that the _version table structure has the entire datetime definition with the default copied, instead of just being an empty datetime field. I am using

MySQL     8.0.21
SQLAlchemy-Continuum 1.3.11
SQLAlchemy-Utils     0.36.8

I believe this is similar to #47

Let's say we have this class:

class Rig(db.Model, VersioningMixin):
    __tablename__ = 'rig'

    id = db.Column( db.Integer, primary_key=True)
    name = db.Column( db.String(255), nullable=False)
    instance_label = db.synonym('name')
    parent_id = db.Column( db.Integer, db.ForeignKey('rig.id'), server_default='1', nullable=False )
    modified_at = db.Column( db.DateTime, server_default=db.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"), nullable=False )

Then after 1 Insert and 1 Update, the _version table is this:

SELECT * FROM `rig_version`

id	name	parent_id	modified_at	transaction_id	end_transaction_id	operation_type	
2	beh	1	2020-09-06 18:26:14		1	      2	               0	
2	beh-v2	1	2020-09-06 18:25:40		2	    NULL	       1	

Activity

  1. changed the title [-]Column server_default clause erroneously copied to history table[/-] [+]Column server_default clause erroneously copied to _version table[/+] on Sep 6, 2020
  2. added
    pinned
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pinned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions