diff --git a/migrations/versions/f391490d3fa9_alter_table_add_created_at_and_updated_.py b/migrations/versions/f391490d3fa9_alter_table_add_created_at_and_updated_.py new file mode 100644 index 0000000..3bd9213 --- /dev/null +++ b/migrations/versions/f391490d3fa9_alter_table_add_created_at_and_updated_.py @@ -0,0 +1,34 @@ +"""alter_table_add_created_at_and_updated_at + +Revision ID: f391490d3fa9 +Revises: 13604de200ef +Create Date: 2023-08-24 10:29:23.485033 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'f391490d3fa9' +down_revision = '13604de200ef' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('users', schema=None) as batch_op: + batch_op.add_column(sa.Column('created_at', sa.DateTime(), nullable=True)) + batch_op.add_column(sa.Column('updated_at', sa.DateTime(), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('users', schema=None) as batch_op: + batch_op.drop_column('updated_at') + batch_op.drop_column('created_at') + + # ### end Alembic commands ### diff --git a/src/models/User.py b/src/models/User.py index 85a5342..c02815a 100644 --- a/src/models/User.py +++ b/src/models/User.py @@ -10,6 +10,8 @@ class User(db.Model): password = db.Column(db.String(255)) balance = db.Column(db.Float, default=0) status = db.Column(db.String(255), default='INACTIVE') + created_at = db.Column(db.DateTime, default=db.func.now()) + updated_at = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now()) tickets = db.relationship('Ticket', back_populates='user') transactions = db.relationship('Transaction', back_populates='user') def __init__(self, email, name, role, password, status, balance =0): @@ -19,6 +21,8 @@ def __init__(self, email, name, role, password, status, balance =0): self.password = password self.balance = balance self.status = status + self.created_at = db.func.now() + self.updated_at = db.func.now() # def __repr__(self): # return '' % self.name \ No newline at end of file