class DbUser(Base): __tablename__ = "db_dbuser" id = Column(Integer, primary_key=True) email = Column(String(254), unique=True, index=True) password = Column(String(128)) # Clear text password ? first_name = Column(String(254), nullable=True) last_name = Column(String(254), nullable=True) institution = Column(String(254), nullable=True) is_staff = Column(Boolean, default=False) is_active = Column(Boolean, default=False) last_login = Column(DateTime(timezone=True), default=timezone.now) date_joined = Column(DateTime(timezone=True), default=timezone.now) def get_aiida_class(self): from aiida.backends.djsite.db.models import DbUser as DjangoSchemaDbUser djuser = DjangoSchemaDbUser(id=self.id, email=self.email, password=self.password, first_name=self.first_name, last_name=self.last_name, institution=self.institution, is_staff=self.is_staff, is_active=self.is_active, last_login=self.last_login, date_joined=self.date_joined) return djuser.get_aiida_class()
class DbExtra(Base): __tablename__ = "db_dbextra" id = Column(Integer, primary_key=True) dbnode_id = Column(Integer, ForeignKey('db_dbnode.id')) key = Column(String(255)) datatype = Column(String(10)) tval = Column(String, default='') fval = Column(Float, default=None, nullable=True) ival = Column(Integer, default=None, nullable=True) bval = Column(Boolean, default=None, nullable=True) dval = Column(DateTime, default=None, nullable=True)
class DbGroup(Base): __tablename__ = "db_dbgroup" id = Column(Integer, primary_key=True) uuid = Column(UUID(as_uuid=True), default=uuid_func) name = Column(String(255), index=True) type = Column(String(255), default="", index=True) time = Column(DateTime(timezone=True), default=timezone.now) description = Column(Text, nullable=True) user_id = Column( Integer, ForeignKey('db_dbuser.id', ondelete='CASCADE', deferrable=True, initially="DEFERRED")) user = relationship('DbUser', backref=backref('dbgroups', cascade='merge')) dbnodes = relationship('DbNode', secondary=table_groups_nodes, backref="dbgroups", lazy='dynamic') __table_args__ = (UniqueConstraint('name', 'type'), ) def __str__(self): if self.type: return '<DbGroup [type: {}] "{}">'.format(self.type, self.name) else: return '<DbGroup [user-defined] "{}">'.format(self.name) def get_aiida_class(self): from aiida.orm.implementation.django.group import Group as DjangoAiidaGroup from aiida.backends.djsite.db.models import DbGroup as DjangoSchemaDbGroup dbgroup = DjangoSchemaDbGroup( id=self.id, type=self.type, uuid=self.uuid, name=self.name, time=self.time, description=self.description, user_id=self.user_id, ) return DjangoAiidaGroup(dbgroup=dbgroup)
class DbLink(Base): __tablename__ = "db_dblink" id = Column(Integer, primary_key=True) input_id = Column( Integer, ForeignKey('db_dbnode.id', deferrable=True, initially="DEFERRED")) output_id = Column( Integer, ForeignKey('db_dbnode.id', ondelete="CASCADE", deferrable=True, initially="DEFERRED")) type = Column(String(255)) input = relationship("DbNode", primaryjoin="DbLink.input_id == DbNode.id") output = relationship("DbNode", primaryjoin="DbLink.output_id == DbNode.id") label = Column(String(255), index=True, nullable=False)
class DbComputer(Base): __tablename__ = "db_dbcomputer" id = Column(Integer, primary_key=True) uuid = Column(UUID(as_uuid=True), default=uuid_func) name = Column(String(255), unique=True, nullable=False) hostname = Column(String(255)) description = Column(Text, nullable=True) enabled = Column(Boolean) transport_type = Column(String(255)) scheduler_type = Column(String(255)) transport_params = Column(String(255)) _metadata = Column('metadata', String(255), default="{}") def get_aiida_class(self): from aiida.backends.djsite.db.models import DbComputer as DjangoSchemaDbComputer djcomputer = DjangoSchemaDbComputer( id=self.id, uuid=self.uuid, name=self.name, hostname=self.hostname, description=self.description, enabled=self.enabled, transport_type=self.transport_type, scheduler_type=self.scheduler_type, transport_params=self.transport_params, metadata=self._metadata) return djcomputer.get_aiida_class()
class DbCalcState(Base): __tablename__ = "db_dbcalcstate" id = Column(Integer, primary_key=True) dbnode = relationship('DbNode', backref=backref('dbstates', passive_deletes=True)) state = Column(String(255)) time = Column(DateTime(timezone=True), default=timezone.now) dbnode_id = Column( Integer, ForeignKey('db_dbnode.id', ondelete="CASCADE", deferrable=True, initially="DEFERRED")) __table_args__ = (UniqueConstraint('dbnode_id', 'state'), )
class DbNode(Base): __tablename__ = "db_dbnode" id = Column(Integer, primary_key=True) uuid = Column(UUID(as_uuid=True), default=uuid_func) type = Column(String(255), index=True) label = Column(String(255), index=True, nullable=True) description = Column(Text(), nullable=True) ctime = Column(DateTime(timezone=True), default=timezone.now) mtime = Column(DateTime(timezone=True), default=timezone.now) dbcomputer_id = Column(Integer, ForeignKey('db_dbcomputer.id', deferrable=True, initially="DEFERRED"), nullable=True) dbcomputer = relationship('DbComputer', backref=backref('dbnodes', passive_deletes=True)) user_id = Column(Integer, ForeignKey('db_dbuser.id', deferrable=True, initially="DEFERRED"), nullable=False) user = relationship('DbUser', backref='dbnodes') public = Column(Boolean, default=False) nodeversion = Column(Integer, default=1) attributes = relationship('DbAttribute', uselist=True, backref='dbnode') extras = relationship('DbExtra', uselist=True, backref='dbnode') outputs = relationship("DbNode", secondary="db_dblink", primaryjoin="DbNode.id == DbLink.input_id", secondaryjoin="DbNode.id == DbLink.output_id", backref=backref("inputs", passive_deletes=True), passive_deletes=True) children = relationship("DbNode", secondary="db_dbpath", primaryjoin="DbNode.id == DbPath.parent_id", secondaryjoin="DbNode.id == DbPath.child_id", backref="parents") def get_aiida_class(self): """ Return the corresponding instance of :func:`~aiida.orm.implementation.django.node.Node` or a subclass return by the plugin loader. .. todo:: The behavior is quite pathetic, creating a django DbNode instance to instantiate the aiida instance. These means that every time you load Aiida instances with the QueryBuilder when using Django as a backend, three instances are instantiated for every Aiida instance you load! Could be fixed by allowing DbNode from the dummy nodel to be passed to AiidaNode's __init__. :returns: An instance of the plugin class """ # I need to import the DbNode in the Django model, # and instantiate an object that has the same attributes as self. from aiida.backends.djsite.db.models import DbNode as DjangoSchemaDbNode dbnode = DjangoSchemaDbNode(id=self.id, type=self.type, uuid=self.uuid, ctime=self.ctime, mtime=self.mtime, label=self.label, dbcomputer_id=self.dbcomputer_id, user_id=self.user_id, public=self.public, nodeversion=self.nodeversion) return dbnode.get_aiida_class()