有没有一种方法可以在AWS DynamoDB表上实施架构约束? [英] Is there a way to enforce a schema constraint on an AWS DynamoDB table?

查看:71
本文介绍了有没有一种方法可以在AWS DynamoDB表上实施架构约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名MSSQL开发人员,最近因为我们使用AWS并被要求使用DynamoDB构建新应用程序,因此我们需要一个高度可扩展的数据库服务。

I'm a MSSQL developer who recently was tasked with building a new application using DynamoDB since we use AWS and we wanted a highly scaleable database service.

我最大的关注的是数据完整性。例如,我有一个供所有用户使用的表,其中每行都需要有一个用户名,电子邮件和姓名字段,所有字符串以及一个经过验证的字段,该字段为整数。无论如何,是否要求该表中的所有条目都具有这些字段并具有特定类型?

My biggest concern is data integrity. For example, I have a table for all my users where every row needs to have a username, email, and name field, all strings, with a verified field that's an int. Is there anyway to require all entries in that table to have those fields and to be of that particular type?

由于该应用程序在PHP中,因此我正在使用水壶作为我的ORM,这应该防止我破坏数据完整性,但是另一位开发人员对是否添加另一个应用程序,或者有人通过控制台手动更改某些类型。
https://github.com/inouet/kettle

Since the application is in PHP I'm using Kettle as my ORM which should prevent me from messing up the data integrity but another developer voiced a concern about if we ever add another application or if someone manually changes some types via the console. https://github.com/inouet/kettle

推荐答案

当前,不,您有责任就基本表中不是键的属性的存在维护项目的完整性。但是,您可以使用LSI和GSI强制执行属性的数据类型(尽管我不认为这不是推荐的模式,因为这可能会引起分区发热,尤其是对于值范围较小的属性)。例如,经过验证的似乎可能只需要0或1作为一个值,因此,如果您创建的PK = verified的GSI,其中verify是数字,则已验证的GSI可能会限制对基表的写入。

Currently, no, you are responsible for maintaining the integrity of your items with respect to the existence of attributes that are not keys on the base table. However, you can use LSI and GSI to enforce data types of attributes (notwithstanding my qualm that this is not a recommended pattern, as it could cause partition heat especially for attributes whose range of values is small). For example, verified seems like it might take only 0 or 1 as a value, so if you create a GSI with PK=verified where verified is a Number, writes to the base table may get throttled by the verified GSI.

这篇关于有没有一种方法可以在AWS DynamoDB表上实施架构约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