Skip to content

Commit 4ca36df

Browse files
committed
Provision -> UpdateTableIfRequired refactor
1 parent 0858c5b commit 4ca36df

File tree

4 files changed

+72
-59
lines changed

4 files changed

+72
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type Counter private (table : TableContext<CounterEntry>, key : TableKey) =
120120
static member Create(client : IAmazonDynamoDB, tableName : string) = async {
121121
let table = TableContext<CounterEntry>(client, tableName)
122122
let throughput = ProvisionedThroughput(readCapacityUnits = 10L, writeCapacityUnits = 10L)
123-
do! table.CreateTableIfNotExistsAsync(Throughput.Provisioned throughput)
123+
do! table.VerifyOrCreateTableAsync(Throughput.Provisioned throughput)
124124
let initialEntry = { Id = Guid.NewGuid() ; Value = 0L }
125125
let! key = table.PutItemAsync(initialEntry)
126126
return Counter(table, key)

RELEASE_NOTES.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
* Added `TryGetItemAsync` (same as `GetItemAsync`, but returns `None`, instead of throwing, if an item is not present)
66
* Switched test framework to Xunit, assertions to Unquote, runner to `dotnet test`
77
* Clarified Creation/Verification APIs:
8-
* Obsoleted `TableContext.Create` (replace with `TableContext.Scripting.Initialize`, `TableContext.CreateTableIfNotExistsAsync`, `TableContext.VerifyTableAsync`)
8+
* Obsoleted `TableContext.Create` (replace with `TableContext.Scripting.Initialize`, `TableContext.VerifyOrCreateTableAsync`, `TableContext.VerifyTableAsync`)
99
* Added `TableContext` constructor (replaces `TableContext.Create(verifyTable = false)`)
1010
* Added `TableContext.Scripting.Initialize` (replaces `TableContext.Create()`)
1111
* Added `TableContext.VerifyTableAsync` overload that only performs verification but never creates a Table
12-
* Added `TableContext.CreateTableIfNotExistsAsync` (replaces `TableContext.VerifyTableAsync(createIfNotExists = true)`)
13-
* Added `TableContext.ProvisionTableAsync` (as per `CreateTableIfNotExistsAsync` but does an `UpdateTableAsync` if `throughput` or `streaming` has changed)
14-
* Added Support for `Throughput.OnDemand` mode (sets `BillingMode` to `PAY_PER_REQUEST` rather than attempting to configure a `ProvisionedThroughput`)
15-
* Added ability to configure DynamoDB streaming (via `Streaming` DU) to `CreateTableIfNotExistsAsync` and `ProvisionTableAsync`
16-
* Removed `TableContext.CreateAsync` (replace with `TableContext.VerifyTableAsync` or `CreateTableIfNotExistsAsync`)
12+
* Added `TableContext.VerifyOrCreateTableAsync` (replaces `TableContext.VerifyTableAsync(createIfNotExists = true)`)
13+
* Added `TableContext.UpdateTableIfRequiredAsync` (conditional `UpdateTableAsync` to establish specified `throughput` or `streaming` only if required)
14+
* Added `Throughput.OnDemand` mode (sets `BillingMode` to `PAY_PER_REQUEST` rather than attempting to configure a `ProvisionedThroughput`)
15+
* Added ability to configure DynamoDB streaming (via `Streaming` DU) to `VerifyOrCreateTableAsync` and `UpdateTableIfRequiredAsync`
16+
* Removed `TableContext.CreateAsync` (replace with `TableContext.VerifyTableAsync` or `VerifyOrCreateTableAsync`)
1717
* Replaced `TableKeySchemata.CreateCreateTableRequest` with `ApplyToCreateTableRequest`
1818

1919
### 0.9.3-beta

src/FSharp.AWS.DynamoDB/Script.fsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type EasyCounters private (table : TableContext<CounterEntry>) =
128128
// Create the table if necessary. Verifies schema is correct if it has already been created
129129
// NOTE the hard coded initial throughput provisioning - arguably this belongs outside of your application logic
130130
let throughput = ProvisionedThroughput(readCapacityUnits = 10L, writeCapacityUnits = 10L)
131-
do! table.CreateTableIfNotExistsAsync(Throughput.Provisioned throughput)
131+
do! table.VerifyOrCreateTableAsync(Throughput.Provisioned throughput)
132132
return EasyCounters(table)
133133
}
134134

@@ -138,16 +138,21 @@ type EasyCounters private (table : TableContext<CounterEntry>) =
138138
/// Variant of EasyCounters that splits the provisioning step from the (optional) validation that the table is present
139139
type SimpleCounters private (table : TableContext<CounterEntry>) =
140140

141-
static member Provision(client : IAmazonDynamoDB, tableName : string, readCapacityUnits, writeCapacityUnits) : Async<unit> =
141+
static member Provision(client : IAmazonDynamoDB, tableName : string, readCapacityUnits, writeCapacityUnits) : Async<unit> = async {
142142
let table = TableContext<CounterEntry>(client, tableName)
143-
// normally, RCU/WCU provisioning only happens first time the Table is created and is then considered an external concern
144-
// here we use `ProvisionTableAsync` instead of `CreateTableIfNotExistsAsync` to reset it each time we deploy the app
145143
let provisionedThroughput = ProvisionedThroughput(readCapacityUnits, writeCapacityUnits)
146-
table.ProvisionTableAsync(Throughput.Provisioned provisionedThroughput)
144+
let throughput = Throughput.Provisioned provisionedThroughput
145+
// normally, RCU/WCU provisioning only happens first time the Table is created and is then considered an external concern
146+
// here we use `UpdateTableIfRequiredAsync` to reset it each time we deploy the app
147+
do! table.VerifyOrCreateTableAsync(throughput)
148+
do! table.UpdateTableIfRequiredAsync(throughput) }
147149

148-
static member ProvisionOnDemand(client : IAmazonDynamoDB, tableName : string) : Async<unit> =
150+
static member ProvisionOnDemand(client : IAmazonDynamoDB, tableName : string) : Async<unit> = async {
149151
let table = TableContext<CounterEntry>(client, tableName)
150-
table.ProvisionTableAsync(Throughput.OnDemand)
152+
let throughput = Throughput.OnDemand
153+
do! table.VerifyOrCreateTableAsync(throughput)
154+
// as per the Provision, above, we reset to OnDemand, if it got reconfigured since it was originally created
155+
do! table.UpdateTableIfRequiredAsync(throughput) }
151156

152157
/// We only want to do the initialization bit once per instance of our application
153158
/// Similar to EasyCounters.Create in that it ensures the table is provisioned correctly

0 commit comments

Comments
 (0)