123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter database
- name:device_info.py
- author:rabin
- """
- from .__load__ import *
- class Device_info(Model):
- __table__ = 'device_info'
- __comment__ = '设备管理'
- id = Fields(type='uuid', primaryKey=True, comment='设备ID', uuid='farm_id')
- farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
- name = Fields(type='varchar(50)', comment='设备名')
- #hardware_id = Fields(type='bigint', comment='硬件id', match='number|硬件id必须是数字', unique=True)
- #hardware_id = Fields(type='bigint', comment='硬件id', match='number|硬件id必须是数字')
- hardware_id = Fields(type='varchar(500)', comment='硬件id')
- hardware_type = Fields(type='int', comment='硬件类型')
- gateway_id = Fields(type='uuid', comment='网关id')
- type_id = Fields(type='int', comment='设备类型id')
- value = Fields(type='varchar(1000)', comment='设备传过来的值')
- exp = Fields(type='varchar(500)', comment='表达式')
- max = Fields(type='float', comment='最大上限', match='numberFloat|最大上限必须是数字')
- min = Fields(type='float', comment='最小下限', match='numberFloat|最小下限必须是数字')
- cxnum = Fields(type='int', comment='超限次数')
- cxtype = Fields(type='int', comment='超限类型,1为超过上限,2为超过下限')
- cxdate = Fields(type='int', comment='首次超限时间')
- status = Fields(type='boolean', default='False', comment='设备连接状态')
- state = Fields(type='boolean', default='True', comment='数据存在状态')
- cdate = Fields(type='int', default='time', comment='创建时间')
- udate = Fields(type='int', default='time', comment='接入时间')
- inorder = Fields(type='int', default='0', comment='排序', match='number|排序必须是数字')
- oper = Fields(type='boolean', default='False', comment='操作类型')
- operdate = Fields(type='int', comment='操作时间')
- server_id = Fields(type='int', comment='服务id')
- product_id = Fields(type='int', comment='产品id')
- code_id = Fields(type='int', comment='命令码id')
- code_index = Fields(type='int', comment='命令码索引key')
- ##ALTER TABLE demeter_device_info ADD exp varchar(500);
- #ALTER TABLE demeter_device_info ADD inorder int default 100;
- #ALTER TABLE demeter_device_info ADD oper boolean;
- #ALTER TABLE demeter_device_info ADD operdate int;
- #ALTER TABLE demeter_device_info DROP inorder;
- #ALTER TABLE demeter_device_info ALTER hardware_id type varchar(500);
- #ALTER TABLE demeter_device_info ADD server_id int;
- #ALTER TABLE demeter_device_info ADD product_id int;
- #ALTER TABLE demeter_device_info ADD code_id int;
- #ALTER TABLE demeter_device_info ADD code_index int;
- '''
- 1、增加一列ALTER TABLE table_name ADD column_name datatype;
- 2、删除一列
- ALTER TABLE table_name DROP column_name;
- 3、更改列的数据类型
- ALTER TABLE table_name ALTER column_name TYPE datatype;
- 4、表的重命名
- ALTER TABLE table_name RENAME TO new_name;
- 5、更改列的名字
- ALTER TABLE table_name RENAME column_name to new_column_name;
- 6、字段的not null设置
- ALTER TABLE table_name ALTER column_name {SET|DROP} NOT NULL;
- 7、给列添加default
- ALTER TABLE table_name ALTER column_name SET DEFAULT expression;
- 作者:暗香抚动
- 链接:https://www.jianshu.com/p/fe824d6ecfb0
- 来源:简书
- 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
- '''
|