Skip to content

Commit

Permalink
Merge pull request #38 from cf15-t5/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
lutfianRhdn authored Aug 24, 2023
2 parents 592a9f0 + 18c9788 commit 33c0421
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 ###
4 changes: 4 additions & 0 deletions src/models/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 '<User %r>' % self.name

0 comments on commit 33c0421

Please sign in to comment.