Example #1
0
        public async Task InitializeAsync(CancellationToken ct = default)
        {
            await cosmosClient.CreateDatabaseIfNotExistsAsync(new Database { Id = DatabaseId });

            await cosmosClient.CreateDocumentCollectionIfNotExistsAsync(databaseUri,
                                                                        new DocumentCollection
            {
                PartitionKey = new PartitionKeyDefinition
                {
                    Paths = new Collection <string>
                    {
                        "/id"
                    }
                },
                Id = Constants.LeaseCollection
            });

            await cosmosClient.CreateDocumentCollectionIfNotExistsAsync(databaseUri,
                                                                        new DocumentCollection
            {
                PartitionKey = new PartitionKeyDefinition
                {
                    Paths = new Collection <string>
                    {
                        "/eventStream"
                    }
                },
                IndexingPolicy = new IndexingPolicy
                {
                    IncludedPaths = new Collection <IncludedPath>
                    {
                        new IncludedPath
                        {
                            Path    = "/*",
                            Indexes = new Collection <Index>
                            {
                                Index.Range(DataType.Number),
                                Index.Range(DataType.String)
                            }
                        }
                    }
                },
                UniqueKeyPolicy = new UniqueKeyPolicy
                {
                    UniqueKeys = new Collection <UniqueKey>
                    {
                        new UniqueKey
                        {
                            Paths = new Collection <string>
                            {
                                "/eventStream",
                                "/eventStreamOffset"
                            }
                        }
                    }
                },
                Id = Constants.Collection
            },
                                                                        new RequestOptions
            {
                PartitionKey = new PartitionKey("/eventStream")
            });
        }