class FrameworkRecord(db.Model): """ 脚手架 """ __tablename__ = 'res_framework' id = db.Column(db.Integer, primary_key=True) project_name = db.Column(db.String(64), index=True, nullable=False) service_name = db.Column(db.String(64), index=True, nullable=False) project_type = db.Column(db.Integer, nullable=False) down_url = db.Column(db.String(128), nullable=False) desc = db.Column(db.String(64), default='', nullable=True) date_joined = db.Column(db.DateTime, default=datetime.now) def to_json(self): return to_json_ext(self, self.__class__)
class ModuleRecord(db.Model): """ 项目模块 """ __tablename__ = 'res_module' id = db.Column(db.Integer, primary_key=True) module_name = db.Column(db.String(64), index=True, nullable=False) #模块名称 project_id = db.Column(db.Integer, db.ForeignKey('res_project.id')) #项目ID module_tech = db.Column(db.String(8), nullable=False) #技术栈 git_url = db.Column(db.String(64), nullable=False) #git地址 logs_path = db.Column(db.String(64), nullable=False) #日志路径 module_path = db.Column(db.String(64)) #模块路径 port = db.Column(db.Integer) #端口 desc = db.Column(db.String(128)) #模块描述 sequence = db.Column(db.Integer) #发布顺序 module_type = db.Column(db.String(8)) #模块类型,基础模块、服务模块、网关模块 creator_id = db.Column(db.Integer, db.ForeignKey('account_user.id')) date_joined = db.Column(db.DateTime, default=datetime.now) date_updated = db.Column(db.DateTime, default=datetime.now) is_deleted = db.Column(db.Boolean, default=False) def to_json(self): return to_json_ext(self, self.__class__)
class Department(db.Model): """ 部门表 """ __tablename__ = 'account_department' id = db.Column(db.Integer, primary_key=True) department = db.Column(db.String(32), index=True, unique=True, nullable=False) def to_json(self): return to_json_ext(self, self.__class__)
class ProjectRecord(db.Model): """ 项目 """ __tablename__ = 'res_project' id = db.Column(db.Integer, primary_key=True) project_name = db.Column(db.String(64), index=True, unique=True, nullable=False) #项目名称 department_id = db.Column(db.Integer, db.ForeignKey('account_department.id')) #部门ID project_stage = db.Column(db.String(8), default='default') #项目状态 leader_id = db.Column(db.Integer, db.ForeignKey('account_user.id')) #项目负责人 desc = db.Column(db.String(128)) #项目描述 creator_id = db.Column(db.Integer, db.ForeignKey('account_user.id')) date_joined = db.Column(db.DateTime, default=datetime.now) date_updated = db.Column(db.DateTime, default=datetime.now) is_deleted = db.Column(db.Boolean, default=False) def to_json(self): return to_json_ext(self, self.__class__)
class User(db.Model): """ 用户表 """ __tablename__ = 'account_user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True, nullable=False) password = db.Column(db.String(32), nullable=False) email = db.Column(db.String(120), nullable=True) chinese_name = db.Column(db.String(32), nullable=True) mobile = db.Column(db.String(32), nullable=True) ldap_dn = db.Column(db.String(120), nullable=True) is_active = db.Column(db.Boolean, default=False) role = db.Column(db.String(64), default=0) date_updated = db.Column(db.DateTime) date_joined = db.Column(db.DateTime, default=datetime.now) def __repr__(self): return '<User %r>' % (self.username) def to_json(self): roles_list = [] for role in list(self.role): roles_list.append(roles_dict.get(role)) return { 'id': self.id, 'username': self.username, 'email': self.email, 'chinese_name': self.chinese_name, 'mobile': self.mobile or '', 'role': roles_list, 'date_joined': self.date_joined.strftime('%Y-%m-%d %H:%M:%S') }