diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentEntity.cs b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentEntity.cs index f35cb2286..b9fb687af 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentEntity.cs +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentEntity.cs @@ -24,11 +24,6 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents [BsonId] [BsonRequired] - [BsonElement] - public string DocumentId { get; set; } - - [BsonRequired] - [BsonElement("id")] [BsonRepresentation(BsonType.String)] public Guid Id { get; set; } diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs index 93df9d115..1b4454ed4 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs @@ -54,14 +54,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents var idData = value.Data?.ToIdModel(schema.SchemaDef, true); - var id = key.ToString(); - var document = SimpleMapper.Map(value, new MongoContentEntity { AppIdId = value.AppId.Id, SchemaIdId = value.SchemaId.Id, IsDeleted = value.IsDeleted, - DocumentId = key.ToString(), DataText = idData?.ToFullText(), DataByIds = idData, ReferencedIds = idData?.ToReferencedIds(schema.SchemaDef), @@ -71,14 +68,14 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents try { - await Collection.ReplaceOneAsync(x => x.DocumentId == id && x.Version == oldVersion, document, Upsert); + await Collection.ReplaceOneAsync(x => x.Id == key && x.Version == oldVersion, document, Upsert); } catch (MongoWriteException ex) { if (ex.WriteError.Category == ServerErrorCategory.DuplicateKey) { var existingVersion = - await Collection.Find(x => x.DocumentId == id).Only(x => x.DocumentId, x => x.Version) + await Collection.Find(x => x.Id == key).Only(x => x.Id, x => x.Version) .FirstOrDefaultAsync(); if (existingVersion != null) @@ -91,8 +88,6 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents throw; } } - - document.DocumentId = $"{key}_{newVersion}"; } private async Task GetSchemaAsync(Guid appId, Guid schemaId) diff --git a/src/Squidex/Config/Domain/EntitiesServices.cs b/src/Squidex/Config/Domain/EntitiesServices.cs index e37d1b9ba..854457911 100644 --- a/src/Squidex/Config/Domain/EntitiesServices.cs +++ b/src/Squidex/Config/Domain/EntitiesServices.cs @@ -172,10 +172,7 @@ namespace Squidex.Config.Domain services.AddTransientAs() .As(); - services.AddTransientAs() - .As(); - - services.AddTransientAs() + services.AddTransientAs() .As(); services.AddTransientAs() diff --git a/src/Squidex/Config/Domain/StoreServices.cs b/src/Squidex/Config/Domain/StoreServices.cs index b2592dae5..3e6909af1 100644 --- a/src/Squidex/Config/Domain/StoreServices.cs +++ b/src/Squidex/Config/Domain/StoreServices.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.DataProtection.Repositories; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Migrate_01.Migrations; using MongoDB.Driver; using Squidex.Domain.Apps.Entities; using Squidex.Domain.Apps.Entities.Assets.Repositories; @@ -107,6 +108,12 @@ namespace Squidex.Config.Domain .As>() .As() .As(); + + services.AddTransientAs(c => new DeleteArchiveCollectionSetup(mongoContentDatabase)) + .As(); + + services.AddTransientAs() + .As(); } }); diff --git a/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs b/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs index 2e4b36aa2..9f92da4da 100644 --- a/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs +++ b/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs @@ -79,7 +79,7 @@ namespace Squidex.Pipeline.Swagger public static SwaggerSecurityScheme CreateOAuthSchema(MyUrlsOptions urlOptions) { - var tokenUrl = urlOptions.BuildUrl($"{Constants.IdentityServerPrefix}/connect/token"); + var tokenUrl = urlOptions.BuildUrl($"{Constants.IdentityServerPrefix}/connect/token", false); var securityDocs = LoadDocs("security"); var securityText = securityDocs.Replace("", tokenUrl); diff --git a/tools/Migrate_01/MigrationPath.cs b/tools/Migrate_01/MigrationPath.cs index ce17926c9..4fa33b273 100644 --- a/tools/Migrate_01/MigrationPath.cs +++ b/tools/Migrate_01/MigrationPath.cs @@ -15,7 +15,7 @@ namespace Migrate_01 { public sealed class MigrationPath : IMigrationPath { - private const int CurrentVersion = 9; + private const int CurrentVersion = 10; private readonly IServiceProvider serviceProvider; public MigrationPath(IServiceProvider serviceProvider) @@ -32,6 +32,17 @@ namespace Migrate_01 var migrations = new List(); + // Version 10: Delete old archive fields + if (version < 10) + { + var migration = serviceProvider.GetService(); + + if (migration != null) + { + migrations.Add(migration); + } + } + // Version 6: Convert Event store. Must always be executed first. if (version < 6) { @@ -53,7 +64,13 @@ namespace Migrate_01 // Version 9: Grain Indexes if (version < 9) { - migrations.Add(serviceProvider.GetRequiredService()); + var migration = serviceProvider.GetService(); + + if (migration != null) + { + migrations.Add(migration); + } + migrations.Add(serviceProvider.GetRequiredService()); } @@ -66,7 +83,7 @@ namespace Migrate_01 // Version 8: Introduce Archive collection. if (version < 8) { - migrations.Add(serviceProvider.GetRequiredService()); + migrations.Add(serviceProvider.GetRequiredService()); } return (CurrentVersion, migrations); diff --git a/tools/Migrate_01/Migrations/DeleteArchiveCollectionSetup.cs b/tools/Migrate_01/Migrations/DeleteArchiveCollectionSetup.cs new file mode 100644 index 000000000..02b6d2608 --- /dev/null +++ b/tools/Migrate_01/Migrations/DeleteArchiveCollectionSetup.cs @@ -0,0 +1,32 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.Threading.Tasks; +using MongoDB.Bson; +using MongoDB.Driver; +using Squidex.Infrastructure.Migrations; + +namespace Migrate_01.Migrations +{ + public sealed class DeleteArchiveCollectionSetup : IMigration + { + private readonly IMongoDatabase database; + + public DeleteArchiveCollectionSetup(IMongoDatabase database) + { + this.database = database; + } + + public async Task UpdateAsync() + { + var collection = database.GetCollection("States_Contents"); + + await collection.Indexes.DropAllAsync(); + await collection.UpdateManyAsync(new BsonDocument(), Builders.Update.Unset("id")); + } + } +}