当前位置:网站首页>从零开始写一个契约测试工具——数据库设计
从零开始写一个契约测试工具——数据库设计
2022-06-22 12:27:00 【点点寒彬】
接上文,第一步需要设计我们的表结构,我初步的构想是两张表来装下它,后续肯定会有一些变动,因为我也是一边写工具一边记录的。
设计说明
工具应该有两块内容,第一块是契约的信息,这部分记录的契约的结构体。第二快是子契约,所有具体的值必须由子契约来承载,子契约的内容一旦定义后是不可变更的。而契约工具对消费端和生产端的具体报文内容都由子契约来承载。
环境说明
我使用的是sqlalchemy这个ORM框架来处理数据库交互的。表结构的代码如下
from sqlalchemy import Column, String, Integer
from sqlalchemy.ext.declarative import declarative_base
BaseModel = declarative_base()
class ContractStructure(BaseModel):
__tablename__ = 'contract_structure'
id = Column(Integer, primary_key=True)
contract_name = Column(String(500), nullable=False)
contract_consumer_body = Column(String(10000), nullable=False)
contract_consumer_keys = Column(String(500), nullable=False)
contract_provider_body = Column(String(5000), nullable=False)
contract_stakeholders = Column(String(500), nullable=False)
contract_child_ids = Column(String(500), nullable=True)
contract_version = Column(Integer, default=1)
contract_last_version = Column(String(1), nullable=False, default='Y')
provider_url = Column(String(100), nullable=True)
class ContractChild(BaseModel):
__tablename__ = 'contract_child'
id = Column(Integer, primary_key=True)
child_id = Column(String(40), nullable=False)
child_name = Column(String(100), nullable=False)
contract_id = Column(Integer)
child_consumer_body = Column(String(10000), nullable=False)
child_provider_body = Column(String(5000), nullable=False)
下面我们一个一个来说明我这样设计的想法
ContractStructure
这个表是用来存放契约结构以及契约的一些相关信息。
- contract_name
契约名称,一般来说方便认识的名字比较好,比如Consumer-Provider这种。
- contract_consumer_body
契约消费者的结构体,也就是consumer端发起的报文。
- contract_consumer_keys
契约消费者的结构体的key,由于契约测试中结构体是不可变的,因此必须要校验consumer端传过来结构的key值,用来确保报文结构的一致性
- contract_provider_body
契约生产者的结构体,也就是返回给consumer端的报文结构
- contract_stakeholders
契约的干系人,一旦契约发生变动,程序需要通知的对象
- contract_child_ids
契约子内容的id
- contract_version
契约的版本信息,一旦契约发生变更,那么版本也要对应的变更
- contract_last_version
标记改版本的契约是否为最新的契约
- provider_url
生产中的url地址,工具要能够给provider端发送契约内容,因此需要一个字段来记录url
contract_child
这个表用来存放子契约的内容
- child_name
子契约对应的名字
- contract_id
所属契约的id
- child_consumer_body
消费端的报文内容
- child_provider_body
生产端的报文内容
最后
以上,我们定义了工具的表,下面应该做的就是开始写具体的契约类。
边栏推荐
- 0007 reverse integer
- Detailed explanation of rules and ideas for advance sale of deposit
- 动作捕捉系统用于地下隧道移动机器人定位与建图
- SAP 开发Keys 申请SSCR Keys申请
- Isn't the execution process of ODPs SQL executed from top to bottom
- Sap-abap- how to find a table and what related tables the fields have
- Precautions for wechat official account development
- 重磅直播|BizDevOps:数字化转型浪潮下的技术破局之路
- 巨杉数据库受邀出席鲲鹏开发者年度盛会2022,共建国产化数字底座
- 天翼云数字政府智慧数据中台通过认证
猜你喜欢

Tianyi cloud digital government smart data center has passed the certification

信创之下:国产数据库群星闪耀时

docker安装postgresql

巨杉数据库受邀出席鲲鹏开发者年度盛会2022,共建国产化数字底座

MySQL_数据处理之增删改

Hurun Research Institute launched the list of potential enterprises of China's meta universe, and Jushan database was selected as the future star enterprise

SAP 系统取消用户设置ALV全局布局

SAP SPRO configure how to display the corresponding t-code

Tis tutorial 02 model

Isn't this another go bug?
随机推荐
[QT] qfileinfo get the components of the file name
access_token不到两个小时失效的处理办法
Sap-abap- how to find a table and what related tables the fields have
AcWing 241 楼兰图腾(树状数组详解)
Sap-abap- how to transfer material master data, supplier master data, work orders, purchase orders and other information to external systems in real time - implicit enhancement.
MySQL_数据处理之增删改
天翼云数字政府智慧数据中台通过认证
342. Power of Four
Arcpy adding layers to map documents
SNC processing failed SAP router certificate regeneration
MySQL_ Addition, deletion and modification of data processing
智龄语音+php
【Qt】QFileInfo获取文件名的各个组成部分
leetcode 第 297 场周赛
Heavyweight live | bizdevops: the way to break the technology situation under the tide of digital transformation
MAUI使用Masa blazor组件库
Sequoiadb distributed database may 2022 issue
推荐一款M1芯片电脑快速搭建集群的虚拟机软件
vs code
Terraform的vpc网络自动化配置解决方案