@@ -43,53 +43,56 @@ static void createTable(final DynamoDbClient client, final String name) throws E
43
43
if (client .listTables ().tableNames ().contains (name )) {
44
44
return ;
45
45
}
46
+ // looks like bug within local dynamodb client around creating multiple tables at the same time
47
+ synchronized (DynamoDbInitializer .class ) {
48
+ client
49
+ .createTable (
50
+ t -> t
51
+ .tableName (name )
52
+ .keySchema (
53
+ KeySchemaElement .builder ().attributeName ("organisationId" ).keyType (KeyType .HASH ).build (),
54
+ KeySchemaElement .builder ().attributeName ("id" ).keyType (KeyType .RANGE ).build ()
55
+ )
56
+ .streamSpecification (streamSpecification -> streamSpecification .streamEnabled (true ).streamViewType (StreamViewType .NEW_IMAGE ))
57
+ .globalSecondaryIndexes (
58
+ GlobalSecondaryIndex
59
+ .builder ()
60
+ .indexName ("secondaryGlobal" )
61
+ .provisionedThroughput (p -> p .readCapacityUnits (10L ).writeCapacityUnits (10L ))
62
+ .projection (b -> b .projectionType (ProjectionType .ALL ))
63
+ .keySchema (KeySchemaElement .builder ().attributeName ("secondaryGlobal" ).keyType (KeyType .HASH ).build ())
64
+ .build (),
65
+ GlobalSecondaryIndex
66
+ .builder ()
67
+ .indexName ("parallelIndex" )
68
+ .provisionedThroughput (p -> p .readCapacityUnits (10L ).writeCapacityUnits (10L ))
69
+ .projection (b -> b .projectionType (ProjectionType .ALL ))
70
+ .keySchema (
71
+ KeySchemaElement .builder ().attributeName ("organisationId" ).keyType (KeyType .HASH ).build (),
72
+ KeySchemaElement .builder ().attributeName ("parallelHash" ).keyType (KeyType .RANGE ).build ()
73
+ )
74
+ .build ()
75
+ )
76
+ .localSecondaryIndexes (
77
+ builder -> builder
78
+ .indexName ("secondaryOrganisation" )
79
+ .projection (b -> b .projectionType (ProjectionType .ALL ))
80
+ .keySchema (
81
+ KeySchemaElement .builder ().attributeName ("organisationId" ).keyType (KeyType .HASH ).build (),
82
+ KeySchemaElement .builder ().attributeName ("secondaryOrganisation" ).keyType (KeyType .RANGE ).build ()
83
+ )
84
+ )
85
+ .attributeDefinitions (
86
+ AttributeDefinition .builder ().attributeName ("organisationId" ).attributeType (ScalarAttributeType .S ).build (),
87
+ AttributeDefinition .builder ().attributeName ("id" ).attributeType (ScalarAttributeType .S ).build (),
88
+ AttributeDefinition .builder ().attributeName ("secondaryGlobal" ).attributeType (ScalarAttributeType .S ).build (),
89
+ AttributeDefinition .builder ().attributeName ("secondaryOrganisation" ).attributeType (ScalarAttributeType .S ).build (),
90
+ AttributeDefinition .builder ().attributeName ("parallelHash" ).attributeType (ScalarAttributeType .S ).build ()
91
+ )
92
+ .provisionedThroughput (p -> p .readCapacityUnits (10L ).writeCapacityUnits (10L ).build ())
93
+ );
46
94
47
- client
48
- .createTable (
49
- t -> t
50
- .tableName (name )
51
- .keySchema (
52
- KeySchemaElement .builder ().attributeName ("organisationId" ).keyType (KeyType .HASH ).build (),
53
- KeySchemaElement .builder ().attributeName ("id" ).keyType (KeyType .RANGE ).build ()
54
- )
55
- .streamSpecification (streamSpecification -> streamSpecification .streamEnabled (true ).streamViewType (StreamViewType .NEW_IMAGE ))
56
- .globalSecondaryIndexes (
57
- GlobalSecondaryIndex
58
- .builder ()
59
- .indexName ("secondaryGlobal" )
60
- .provisionedThroughput (p -> p .readCapacityUnits (10L ).writeCapacityUnits (10L ))
61
- .projection (b -> b .projectionType (ProjectionType .ALL ))
62
- .keySchema (KeySchemaElement .builder ().attributeName ("secondaryGlobal" ).keyType (KeyType .HASH ).build ())
63
- .build (),
64
- GlobalSecondaryIndex
65
- .builder ()
66
- .indexName ("parallelIndex" )
67
- .provisionedThroughput (p -> p .readCapacityUnits (10L ).writeCapacityUnits (10L ))
68
- .projection (b -> b .projectionType (ProjectionType .ALL ))
69
- .keySchema (
70
- KeySchemaElement .builder ().attributeName ("organisationId" ).keyType (KeyType .HASH ).build (),
71
- KeySchemaElement .builder ().attributeName ("parallelHash" ).keyType (KeyType .RANGE ).build ()
72
- )
73
- .build ()
74
- )
75
- .localSecondaryIndexes (
76
- builder -> builder
77
- .indexName ("secondaryOrganisation" )
78
- .projection (b -> b .projectionType (ProjectionType .ALL ))
79
- .keySchema (
80
- KeySchemaElement .builder ().attributeName ("organisationId" ).keyType (KeyType .HASH ).build (),
81
- KeySchemaElement .builder ().attributeName ("secondaryOrganisation" ).keyType (KeyType .RANGE ).build ()
82
- )
83
- )
84
- .attributeDefinitions (
85
- AttributeDefinition .builder ().attributeName ("organisationId" ).attributeType (ScalarAttributeType .S ).build (),
86
- AttributeDefinition .builder ().attributeName ("id" ).attributeType (ScalarAttributeType .S ).build (),
87
- AttributeDefinition .builder ().attributeName ("secondaryGlobal" ).attributeType (ScalarAttributeType .S ).build (),
88
- AttributeDefinition .builder ().attributeName ("secondaryOrganisation" ).attributeType (ScalarAttributeType .S ).build (),
89
- AttributeDefinition .builder ().attributeName ("parallelHash" ).attributeType (ScalarAttributeType .S ).build ()
90
- )
91
- .provisionedThroughput (p -> p .readCapacityUnits (10L ).writeCapacityUnits (10L ).build ())
92
- );
95
+ }
93
96
}
94
97
95
98
static void createHistoryTable (final DynamoDbClient client , final String name ) throws ExecutionException , InterruptedException {
0 commit comments