old_contents: # -*- coding: utf-8 -*-
  # Copyright (c) 2015 The Pycroft Authors. See the AUTHORS file.
  # This file is part of the Pycroft project and licensed under the terms of
  # the Apache License, Version 2.0. See the LICENSE file for details.
  from sqlalchemy import Column, ForeignKey, CheckConstraint
  from sqlalchemy.orm import relationship, backref
  from sqlalchemy.types import BigInteger, Enum, Integer, DateTime
  
  from pycroft.model.base import ModelBase, IntegerIdModel
  from pycroft.model.user import User
  from pycroft.model.functions import utcnow
  from pycroft.model.host import IP
  
  
  class TrafficBalance(ModelBase):
      user_id = Column(Integer, ForeignKey(User.id, ondelete="CASCADE"),
                       primary_key=True)
      user = relationship(User,
                          backref=backref("_traffic_balance", uselist=False))
      amount = Column(BigInteger, nullable=False)
      timestamp = Column(DateTime, default=utcnow(), nullable=False)
  
  
  class TrafficEvent(object):
      timestamp = Column(DateTime, default=utcnow(), nullable=False)
      amount = Column(BigInteger, CheckConstraint('amount >= 0'),
                      nullable=False)
  
  
  class TrafficVolume(TrafficEvent, IntegerIdModel):
      type = Column(Enum("IN", "OUT", name="traffic_direction"),
                    nullable=False)
      ip_id = Column(Integer, ForeignKey(IP.id, ondelete="CASCADE"),
                     nullable=False)
      ip = relationship(IP, backref=backref("traffic_volumes",
                                            cascade="all, delete-orphan"))
      user_id = Column(Integer, ForeignKey(User.id, ondelete='CASCADE'),
                       nullable=True)
      user = relationship(User,
                          backref=backref("traffic_volumes",
                                          cascade="all, delete-orphan"),
                          uselist=False)
      packets = Column(Integer, CheckConstraint('amount >= 0'),
                       nullable=False)
  
  
  class TrafficCredit(TrafficEvent, IntegerIdModel):
      user_id = Column(Integer, ForeignKey(User.id, ondelete='CASCADE'),
                       nullable=False)
      user = relationship(User,
                          backref=backref("traffic_credits",
                                          cascade="all, delete-orphan"),
                          uselist=False)
  
new_contents: # -*- coding: utf-8 -*-
  # Copyright (c) 2015 The Pycroft Authors. See the AUTHORS file.
  # This file is part of the Pycroft project and licensed under the terms of
  # the Apache License, Version 2.0. See the LICENSE file for details.
  from sqlalchemy import Column, ForeignKey, CheckConstraint
  from sqlalchemy.orm import relationship, backref
  from sqlalchemy.types import BigInteger, Enum, Integer, DateTime
  
  from pycroft.model.base import ModelBase, IntegerIdModel
  from pycroft.model.user import User
  from pycroft.model.functions import utcnow
  from pycroft.model.host import IP
  
  
  class TrafficBalance(ModelBase):
      user_id = Column(Integer, ForeignKey(User.id, ondelete="CASCADE"),
                       primary_key=True)
      user = relationship(User,
                          backref=backref("_traffic_balance", uselist=False))
      amount = Column(BigInteger, nullable=False)
      timestamp = Column(DateTime, default=utcnow(), nullable=False)
  
  
  class TrafficEvent(object):
      timestamp = Column(DateTime, default=utcnow(), nullable=False)
      amount = Column(BigInteger, CheckConstraint('amount >= 0'),
                      nullable=False)
  
  
  class TrafficVolume(TrafficEvent, IntegerIdModel):
      type = Column(Enum("Ingress", "Egress", name="traffic_direction"),
                    nullable=False)
      ip_id = Column(Integer, ForeignKey(IP.id, ondelete="CASCADE"),
                     nullable=False)
      ip = relationship(IP, backref=backref("traffic_volumes",
                                            cascade="all, delete-orphan"))
      user_id = Column(Integer, ForeignKey(User.id, ondelete='CASCADE'),
                       nullable=True)
      user = relationship(User,
                          backref=backref("traffic_volumes",
                                          cascade="all, delete-orphan"),
                          uselist=False)
      packets = Column(Integer, CheckConstraint('amount >= 0'),
                       nullable=False)
  
  
  class TrafficCredit(TrafficEvent, IntegerIdModel):
      user_id = Column(Integer, ForeignKey(User.id, ondelete='CASCADE'),
                       nullable=False)
      user = relationship(User,
                          backref=backref("traffic_credits",
                                          cascade="all, delete-orphan"),
                          uselist=False)
  
subject: Rename traffic direction values