Skip to content

Commit

Permalink
InitializeAsync -> CreateTableIfNotExistsAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Apr 7, 2022
1 parent 987f98b commit 5ae2300
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type Counter private (table : TableContext<CounterEntry>, key : TableKey) =
static member Create(client : IAmazonDynamoDB, tableName : string) = async {
let table = TableContext<CounterEntry>(client, tableName)
let throughput = ProvisionedThroughput(readCapacityUnits = 10L, writeCapacityUnits = 10L)
do! table.InitializeTableAsync(Throughput.Provisioned throughput)
do! table.CreateTableIfNotExistsAsync(Throughput.Provisioned throughput)
let initialEntry = { Id = Guid.NewGuid() ; Value = 0L }
let! key = table.PutItemAsync(initialEntry)
return Counter(table, key)
Expand Down
10 changes: 5 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* Added `TryGetItemAsync` (same as `GetItemAsync`, but returns `None`, instead of throwing, if an item is not present)
* Switched test framework to Xunit, assertions to Unquote, runner to `dotnet test`
* Clarified Creation/Verification APIs:
* Obsoleted `TableContext.Create` (replace with `TableContext.Scripting.Initialize` and/or `TableContext.InitializeTableAsync`)
* Obsoleted `TableContext.Create` (replace with `TableContext.Scripting.Initialize`, `TableContext.CreateTableIfNotExistsAsync`, `TableContext.VerifyTableAsync`)
* Added `TableContext` constructor (replaces `TableContext.Create(verifyTable = false)`)
* Added `TableContext.Scripting.Initialize` (replaces `TableContext.Create()`)
* Added `TableContext.VerifyTableAsync` overload that only performs verification but never creates a Table
* Added `TableContext.InitializeTableAsync` (replaces `TableContext.VerifyTableAsync(createIfNotExists = true)`)
* Added `TableContext.ProvisionTableAsync` (as per `InitializeTableAsync` but does an `UpdateTableAsync` if `throughput` or `streaming` has changed)
* Added `TableContext.CreateTableIfNotExistsAsync` (replaces `TableContext.VerifyTableAsync(createIfNotExists = true)`)
* Added `TableContext.ProvisionTableAsync` (as per `CreateTableIfNotExistsAsync` but does an `UpdateTableAsync` if `throughput` or `streaming` has changed)
* Added Support for `Throughput.OnDemand` mode (sets `BillingMode` to `PAY_PER_REQUEST` rather than attempting to configure a `ProvisionedThroughput`)
* Added ability to configure DynamoDB streaming (via `Streaming` DU) to `InitializeTableAsync` and `ProvisionTableAsync`
* Removed `TableContext.CreateAsync` (replace with `TableContext.VerifyTableAsync` or `InitializeTableAsync`)
* Added ability to configure DynamoDB streaming (via `Streaming` DU) to `CreateTableIfNotExistsAsync` and `ProvisionTableAsync`
* Removed `TableContext.CreateAsync` (replace with `TableContext.VerifyTableAsync` or `CreateTableIfNotExistsAsync`)
* Replaced `TableKeySchemata.CreateCreateTableRequest` with `ApplyToCreateTableRequest`

### 0.9.3-beta
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.AWS.DynamoDB/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type EasyCounters private (table : TableContext<CounterEntry>) =
// Create the table if necessary. Verifies schema is correct if it has already been created
// NOTE the hard coded initial throughput provisioning - arguably this belongs outside of your application logic
let throughput = ProvisionedThroughput(readCapacityUnits = 10L, writeCapacityUnits = 10L)
do! table.InitializeTableAsync(Throughput.Provisioned throughput)
do! table.CreateTableIfNotExistsAsync(Throughput.Provisioned throughput)
return EasyCounters(table)
}

Expand All @@ -141,7 +141,7 @@ type SimpleCounters private (table : TableContext<CounterEntry>) =
static member Provision(client : IAmazonDynamoDB, tableName : string, readCapacityUnits, writeCapacityUnits) : Async<unit> =
let table = TableContext<CounterEntry>(client, tableName)
// normally, RCU/WCU provisioning only happens first time the Table is created and is then considered an external concern
// here we use `ProvisionTableAsync` instead of `InitializeTableAsync` to reset it each time we deploy the app
// here we use `ProvisionTableAsync` instead of `CreateTableIfNotExistsAsync` to reset it each time we deploy the app
let provisionedThroughput = ProvisionedThroughput(readCapacityUnits, writeCapacityUnits)
table.ProvisionTableAsync(Throughput.Provisioned provisionedThroughput)

Expand Down
20 changes: 10 additions & 10 deletions src/FSharp.AWS.DynamoDB/TableContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ type TableContext<'TRecord> internal

/// <summary>
/// Creates a DynamoDB client instance for given F# record and table name.<br/>
/// For creating, provisioning or verification, see <c>InitializeTableAsync</c> and <c>VerifyTableAsync</c>.
/// For creating, provisioning or verification, see <c>CreateTableIfNotExistsAsync</c> and <c>VerifyTableAsync</c>.
/// </summary>
/// <param name="client">DynamoDB client instance.</param>
/// <param name="tableName">Table name to target.</param>
Expand Down Expand Up @@ -1017,7 +1017,7 @@ type TableContext<'TRecord> internal

