models.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. """Database models"""
  2. from sqlalchemy import Column, ForeignKey, Integer, String, \
  3. DateTime, BigInteger, SmallInteger, Date
  4. from sqlalchemy.orm import relationship, backref
  5. from sqlalchemy.ext.declarative import declarative_base
  6. Base = declarative_base()
  7. class Factory(Base):
  8. """Model for factory"""
  9. __tablename__ = 'factory'
  10. id = Column(Integer, primary_key=True)
  11. name = Column(String)
  12. resource_type = Column(SmallInteger)
  13. player_id = Column(BigInteger, ForeignKey('player.id'))
  14. player = relationship(
  15. 'Player',
  16. backref=backref('factories', lazy='dynamic')
  17. )
  18. class FactoryTrack(Base):
  19. """Model for facctory track"""
  20. __tablename__ = 'factory_track'
  21. id = Column(Integer, primary_key=True)
  22. date_time = Column(DateTime)
  23. state_id = Column(Integer, ForeignKey('state.id'))
  24. state = relationship(
  25. 'State',
  26. backref=backref('factory_tracks', lazy='dynamic')
  27. )
  28. class FactoryLocation(Base):
  29. """Model for factory location"""
  30. __tablename__ = 'factory_location'
  31. factory_id = Column(Integer, ForeignKey('factory.id'), primary_key=True)
  32. region_id = Column(Integer, ForeignKey('region.id'), primary_key=True)
  33. from_date_time = Column(DateTime, primary_key=True)
  34. until_date_time = Column(DateTime)
  35. region = relationship('Region')
  36. class FactoryStat(Base):
  37. """Model for factory"""
  38. __tablename__ = 'factory_stat'
  39. id = Column(Integer, primary_key=True)
  40. level = Column(SmallInteger)
  41. workers = Column(SmallInteger)
  42. experience = Column(Integer)
  43. wage = Column(Integer)
  44. factory_id = Column(Integer, ForeignKey('factory.id'))
  45. factory = relationship(
  46. 'Factory',
  47. backref=backref('factory_stats', lazy='dynamic')
  48. )
  49. factory_track_id = Column(Integer, ForeignKey('factory_track.id'))
  50. factory_track = relationship(
  51. 'FactoryTrack',
  52. backref=backref('factory_stats', lazy='dynamic')
  53. )
  54. class State(Base):
  55. """Model for state"""
  56. __tablename__ = 'state'
  57. id = Column(Integer, primary_key=True)
  58. name = Column(String)
  59. class Region(Base):
  60. """Model for region"""
  61. __tablename__ = 'region'
  62. id = Column(Integer, primary_key=True)
  63. name = Column(String)
  64. class StateRegion(Base):
  65. """Model for state region"""
  66. __tablename__ = 'state_region'
  67. state_id = Column(Integer, ForeignKey('state.id'), primary_key=True)
  68. from_date_time = Column(DateTime, primary_key=True)
  69. until_date_time = Column(DateTime)
  70. region_id = Column(Integer, ForeignKey('region.id'), primary_key=True)
  71. region = relationship(
  72. 'Region',
  73. backref=backref('state_regions', lazy='dynamic')
  74. )
  75. class Player(Base):
  76. """Model for player"""
  77. __tablename__ = 'player'
  78. id = Column(BigInteger, primary_key=True)
  79. name = Column(String)
  80. nation = Column(String)
  81. registration_date = Column(Date)