class User(db.Model): __tablename__ = 'users' user_id = db.Column(db.Integer, primary_key=True) registration = db.Column(db.String(14), nullable=False, unique=True) name = db.Column(db.String(128), nullable=False) email = db.Column(db.String(64), nullable=False, unique=True) password = db.Column(db.Text, nullable=False) salt = db.Column(db.Text) user_type_id = db.Column(db.Integer, db.ForeignKey('user_type.user_type_id')) cars = db.relationship('Car', backref='Owner', primaryjoin='Car.user_id==User.user_id') user_type = db.relationship( 'UserType', primaryjoin='User.user_type_id == UserType.user_type_id', backref='users') def __init__(self, registration, name, email, password, salt, user_type_id): self.name = name self.salt = salt self.email = email self.password = password self.registration = registration self.user_type_id = user_type_id
class UserType(db.Model): __tablename__ = 'user_type' user_type_id = db.Column(db.Integer, primary_key=True) type_code = db.Column(db.String(2), nullable=False, unique=True) type_description = db.Column(db.String(32), nullable=False) def __init__(self, type_code, type_description): self.type_code = type_code self.type_description = type_description
class Node(db.Model): __tablename__ = 'node' node_id = db.Column(db.Integer, primary_key=True) ip_address = db.Column(db.String(32), nullable=False, unique=True) alias = db.Column(db.String(16), nullable=False, unique=True) active = db.Column(db.Boolean, nullable=False) def __init__(self, ip_address, alias): self.ip_address = ip_address self.alias = alias self.active = True
class Car(db.Model): __tablename__ = 'car' car_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'), nullable=False) license_plate = db.Column(db.String(7), nullable=False, unique=True) mileage = db.Column(db.String(7), nullable=False) node_id = db.Column(db.Integer, db.ForeignKey('node.node_id')) node = db.relationship('Node', primaryjoin='Car.node_id == Node.node_id', backref='cars') def __init__(self, user_id, license_plate, mileage, node_id): self.user_id = user_id self.license_plate = license_plate self.mileage = mileage self.node_id = node_id
class VCarPerVendor(db.Model): __tablename__ = 'v_car_per_vendor' vendor_id = db.Column(db.Integer, primary_key=True) license_plate = db.Column(db.String(7)) registration = db.Column(db.String(14))