Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create_table should include polymorphic indexes (#1107)
With polymorphism, an index's key attribute might be defined only in a derived model (e.g. if it pertains only to a certain kind of model — for other models, it'd be a sparse index), and so it makes sense to add that index only to the derived model, e.g. ```python class BaseModel(Model): ... cls = DescriminatorAttribute() class DerivedIndex(GlobalSecondaryIndex): class Meta: index_name = 'derived' ... ham = UnicodeAttribute(hash_key=True) class DerivedModel(BaseModel, discriminator='spam'): ham = UnicodeAttribute() index = DerivedIndex() ``` A common pattern in a development environment is to use `Model.create_table`. For a polymorphic model, given you have to pick _one_ model to invoke `create_table` on, it only serves right that you invoke it on the base model. Before this change, the base model's "schema" didn't include all the derived models' indexes. With this change, it will.
- Loading branch information
Showing
11 changed files
with
304 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.[signals] | ||
sphinx-rtd-theme==0.4.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sys | ||
from typing import Dict | ||
from typing import List | ||
|
||
if sys.version_info >= (3, 8): | ||
from typing import TypedDict | ||
else: | ||
from typing_extensions import TypedDict | ||
|
||
if sys.version_info >= (3, 11): | ||
from typing import NotRequired | ||
else: | ||
from typing_extensions import NotRequired | ||
|
||
|
||
class SchemaAttrDefinition(TypedDict): | ||
AttributeName: str | ||
AttributeType: str | ||
|
||
|
||
class KeySchema(TypedDict): | ||
AttributeName: str | ||
KeyType: str | ||
|
||
|
||
class Projection(TypedDict): | ||
ProjectionType: str | ||
NonKeyAttributes: NotRequired[List[str]] | ||
|
||
|
||
class IndexSchema(TypedDict): | ||
index_name: str | ||
key_schema: List[Dict[str, str]] | ||
projection: Dict[str, str] | ||
attribute_definitions: List[SchemaAttrDefinition] | ||
|
||
|
||
class ProvisionedThroughput(TypedDict, total=False): | ||
ReadCapacityUnits: int | ||
WriteCapacityUnits: int | ||
|
||
|
||
class GlobalSecondaryIndexSchema(IndexSchema): | ||
provisioned_throughput: ProvisionedThroughput | ||
|
||
|
||
class ModelSchema(TypedDict): | ||
attribute_definitions: List[SchemaAttrDefinition] | ||
key_schema: List[KeySchema] | ||
global_secondary_indexes: List[GlobalSecondaryIndexSchema] | ||
local_secondary_indexes: List[IndexSchema] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.