/// <summary>
/// Asynchronously verify that the table exists and is compatible with record key schema, or throw.<br/>
/// See also <c>InitializeTableAsync</c>, which performs the same check, but can create or re-provision the Table if required.
/// See also <c>CreateTableIfNotExistsAsync</c>, which performs the same check, but can create or re-provision the Table if required.
/// </summary>
member _.VerifyTableAsync() : Async<unit> =
Provisioning.validateOnly (client, tableName, template)
Expand All @@ -1027,14 +1027,14 @@ type TableContext<'TRecord> internal

/// <summary>
/// Asynchronously verifies that the table exists and is compatible with record key schema, throwing if it is incompatible.<br/>
/// If the table is not present, it is provisioned, with the specified <c>throughput</c>.<br/>
/// If the table is not present, it is created, with the specified <c>throughput</c>.<br/>
/// See also <c>VerifyTableAsync</c>, which only verifies the Table is present and correct.<br/>
/// See also <c>ProvisionTableAsync</c>, which will adjust throughput and streaming if they are not as specified.
/// </summary>
/// <param name="throughput">Throughput configuration to use for the table.</param>
/// <param name="streaming">Optional streaming configuration to apply for the table. Default: Disabled..</param>
/// <param name="customize">Callback to post-process the <c>CreateTableRequest</c>.</param>
member t.InitializeTableAsync(throughput : Throughput, ?streaming, ?customize) : Async<unit> =
member t.CreateTableIfNotExistsAsync(throughput : Throughput, ?streaming, ?customize) : Async<unit> =
t.InternalCreateOrValidate(throughput, ?streaming = streaming, ?customize = customize) |> Async.Ignore

/// <summary>
Expand Down Expand Up @@ -1074,17 +1074,17 @@ type TableContext<'TRecord> internal
/// <summary>Asynchronously verify that the table exists and is compatible with record key schema.</summary>
/// <param name="createIfNotExists">Create the table instance now instance if it does not exist. Defaults to false.</param>
/// <param name="provisionedThroughput">Provisioned throughput for the table if newly created. Defaults to (10,10).</param>
[<System.Obsolete("Please replace with either 1. VerifyTableAsync or 2. InitializeTableAsync")>]
[<System.Obsolete("Please replace with either 1. VerifyTableAsync or 2. CreateTableIfNotExistsAsync")>]
member t.VerifyTableAsync(?createIfNotExists : bool, ?provisionedThroughput : ProvisionedThroughput) : Async<unit> =
if createIfNotExists = Some true then
let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput(10L, 10L)
t.InitializeTableAsync(Throughput.Provisioned throughput)
t.CreateTableIfNotExistsAsync(Throughput.Provisioned throughput)
else
t.VerifyTableAsync()

// Deprecated factory method, to be removed. Replaced with
// 1. TableContext<'T> ctor (synchronous)
// 2. InitializeTableAsync OR VerifyTableAsync (explicitly async to signify that verification/creation is a costly and/or privileged operation)
// 2. CreateTableIfNotExistsAsync OR VerifyTableAsync (explicitly async to signify that verification/creation is a costly and/or privileged operation)
type TableContext internal () =

/// <summary>
Expand All @@ -1097,7 +1097,7 @@ type TableContext internal () =
/// <param name="provisionedThroughput">Provisioned throughput for the table if newly created. Default: 10 RCU, 10 WCU</param>
/// <param name="metricsCollector">Function to receive request metrics.</param>
[<System.Obsolete(@"Creation with synchronous verification has been deprecated. Please use either
1. TableContext constructor (optionally followed by VerifyTableAsync or InitializeTableAsync) OR
1. TableContext constructor (optionally followed by VerifyTableAsync or CreateTableIfNotExistsAsync) OR
2. (for scripting scenarios) Scripting.TableContext.Initialize")>]
static member Create<'TRecord>
( client : IAmazonDynamoDB, tableName : string, ?verifyTable : bool,
Expand All @@ -1106,7 +1106,7 @@ type TableContext internal () =
let context = TableContext<'TRecord>(client, tableName, ?metricsCollector = metricsCollector)
if createIfNotExists = Some true then
let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput(10L, 10L)
do! context.InitializeTableAsync(Throughput.Provisioned throughput)
do! context.CreateTableIfNotExistsAsync(Throughput.Provisioned throughput)
elif verifyTable <> Some false then
do! context.VerifyTableAsync()
return context }
Expand All @@ -1132,7 +1132,7 @@ module Scripting =
let context = TableContext<'TRecord>(client, tableName, ?metricsCollector = metricsCollector)
match throughput with
| None -> context.VerifyTableAsync() |> Async.RunSynchronously
| Some t -> context.InitializeTableAsync(t) |> Async.RunSynchronously
| Some t -> context.CreateTableIfNotExistsAsync(t) |> Async.RunSynchronously
context

type TableContext<'TRecord> with
Expand Down

0 comments on commit 5ae2300

Please sign in to comment.