// This is a sequenced migration. On a new schemas this is complete after UpdateFrom2. public int Create() { SchemaBuilder.CreateMapIndexTable <UserIndex>(table => table .Column <string>("NormalizedUserName") // TODO These should have defaults. on SQL Server they will fall at 255. Exceptions are currently thrown if you go over that. .Column <string>("NormalizedEmail") .Column <bool>("IsEnabled", c => c.NotNull().WithDefault(true)) .Column <string>("UserId") ); SchemaBuilder.AlterTable(nameof(UserIndex), table => table .CreateIndex("IDX_UserIndex_IsEnabled", "DocumentId", "IsEnabled") ); SchemaBuilder.AlterTable(nameof(UserIndex), table => table .CreateIndex("IDX_UserIndex_UserId", "DocumentId", "UserId") ); SchemaBuilder.AlterTable(nameof(UserIndex), table => table // This index will be used for lookups when logging in. .CreateIndex("IDX_UserIndex_UserName", "DocumentId", "NormalizedUserName") ); SchemaBuilder.AlterTable(nameof(UserIndex), table => table .CreateIndex("IDX_UserIndex_Email", "DocumentId", "NormalizedEmail") ); SchemaBuilder.CreateReduceIndexTable <UserByRoleNameIndex>(table => table .Column <string>("RoleName") .Column <int>("Count") ); return(UpdateFrom1()); }
public async Task ShouldCreateHashedIndexKeyName() { await _store.InitializeCollectionAsync("LongCollection"); using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) { await connection.OpenAsync(); using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel)) { var builder = new SchemaBuilder(_store.Configuration, transaction); // tpFK_LongCollection_PersonsByNameCol_LongCollection_Document_Id : 64 chars. Throws exception if not hashed. builder.CreateReduceIndexTable <PersonsByNameCol>(column => column .Column <string>(nameof(PersonsByNameCol.Name)) .Column <int>(nameof(PersonsByNameCol.Count)), "LongCollection" ); transaction.Commit(); } using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel)) { var builder = new SchemaBuilder(_store.Configuration, transaction); builder.DropReduceIndexTable <PersonsByNameCol>("LongCollection"); transaction.Commit(); } } }
static async Task BuildDatabase(IStore store) { await store.InitializeAsync(); using (var session = store.CreateSession()) { var builder = new SchemaBuilder(session); builder.CreateMapIndexTable(nameof(BlogPostByAuthor), table => { table.Column <string>(nameof(BlogPostByAuthor.Author)); table.Column <string>(nameof(BlogPostByAuthor.Title)); }); builder.CreateMapIndexTable(nameof(BlogPostByTag), table => { table.Column <string>(nameof(BlogPostByTag.Tag)); }); builder.CreateReduceIndexTable(nameof(BlogPostByMonth), table => { table.Column <string>(nameof(BlogPostByMonth.PublishedMonth)); table.Column <int>(nameof(BlogPostByMonth.Count)); }); } }
public async Task ShouldCreateHashedIndexKeyName() { // NB: Postgres will not throw here when the key is too long. It will simply truncate it. // This will cause exceptions in other tables when the 'short' key is truncated again. await _store.InitializeCollectionAsync("LongCollection"); using (var connection = _store.Configuration.ConnectionFactory.CreateConnection()) { await connection.OpenAsync(); using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel)) { var builder = new SchemaBuilder(_store.Configuration, transaction); builder.CreateReduceIndexTable <PersonsByNameCol>(column => column .Column <string>(nameof(PersonsByNameCol.Name)) .Column <int>(nameof(PersonsByNameCol.Count)), "LongCollection" ); transaction.Commit(); } using (var transaction = connection.BeginTransaction(_store.Configuration.IsolationLevel)) { var builder = new SchemaBuilder(_store.Configuration, transaction); builder.DropReduceIndexTable <PersonsByNameCol>("LongCollection"); transaction.Commit(); } } }
public int Create() { SchemaBuilder.CreateMapIndexTable(nameof(UserIndex), table => table .Column <string>("NormalizedUserName") .Column <string>("NormalizedEmail") ); SchemaBuilder.CreateReduceIndexTable(nameof(UserByRoleNameIndex), table => table .Column <string>("RoleName") .Column <int>("Count") ); return(UpdateFrom1()); }
public int Create() { SchemaBuilder.CreateMapIndexTable <OpenIdApplicationIndex>(table => table .Column <string>(nameof(OpenIdApplicationIndex.ApplicationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdApplicationIndex.ClientId), column => column.Unique())); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByLogoutUriIndex>(table => table .Column <string>(nameof(OpenIdAppByLogoutUriIndex.LogoutRedirectUri)) .Column <int>(nameof(OpenIdAppByLogoutUriIndex.Count))); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRedirectUriIndex>(table => table .Column <string>(nameof(OpenIdAppByRedirectUriIndex.RedirectUri)) .Column <int>(nameof(OpenIdAppByRedirectUriIndex.Count))); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRoleNameIndex>(table => table .Column <string>(nameof(OpenIdAppByRoleNameIndex.RoleName)) .Column <int>(nameof(OpenIdAppByRoleNameIndex.Count))); SchemaBuilder.CreateMapIndexTable <OpenIdAuthorizationIndex>(table => table .Column <string>(nameof(OpenIdAuthorizationIndex.AuthorizationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdAuthorizationIndex.ApplicationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdAuthorizationIndex.Status)) .Column <string>(nameof(OpenIdAuthorizationIndex.Subject)) .Column <string>(nameof(OpenIdAuthorizationIndex.Type))); SchemaBuilder.CreateMapIndexTable <OpenIdScopeIndex>(table => table .Column <string>(nameof(OpenIdScopeIndex.Name), column => column.Unique()) .Column <string>(nameof(OpenIdScopeIndex.ScopeId), column => column.WithLength(48))); SchemaBuilder.CreateReduceIndexTable <OpenIdScopeByResourceIndex>(table => table .Column <string>(nameof(OpenIdScopeByResourceIndex.Resource)) .Column <int>(nameof(OpenIdScopeByResourceIndex.Count))); SchemaBuilder.CreateMapIndexTable <OpenIdTokenIndex>(table => table .Column <string>(nameof(OpenIdTokenIndex.TokenId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdTokenIndex.ApplicationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdTokenIndex.AuthorizationId), column => column.WithLength(48)) .Column <DateTimeOffset>(nameof(OpenIdTokenIndex.ExpirationDate)) .Column <string>(nameof(OpenIdTokenIndex.ReferenceId)) .Column <string>(nameof(OpenIdTokenIndex.Status)) .Column <string>(nameof(OpenIdTokenIndex.Subject)) .Column <string>(nameof(OpenIdTokenIndex.Type))); return(3); }
public int Create() { SchemaBuilder.CreateMapIndexTable(nameof(OpenIdApplicationIndex), table => table .Column <string>(nameof(OpenIdApplicationIndex.ClientId)) .Column <string>(nameof(OpenIdApplicationIndex.LogoutRedirectUri)) ); SchemaBuilder.CreateReduceIndexTable(nameof(OpenIdApplicationByRoleNameIndex), table => table .Column <string>(nameof(OpenIdApplicationByRoleNameIndex.RoleName)) .Column <int>(nameof(OpenIdApplicationByRoleNameIndex.Count)) ); SchemaBuilder.CreateMapIndexTable(nameof(OpenIdTokenIndex), table => table .Column <int>(nameof(OpenIdTokenIndex.AppId)) .Column <string>(nameof(OpenIdTokenIndex.Subject)) .Column <int>(nameof(OpenIdTokenIndex.TokenId))); return(1); }
public int UpdateFrom2() { SchemaBuilder.DropReduceIndexTable <OpenIdApplicationByPostLogoutRedirectUriIndex>(null); SchemaBuilder.DropReduceIndexTable <OpenIdApplicationByRedirectUriIndex>(null); SchemaBuilder.DropReduceIndexTable <OpenIdApplicationByRoleNameIndex>(null); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByLogoutUriIndex>(table => table .Column <string>(nameof(OpenIdAppByLogoutUriIndex.LogoutRedirectUri)) .Column <int>(nameof(OpenIdAppByLogoutUriIndex.Count))); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRedirectUriIndex>(table => table .Column <string>(nameof(OpenIdAppByRedirectUriIndex.RedirectUri)) .Column <int>(nameof(OpenIdAppByRedirectUriIndex.Count))); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRoleNameIndex>(table => table .Column <string>(nameof(OpenIdAppByRoleNameIndex.RoleName)) .Column <int>(nameof(OpenIdAppByRoleNameIndex.Count))); return(3); }
// This code can be removed in a later version. public async Task <int> UpdateFrom7Async() { // Create all index tables with the new collection value. SchemaBuilder.CreateMapIndexTable <OpenIdApplicationIndex>(table => table .Column <string>(nameof(OpenIdApplicationIndex.ApplicationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdApplicationIndex.ClientId), column => column.Unique()), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdApplicationIndex>(table => table .CreateIndex("IDX_COL_OpenIdApplication", "DocumentId", nameof(OpenIdApplicationIndex.ApplicationId), nameof(OpenIdApplicationIndex.ClientId)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByLogoutUriIndex>(table => table .Column <string>(nameof(OpenIdAppByLogoutUriIndex.LogoutRedirectUri)) .Column <int>(nameof(OpenIdAppByLogoutUriIndex.Count)), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdAppByLogoutUriIndex>(table => table .CreateIndex("IDX_COL_OpenIdAppByLogoutUri_LogoutRedirectUri", nameof(OpenIdAppByLogoutUriIndex.LogoutRedirectUri)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRedirectUriIndex>(table => table .Column <string>(nameof(OpenIdAppByRedirectUriIndex.RedirectUri)) .Column <int>(nameof(OpenIdAppByRedirectUriIndex.Count)), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdAppByRedirectUriIndex>(table => table .CreateIndex("IDX_COL_OpenIdAppByRedirectUri_RedirectUri", nameof(OpenIdAppByRedirectUriIndex.RedirectUri)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRoleNameIndex>(table => table .Column <string>(nameof(OpenIdAppByRoleNameIndex.RoleName)) .Column <int>(nameof(OpenIdAppByRoleNameIndex.Count)), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdAppByRoleNameIndex>(table => table .CreateIndex("IDX_COL_OpenIdAppByRoleName_RoleName", nameof(OpenIdAppByRoleNameIndex.RoleName)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateMapIndexTable <OpenIdScopeIndex>(table => table .Column <string>(nameof(OpenIdScopeIndex.Name), column => column.Unique()) .Column <string>(nameof(OpenIdScopeIndex.ScopeId), column => column.WithLength(48)), collection: OpenIdScopeCollection); SchemaBuilder.AlterIndexTable <OpenIdScopeIndex>(table => table .CreateIndex("IDX_COL_OpenIdScope", "DocumentId", nameof(OpenIdScopeIndex.Name), nameof(OpenIdScopeIndex.ScopeId)), collection: OpenIdScopeCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdScopeByResourceIndex>(table => table .Column <string>(nameof(OpenIdScopeByResourceIndex.Resource)) .Column <int>(nameof(OpenIdScopeByResourceIndex.Count)), collection: OpenIdScopeCollection); SchemaBuilder.AlterIndexTable <OpenIdScopeByResourceIndex>(table => table .CreateIndex("IDX_COL_OpenIdScopeByResource_Resource", nameof(OpenIdScopeByResourceIndex.Resource)), collection: OpenIdScopeCollection ); // Retrieve all existing applications and scopes from original Document table. var applications = await _session.Query <OpenIdApplication>().ListAsync(); var scopes = await _session.Query <OpenIdScope>().ListAsync(); // Enlist the old documents in the new collection and remove from the old collections. foreach (var application in applications) { // Set the id to 0 or it will be considered an updated entity. application.Id = 0; _session.Save(application, collection: OpenIdApplicationCollection); // Delete from the original collection. _session.Delete(application); } // Enlist the old documents in the new collection and remove from the old collections. foreach (var scope in scopes) { // Set the id to 0 or it will be considered an updated entity. scope.Id = 0; _session.Save(scope, collection: OpenIdScopeCollection); // Delete from the original collection. _session.Delete(scope); } // Flush the saved documents so that the old reduced indexes will be calculated // and commited to the transaction before they are then dropped. await _session.FlushAsync(); // These can be safely dropped after flushing. SchemaBuilder.DropMapIndexTable <OpenIdApplicationIndex>(); SchemaBuilder.DropReduceIndexTable <OpenIdAppByLogoutUriIndex>(); SchemaBuilder.DropReduceIndexTable <OpenIdAppByRedirectUriIndex>(); SchemaBuilder.DropReduceIndexTable <OpenIdAppByRoleNameIndex>(); SchemaBuilder.DropMapIndexTable <OpenIdScopeIndex>(); SchemaBuilder.DropReduceIndexTable <OpenIdScopeByResourceIndex>(); return(8); }
public int Create() { SchemaBuilder.CreateMapIndexTable <OpenIdApplicationIndex>(table => table .Column <string>(nameof(OpenIdApplicationIndex.ApplicationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdApplicationIndex.ClientId), column => column.Unique()), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdApplicationIndex>(table => table .CreateIndex("IDX_COL_OpenIdApplication", "DocumentId", nameof(OpenIdApplicationIndex.ApplicationId), nameof(OpenIdApplicationIndex.ClientId)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByLogoutUriIndex>(table => table .Column <string>(nameof(OpenIdAppByLogoutUriIndex.LogoutRedirectUri)) .Column <int>(nameof(OpenIdAppByLogoutUriIndex.Count)), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdAppByLogoutUriIndex>(table => table .CreateIndex("IDX_COL_OpenIdAppByLogoutUri_LogoutRedirectUri", nameof(OpenIdAppByLogoutUriIndex.LogoutRedirectUri)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRedirectUriIndex>(table => table .Column <string>(nameof(OpenIdAppByRedirectUriIndex.RedirectUri)) .Column <int>(nameof(OpenIdAppByRedirectUriIndex.Count)), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdAppByRedirectUriIndex>(table => table .CreateIndex("IDX_COL_OpenIdAppByRedirectUri_RedirectUri", nameof(OpenIdAppByRedirectUriIndex.RedirectUri)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdAppByRoleNameIndex>(table => table .Column <string>(nameof(OpenIdAppByRoleNameIndex.RoleName)) .Column <int>(nameof(OpenIdAppByRoleNameIndex.Count)), collection: OpenIdApplicationCollection); SchemaBuilder.AlterIndexTable <OpenIdAppByRoleNameIndex>(table => table .CreateIndex("IDX_COL_OpenIdAppByRoleName_RoleName", nameof(OpenIdAppByRoleNameIndex.RoleName)), collection: OpenIdApplicationCollection ); SchemaBuilder.CreateMapIndexTable <OpenIdAuthorizationIndex>(table => table .Column <string>(nameof(OpenIdAuthorizationIndex.AuthorizationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdAuthorizationIndex.ApplicationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdAuthorizationIndex.Status)) .Column <string>(nameof(OpenIdAuthorizationIndex.Subject)) .Column <string>(nameof(OpenIdAuthorizationIndex.Type)) .Column <DateTime>(nameof(OpenIdAuthorizationIndex.CreationDate)), collection: OpenIdAuthorizationCollection); SchemaBuilder.AlterIndexTable <OpenIdAuthorizationIndex>(table => table .CreateIndex("IDX_COL_OpenIdAuthorization_ApplicationId", "DocumentId", nameof(OpenIdAuthorizationIndex.ApplicationId), nameof(OpenIdAuthorizationIndex.Status), nameof(OpenIdAuthorizationIndex.Subject)), collection: OpenIdAuthorizationCollection ); SchemaBuilder.AlterIndexTable <OpenIdAuthorizationIndex>(table => table .CreateIndex("IDX_COL_OpenIdAuthorization_AuthorizationId", "DocumentId", nameof(OpenIdAuthorizationIndex.AuthorizationId), nameof(OpenIdAuthorizationIndex.Status), nameof(OpenIdAuthorizationIndex.Type), nameof(OpenIdAuthorizationIndex.CreationDate)), collection: OpenIdAuthorizationCollection ); SchemaBuilder.CreateMapIndexTable <OpenIdScopeIndex>(table => table .Column <string>(nameof(OpenIdScopeIndex.Name), column => column.Unique()) .Column <string>(nameof(OpenIdScopeIndex.ScopeId), column => column.WithLength(48)), collection: OpenIdScopeCollection); SchemaBuilder.AlterIndexTable <OpenIdScopeIndex>(table => table .CreateIndex("IDX_COL_OpenIdScope", "DocumentId", nameof(OpenIdScopeIndex.Name), nameof(OpenIdScopeIndex.ScopeId)), collection: OpenIdScopeCollection ); SchemaBuilder.CreateReduceIndexTable <OpenIdScopeByResourceIndex>(table => table .Column <string>(nameof(OpenIdScopeByResourceIndex.Resource)) .Column <int>(nameof(OpenIdScopeByResourceIndex.Count)), collection: OpenIdScopeCollection); SchemaBuilder.AlterIndexTable <OpenIdScopeByResourceIndex>(table => table .CreateIndex("IDX_COL_OpenIdScopeByResource_Resource", nameof(OpenIdScopeByResourceIndex.Resource)), collection: OpenIdScopeCollection ); SchemaBuilder.CreateMapIndexTable <OpenIdTokenIndex>(table => table .Column <string>(nameof(OpenIdTokenIndex.TokenId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdTokenIndex.ApplicationId), column => column.WithLength(48)) .Column <string>(nameof(OpenIdTokenIndex.AuthorizationId), column => column.WithLength(48)) .Column <DateTime>(nameof(OpenIdTokenIndex.ExpirationDate)) .Column <string>(nameof(OpenIdTokenIndex.ReferenceId)) .Column <string>(nameof(OpenIdTokenIndex.Status)) .Column <string>(nameof(OpenIdTokenIndex.Subject)) .Column <string>(nameof(OpenIdTokenIndex.Type)) .Column <DateTime>(nameof(OpenIdTokenIndex.CreationDate)), collection: OpenIdTokenCollection); SchemaBuilder.AlterIndexTable <OpenIdTokenIndex>(table => table .CreateIndex("IDX_COL_OpenIdToken_ApplicationId", "DocumentId", nameof(OpenIdTokenIndex.ApplicationId), nameof(OpenIdTokenIndex.Status), nameof(OpenIdTokenIndex.Subject)), collection: OpenIdTokenCollection ); SchemaBuilder.AlterIndexTable <OpenIdTokenIndex>(table => table .CreateIndex("IDX_COL_OpenIdToken_AuthorizationId", "DocumentId", nameof(OpenIdTokenIndex.AuthorizationId), nameof(OpenIdTokenIndex.Status), nameof(OpenIdTokenIndex.Type), nameof(OpenIdTokenIndex.CreationDate), nameof(OpenIdTokenIndex.ExpirationDate)), collection: OpenIdTokenCollection ); SchemaBuilder.AlterIndexTable <OpenIdTokenIndex>(table => table .CreateIndex("IDX_COL_OpenIdToken_TokenId", "DocumentId", nameof(OpenIdTokenIndex.TokenId), nameof(OpenIdTokenIndex.ReferenceId)), collection: OpenIdTokenCollection ); // Shortcut other migration steps on new content definition schemas. return(8); }
// This is a sequenced migration. On a new schemas this is complete after UpdateFrom2. public int Create() { SchemaBuilder.CreateMapIndexTable <UserIndex>(table => table .Column <string>("NormalizedUserName") // TODO These should have defaults. on SQL Server they will fall at 255. Exceptions are currently thrown if you go over that. .Column <string>("NormalizedEmail") .Column <bool>("IsEnabled", c => c.NotNull().WithDefault(true)) .Column <bool>("IsLockoutEnabled", c => c.NotNull().WithDefault(false)) .Column <DateTime?>("LockoutEndUtc", c => c.Nullable()) .Column <int>("AccessFailedCount", c => c.NotNull().WithDefault(0)) .Column <string>("UserId") ); SchemaBuilder.AlterIndexTable <UserIndex>(table => table .CreateIndex("IDX_UserIndex_DocumentId", "DocumentId", "UserId", "NormalizedUserName", "NormalizedEmail", "IsEnabled" ) ); SchemaBuilder.AlterIndexTable <UserIndex>(table => table .CreateIndex("IDX_UserIndex_Lockout", "DocumentId", "IsLockoutEnabled", "LockoutEndUtc", "AccessFailedCount" ) ); SchemaBuilder.CreateReduceIndexTable <UserByRoleNameIndex>(table => table .Column <string>("RoleName") .Column <int>("Count") ); SchemaBuilder.AlterIndexTable <UserByRoleNameIndex>(table => table .CreateIndex("IDX_UserByRoleNameIndex_RoleName", "RoleName") ); SchemaBuilder.CreateMapIndexTable <UserByLoginInfoIndex>(table => table .Column <string>("LoginProvider") .Column <string>("ProviderKey")); SchemaBuilder.AlterIndexTable <UserByLoginInfoIndex>(table => table .CreateIndex("IDX_UserByLoginInfoIndex_DocumentId", "DocumentId", "LoginProvider", "ProviderKey") ); SchemaBuilder.CreateMapIndexTable <UserByClaimIndex>(table => table .Column <string>(nameof(UserByClaimIndex.ClaimType)) .Column <string>(nameof(UserByClaimIndex.ClaimValue)), null); SchemaBuilder.AlterIndexTable <UserByClaimIndex>(table => table .CreateIndex("IDX_UserByClaimIndex_DocumentId", "DocumentId", nameof(UserByClaimIndex.ClaimType), nameof(UserByClaimIndex.ClaimValue)) ); // Shortcut other migration steps on new content definition schemas. return(12); }