from app import db # Association tables (if not already defined) client_domains = db.Table('client_domains', db.Column('client_id', db.Integer, db.ForeignKey('client.id', ondelete="CASCADE")), db.Column('domain_id', db.Integer, db.ForeignKey('domain.id')) ) client_ssl = db.Table('client_ssl', db.Column('client_id', db.Integer, db.ForeignKey('client.id', ondelete="CASCADE")), db.Column('domain_id', db.Integer, db.ForeignKey('domain.id')) ) class Domain(db.Model): __tablename__ = 'domain' __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) domain = db.Column(db.String(255), unique=True, nullable=False) expiration_date = db.Column(db.String(255)) # WHOIS expiration date ssl_expiration_date = db.Column(db.String(255)) # SSL certificate expiration date ssl_only = db.Column(db.Boolean, default=False) # True if added via SSL-only form def __repr__(self): return f"" class Client(db.Model): __tablename__ = 'client' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), nullable=False) phone = db.Column(db.String(255)) address = db.Column(db.String(255)) # Delete all passwords when the client is deleted. passwords = db.relationship('ClientPassword', backref='client', lazy=True, cascade="all, delete-orphan") # Many-to-many: Only the associations will be removed (due to ondelete cascade), not the Domain records. domains = db.relationship('Domain', secondary=client_domains, backref=db.backref('clients', lazy='dynamic')) ssl_domains = db.relationship('Domain', secondary=client_ssl, backref=db.backref('ssl_clients', lazy='dynamic')) def __repr__(self): return f"" class PasswordCategory(db.Model): __tablename__ = 'password_category' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), unique=True, nullable=False) def __repr__(self): return f"" class ClientPassword(db.Model): __tablename__ = 'client_password' id = db.Column(db.Integer, primary_key=True) item = db.Column(db.String(255), nullable=False) username = db.Column(db.String(255), nullable=False) password = db.Column(db.String(255), nullable=False) client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable=False) category_id = db.Column(db.Integer, db.ForeignKey('password_category.id')) category = db.relationship('PasswordCategory') def __repr__(self): return f""