Skip to content

Commit

Permalink
db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 4, 2015
1 parent bcbe882 commit 1e064fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion dataserv/Farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def ping(self, before_commit_callback=None):
farmer.last_seen = ping_time
# if the farmer has been online in the last ONLINE_TIME seconds
# then we can update their uptime statistic
if farmer.uptime == None:
farmer.uptime = timedelta(seconds=0)
if delta_ping <= timedelta(minutes=app.config["ONLINE_TIME"]):
farmer.uptime += delta_ping
else:
Expand Down Expand Up @@ -166,7 +168,10 @@ def calculate_uptime(self):
return 100.0

if delta_ping <= timedelta(minutes=app.config["ONLINE_TIME"]):
farmer_uptime = farmer.uptime + delta_ping
if farmer.uptime == None:
farmer_uptime = delta_ping
else:
farmer_uptime = farmer.uptime + delta_ping
else:
farmer_uptime = farmer.uptime + timedelta(
minutes=app.config["ONLINE_TIME"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""empty message
Revision ID: 1c9790acd60
Revision ID: 1c91ee99cac
Revises: 14d4ac0f0f1
Create Date: 2015-11-02 02:58:57.959981
Create Date: 2015-11-04 07:23:19.991912
"""

# revision identifiers, used by Alembic.
revision = '1c9790acd60'
revision = '1c91ee99cac'
down_revision = '14d4ac0f0f1'

from alembic import op
import sqlalchemy as sa
from datetime import datetime, timedelta


def upgrade():
Expand All @@ -26,8 +27,11 @@ def upgrade():
)
op.create_index(op.f('ix_audit_block'), 'audit', ['block'], unique=False)
op.add_column('farmer', sa.Column('reg_time', sa.DateTime(), nullable=True))
op.add_column('farmer', sa.Column('uptime', sa.Integer(), nullable=True))
op.create_index(op.f('ix_farmer_last_seen'), 'farmer', ['last_seen'], unique=False)
op.add_column('farmer', sa.Column('uptime', sa.Interval(), nullable=True))
op.create_index(op.f('ix_farmer_last_seen'), 'farmer', ['last_seen'], unique=False)
farmer = sa.table('farmer',sa.column('reg_time'),sa.column('last_seen'))
op.execute(farmer.update().values(reg_time=datetime.utcnow()))
op.execute(farmer.update().values(last_seen=datetime.utcnow()))
### end Alembic commands ###


Expand Down

0 comments on commit 1e064fa

Please sign in to comment.