device_info.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter database
  5. name:device_info.py
  6. author:rabin
  7. """
  8. from .__load__ import *
  9. class Device_info(Model):
  10. __table__ = 'device_info'
  11. __comment__ = '设备管理'
  12. id = Fields(type='uuid', primaryKey=True, comment='设备ID', uuid='farm_id')
  13. farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
  14. name = Fields(type='varchar(50)', comment='设备名')
  15. #hardware_id = Fields(type='bigint', comment='硬件id', match='number|硬件id必须是数字', unique=True)
  16. #hardware_id = Fields(type='bigint', comment='硬件id', match='number|硬件id必须是数字')
  17. hardware_id = Fields(type='varchar(500)', comment='硬件id')
  18. hardware_type = Fields(type='int', comment='硬件类型')
  19. gateway_id = Fields(type='uuid', comment='网关id')
  20. type_id = Fields(type='int', comment='设备类型id')
  21. value = Fields(type='varchar(1000)', comment='设备传过来的值')
  22. exp = Fields(type='varchar(500)', comment='表达式')
  23. max = Fields(type='float', comment='最大上限', match='numberFloat|最大上限必须是数字')
  24. min = Fields(type='float', comment='最小下限', match='numberFloat|最小下限必须是数字')
  25. cxnum = Fields(type='int', comment='超限次数')
  26. cxtype = Fields(type='int', comment='超限类型,1为超过上限,2为超过下限')
  27. cxdate = Fields(type='int', comment='首次超限时间')
  28. status = Fields(type='boolean', default='False', comment='设备连接状态')
  29. state = Fields(type='boolean', default='True', comment='数据存在状态')
  30. cdate = Fields(type='int', default='time', comment='创建时间')
  31. udate = Fields(type='int', default='time', comment='接入时间')
  32. oper = Fields(type='boolean', default='False', comment='操作类型')
  33. operdate = Fields(type='int', comment='操作时间')
  34. server_id = Fields(type='int', comment='服务id')
  35. product_id = Fields(type='int', comment='产品id')
  36. code_id = Fields(type='int', comment='命令码id')
  37. code_index = Fields(type='int', comment='命令码索引key')
  38. inorder = Fields(type='int', default='0', comment='排序', match='number|排序必须是数字')
  39. ##ALTER TABLE demeter_device_info ADD exp varchar(500);
  40. #ALTER TABLE demeter_device_info ADD inorder int default 100;
  41. #ALTER TABLE demeter_device_info ADD oper boolean;
  42. #ALTER TABLE demeter_device_info ADD operdate int;
  43. #ALTER TABLE demeter_device_info DROP inorder;
  44. #ALTER TABLE demeter_device_info ALTER hardware_id type varchar(500);
  45. #ALTER TABLE demeter_device_info ADD server_id int;
  46. #ALTER TABLE demeter_device_info ADD product_id int;
  47. #ALTER TABLE demeter_device_info ADD code_id int;
  48. #ALTER TABLE demeter_device_info ADD code_index int;
  49. '''
  50. 1、增加一列ALTER TABLE table_name ADD column_name datatype;
  51. 2、删除一列
  52. ALTER TABLE table_name DROP column_name;
  53. 3、更改列的数据类型
  54. ALTER TABLE table_name ALTER column_name TYPE datatype;
  55. 4、表的重命名
  56. ALTER TABLE table_name RENAME TO new_name;
  57. 5、更改列的名字
  58. ALTER TABLE table_name RENAME column_name to new_column_name;
  59. 6、字段的not null设置
  60. ALTER TABLE table_name ALTER column_name {SET|DROP} NOT NULL;
  61. 7、给列添加default
  62. ALTER TABLE table_name ALTER column_name SET DEFAULT expression;
  63. 作者:暗香抚动
  64. 链接:https://www.jianshu.com/p/fe824d6ecfb0
  65. 来源:简书
  66. 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  67. '''