Browse Source

Remove old archive stuff.

pull/283/head
Sebastian 8 years ago
parent
commit
2edb2ddbc0
  1. 5
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentEntity.cs
  2. 9
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs
  3. 5
      src/Squidex/Config/Domain/EntitiesServices.cs
  4. 7
      src/Squidex/Config/Domain/StoreServices.cs
  5. 2
      src/Squidex/Pipeline/Swagger/SwaggerHelper.cs
  6. 23
      tools/Migrate_01/MigrationPath.cs
  7. 32
      tools/Migrate_01/Migrations/DeleteArchiveCollectionSetup.cs

5
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; }

9
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<ISchemaEntity> GetSchemaAsync(Guid appId, Guid schemaId)

5
src/Squidex/Config/Domain/EntitiesServices.cs

@ -172,10 +172,7 @@ namespace Squidex.Config.Domain
services.AddTransientAs<ConvertEventStoreAppId>()
.As<IMigration>();
services.AddTransientAs<ConvertOldSnapshotStores>()
.As<IMigration>();
services.AddTransientAs<DeleteArchiveCollection>()
services.AddTransientAs<DeleteArchiveCollectionSetup>()
.As<IMigration>();
services.AddTransientAs<PopulateGrainIndexes>()

7
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<ISnapshotStore<ContentState, Guid>>()
.As<IEventConsumer>()
.As<IInitializable>();
services.AddTransientAs(c => new DeleteArchiveCollectionSetup(mongoContentDatabase))
.As<IMigration>();
services.AddTransientAs<ConvertOldSnapshotStores>()
.As<IMigration>();
}
});

2
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("<TOKEN_URL>", tokenUrl);

23
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<IMigration>();
// Version 10: Delete old archive fields
if (version < 10)
{
var migration = serviceProvider.GetService<DeleteArchiveCollectionSetup>();
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<ConvertOldSnapshotStores>());
var migration = serviceProvider.GetService<ConvertOldSnapshotStores>();
if (migration != null)
{
migrations.Add(migration);
}
migrations.Add(serviceProvider.GetRequiredService<PopulateGrainIndexes>());
}
@ -66,7 +83,7 @@ namespace Migrate_01
// Version 8: Introduce Archive collection.
if (version < 8)
{
migrations.Add(serviceProvider.GetRequiredService<DeleteArchiveCollection>());
migrations.Add(serviceProvider.GetRequiredService<DeleteArchiveCollectionSetup>());
}
return (CurrentVersion, migrations);

32
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<BsonDocument>("States_Contents");
await collection.Indexes.DropAllAsync();
await collection.UpdateManyAsync(new BsonDocument(), Builders<BsonDocument>.Update.Unset("id"));
}
}
}
Loading…
Cancel
Save