class Deployment(db.Model): __tablename__ = "deployments" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True, index=True, nullable=False) url = db.Column(db.String(50), unique=True, index=True, nullable=False) private = db.Column(db.Boolean, default=True) users = relationship("User", secondary=deployment_users, backref="deployments") db_servers = relationship(DatabaseServer, backref='deployment') app_servers = relationship(ApplicationServer, backref='deployment') def __repr__(self): return '<Deployment {}>'.format(self.name)
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True, index=True, nullable=False) email = db.Column(db.String(50), unique=True, index=True, nullable=False) _password = db.Column("password", db.String(100), nullable=False) admin = db.Column(db.Boolean, default=False) @hybrid_property def password(self): return self._password @password.setter def password(self, value): """Store the password as a hash for security.""" self._password = generate_password_hash(value) def check_password(self, value): return check_password_hash(self.password, value) def __repr__(self): return '<User {}>'.format(self.name)
class DatabaseServer(db.Model): __tablename__ = "database_servers" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True, nullable=False) private_address = db.Column(db.String(50), unique=True, nullable=False) db_port = db.Column(db.Integer, nullable=True) dbms = db.Column(db.String(10), nullable=False) storage_size = db.Column(db.Float, nullable=False) deployment_id = db.Column(db.Integer, db.ForeignKey('deployments.id')) def __repr__(self): return '<DatabaseServer {}>'.format(self.name)
class ApplicationServer(db.Model): __tablename__ = "application_servers" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True, index=True, nullable=False) private_address = db.Column(db.String(15), unique=True, index=True, nullable=False) os = db.Column(Enum(OS)) ram_size = db.Column(db.Integer, nullable=False) cpu_cores = db.Column(db.Integer, nullable=False) drive_size = db.Column(db.Float, nullable=False) deployment_id = db.Column(db.Integer, db.ForeignKey('deployments.id')) def __repr__(self): return '<ApplicationServer {}>'.format(self.name)
from sqlalchemy.orm import relationship from server_resources import db from server_resources.models.server import DatabaseServer, ApplicationServer deployment_users = db.Table( 'deployment_users', db.Column("u_id", db.Integer, db.ForeignKey("users.id"), primary_key=True), db.Column("d_id", db.Integer, db.ForeignKey("deployments.id"), primary_key=True)) class Deployment(db.Model): __tablename__ = "deployments" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), unique=True, index=True, nullable=False) url = db.Column(db.String(50), unique=True, index=True, nullable=False) private = db.Column(db.Boolean, default=True) users = relationship("User", secondary=deployment_users, backref="deployments") db_servers = relationship(DatabaseServer, backref='deployment') app_servers = relationship(ApplicationServer, backref='deployment') def __repr__(self): return '<Deployment {}>'.format(self.name)