models.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
  2. # Copyright: (c) <spug.dev@gmail.com>
  3. # Released under the AGPL-3.0 License.
  4. from django.db import models
  5. from libs import ModelMixin, human_datetime
  6. from apps.account.models import User
  7. class Environment(models.Model, ModelMixin):
  8. name = models.CharField(max_length=50)
  9. key = models.CharField(max_length=50)
  10. desc = models.CharField(max_length=255, null=True)
  11. sort_id = models.IntegerField(default=0, db_index=True)
  12. created_at = models.CharField(max_length=20, default=human_datetime)
  13. created_by = models.ForeignKey(User, on_delete=models.PROTECT)
  14. def __repr__(self):
  15. return f'<Environment {self.name!r}>'
  16. class Meta:
  17. db_table = 'environments'
  18. ordering = ('-sort_id',)
  19. class Service(models.Model, ModelMixin):
  20. name = models.CharField(max_length=50)
  21. key = models.CharField(max_length=50, unique=True)
  22. desc = models.CharField(max_length=255, null=True)
  23. created_at = models.CharField(max_length=20, default=human_datetime)
  24. created_by = models.ForeignKey(User, on_delete=models.PROTECT)
  25. def __repr__(self):
  26. return f'<Service {self.name!r}>'
  27. class Meta:
  28. db_table = 'services'
  29. ordering = ('-id',)
  30. class Config(models.Model, ModelMixin):
  31. TYPES = (
  32. ('app', 'App'),
  33. ('src', 'Service')
  34. )
  35. type = models.CharField(max_length=5, choices=TYPES)
  36. o_id = models.IntegerField()
  37. key = models.CharField(max_length=50)
  38. env = models.ForeignKey(Environment, on_delete=models.PROTECT)
  39. value = models.TextField(null=True)
  40. desc = models.CharField(max_length=255, null=True)
  41. is_public = models.BooleanField(default=False)
  42. updated_at = models.CharField(max_length=20)
  43. updated_by = models.ForeignKey(User, on_delete=models.PROTECT)
  44. def __repr__(self):
  45. return f'<Config {self.key!r}>'
  46. class Meta:
  47. db_table = 'configs'
  48. ordering = ('-key',)
  49. class ConfigHistory(models.Model, ModelMixin):
  50. ACTIONS = (
  51. ('1', '新增'),
  52. ('2', '更新'),
  53. ('3', '删除')
  54. )
  55. type = models.CharField(max_length=5)
  56. o_id = models.IntegerField()
  57. key = models.CharField(max_length=50)
  58. env_id = models.IntegerField()
  59. value = models.TextField(null=True)
  60. desc = models.CharField(max_length=255, null=True)
  61. is_public = models.BooleanField()
  62. old_value = models.TextField(null=True)
  63. action = models.CharField(max_length=2, choices=ACTIONS)
  64. updated_at = models.CharField(max_length=20)
  65. updated_by = models.ForeignKey(User, on_delete=models.PROTECT)
  66. def __repr__(self):
  67. return f'<ConfigHistory {self.key!r}>'
  68. class Meta:
  69. db_table = 'config_histories'
  70. ordering = ('key',)