Skip to content

Commit

Permalink
Use db.func.utcnow()
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed May 2, 2016
1 parent 9631476 commit 9844ed6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
7 changes: 3 additions & 4 deletions hasjob/models/board.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from pytz import timezone
from werkzeug import cached_property
from flask import url_for, Markup
Expand Down Expand Up @@ -42,21 +41,21 @@
board_auto_tag_table = db.Table('board_auto_tag', db.Model.metadata,
db.Column('tag_id', None, db.ForeignKey('tag.id'), primary_key=True),
db.Column('board_id', None, db.ForeignKey('board.id'), primary_key=True),
db.Column('created_at', db.DateTime, default=datetime.utcnow)
db.Column('created_at', db.DateTime, default=db.func.utcnow())
)


board_auto_jobtype_table = db.Table('board_auto_jobtype', db.Model.metadata,
db.Column('jobtype_id', None, db.ForeignKey('jobtype.id'), primary_key=True),
db.Column('board_id', None, db.ForeignKey('board.id'), primary_key=True),
db.Column('created_at', db.DateTime, default=datetime.utcnow)
db.Column('created_at', db.DateTime, default=db.func.utcnow())
)


board_auto_jobcategory_table = db.Table('board_auto_jobcategory', db.Model.metadata,
db.Column('jobcategory_id', None, db.ForeignKey('jobcategory.id'), primary_key=True),
db.Column('board_id', None, db.ForeignKey('board.id'), primary_key=True),
db.Column('created_at', db.DateTime, default=datetime.utcnow)
db.Column('created_at', db.DateTime, default=db.func.utcnow())
)


Expand Down
6 changes: 3 additions & 3 deletions hasjob/models/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
campaign_event_session_table = db.Table('campaign_event_session', db.Model.metadata,
db.Column('campaign_id', None, db.ForeignKey('campaign.id'), primary_key=True),
db.Column('event_session_id', None, db.ForeignKey('event_session.id'), primary_key=True, index=True),
db.Column('created_at', db.DateTime, default=datetime.utcnow)
db.Column('created_at', db.DateTime, default=db.func.utcnow())
)


Expand Down Expand Up @@ -384,7 +384,7 @@ class CampaignView(TimestampMixin, db.Model):
"""
__tablename__ = 'campaign_view'
#: Datetime when this activity happened (which is likely much before it was written to the database)
datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False, index=True)
datetime = db.Column(db.DateTime, default=db.func.utcnow(), nullable=False, index=True)
#: Campaign
campaign_id = db.Column(None, db.ForeignKey('campaign.id'), nullable=False, primary_key=True)
campaign = db.relationship(Campaign, backref=db.backref('views', lazy='dynamic',
Expand Down Expand Up @@ -417,7 +417,7 @@ class CampaignAnonView(TimestampMixin, db.Model):
"""
__tablename__ = 'campaign_anon_view'
#: Datetime when this activity happened (which is likely much before it was written to the database)
datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False, index=True)
datetime = db.Column(db.DateTime, default=db.func.utcnow(), nullable=False, index=True)
#: Campaign
campaign_id = db.Column(None, db.ForeignKey('campaign.id'), nullable=False, primary_key=True)
campaign = db.relationship(Campaign, backref=db.backref('anonviews', lazy='dynamic',
Expand Down
10 changes: 5 additions & 5 deletions hasjob/models/jobpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def number_abbreviate(number, indian=False):
starred_job_table = db.Table('starred_job', db.Model.metadata,
db.Column('user_id', None, db.ForeignKey('user.id'), primary_key=True),
db.Column('jobpost_id', None, db.ForeignKey('jobpost.id'), primary_key=True),
db.Column('created_at', db.DateTime, default=datetime.utcnow, nullable=False),
db.Column('created_at', db.DateTime, default=db.func.utcnow(), nullable=False),
)


Expand All @@ -72,7 +72,7 @@ class JobPost(BaseMixin, db.Model):
user = db.relationship(User, primaryjoin=user_id == User.id, backref=db.backref('jobposts', lazy='dynamic'))

hashid = db.Column(db.String(5), nullable=False, unique=True)
datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False, index=True) # Published
datetime = db.Column(db.DateTime, default=db.func.utcnow(), nullable=False, index=True) # Published
closed_datetime = db.Column(db.DateTime, nullable=True) # If withdrawn or rejected
# Pinned on the home page. Boards use the BoardJobPost.pinned column
sticky = db.Column(db.Boolean, nullable=False, default=False)
Expand Down Expand Up @@ -677,7 +677,7 @@ class AnonJobView(db.Model):
anon_user_id = db.Column(None, db.ForeignKey('anon_user.id'), primary_key=True, index=True)
anon_user = db.relationship(AnonUser)
#: Timestamp
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False, index=True)
created_at = db.Column(db.DateTime, default=db.func.utcnow(), nullable=False, index=True)

@classmethod
def get(cls, jobpost, anon_user):
Expand All @@ -687,7 +687,7 @@ def get(cls, jobpost, anon_user):
class JobImpression(TimestampMixin, db.Model):
__tablename__ = 'job_impression'
#: Datetime when this activity happened (which is likely much before it was written to the database)
datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False, index=True)
datetime = db.Column(db.DateTime, default=db.func.utcnow(), nullable=False, index=True)
#: Job post that was impressed
jobpost_id = db.Column(None, db.ForeignKey('jobpost.id'), primary_key=True)
jobpost = db.relationship(JobPost)
Expand All @@ -713,7 +713,7 @@ def get_by_ids(cls, jobpost_id, event_session_id):
class JobViewSession(TimestampMixin, db.Model):
__tablename__ = 'job_view_session'
#: Datetime indicates the time, impression has made
datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False, index=True)
datetime = db.Column(db.DateTime, default=db.func.utcnow(), nullable=False, index=True)
#: Job post that was impressed
#: Event session in which jobpost was viewed
#: This takes precedence as we'll be loading all instances
Expand Down
3 changes: 1 addition & 2 deletions hasjob/models/jobpostreport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from . import db
from .user import User
from .jobpost import JobPost
Expand All @@ -16,7 +15,7 @@ class JobPostReport(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=True)
user = db.relationship(User)
datetime = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
datetime = db.Column(db.DateTime, default=db.func.utcnow(), nullable=False)
post_id = db.Column(db.Integer, db.ForeignKey('jobpost.id'), nullable=False)
post = db.relation(JobPost, primaryjoin=post_id == JobPost.id,
backref=db.backref('flags', cascade='all, delete-orphan'))
Expand Down
2 changes: 1 addition & 1 deletion hasjob/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class UserActiveAt(db.Model):
per user per active period.
"""
__tablename__ = 'user_active_at'
active_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, primary_key=True)
active_at = db.Column(db.DateTime, nullable=False, default=db.func.utcnow(), primary_key=True)
user_id = db.Column(None, db.ForeignKey('user.id'), nullable=False, primary_key=True, index=True)
user = db.relationship(User)
board_id = db.Column(None, db.ForeignKey('board.id'), nullable=True, index=True)
Expand Down

0 comments on commit 9844ed6

Please sign in to comment.