public async Task SC00_MigrateDB() { CosmosClient client = new CosmosClient(EndpointUrl, AuthorizationKey); await client.CreateDatabaseIfNotExistsAsync(DatabaseId, ThroughputProperties.CreateManualThroughput(400)); Database database = client.GetDatabase(DatabaseId); await database.DefineContainer("events", "/stream/id").CreateIfNotExistsAsync(); await database.DefineContainer("leases", "/id").CreateIfNotExistsAsync(); await database.DefineContainer("views", "/id").CreateIfNotExistsAsync(); await database.DefineContainer("snapshots", "/id").CreateIfNotExistsAsync(); StoredProcedureProperties storedProcedureProperties = new StoredProcedureProperties { Id = "spAppendToStream", Body = File.ReadAllText("js/spAppendToStream.js") }; Container eventsContainer = database.GetContainer("events"); try { await eventsContainer.Scripts.DeleteStoredProcedureAsync("spAppendToStream"); } catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { // Stored procedure didn't exist yet. } await eventsContainer.Scripts.CreateStoredProcedureAsync(storedProcedureProperties); }
public async Task SC00_CreateDB() { CosmosClient client = new CosmosClient(EndpointUrl, AuthorizationKey); await client.CreateDatabaseIfNotExistsAsync(DatabaseId, ThroughputProperties.CreateManualThroughput(400)); Database database = client.GetDatabase(DatabaseId); await database.DefineContainer(_eventsContainerId, "/stream/id").CreateIfNotExistsAsync(); await database.DefineContainer(_newEventsContainerId, "/stream/id").CreateIfNotExistsAsync(); await database.DefineContainer(_leaseContainerId, "/id").CreateIfNotExistsAsync(); await database.DefineContainer(_viewsContainerId, "/id").CreateIfNotExistsAsync(); await database.DefineContainer(_snapshotContainerId, "/id").CreateIfNotExistsAsync(); await AddStoredProc(database, _eventsContainerId); await AddStoredProc(database, _newEventsContainerId); }