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] [BsonId]
[BsonRequired] [BsonRequired]
[BsonElement]
public string DocumentId { get; set; }
[BsonRequired]
[BsonElement("id")]
[BsonRepresentation(BsonType.String)] [BsonRepresentation(BsonType.String)]
public Guid Id { get; set; } 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 idData = value.Data?.ToIdModel(schema.SchemaDef, true);
var id = key.ToString();
var document = SimpleMapper.Map(value, new MongoContentEntity var document = SimpleMapper.Map(value, new MongoContentEntity
{ {
AppIdId = value.AppId.Id, AppIdId = value.AppId.Id,
SchemaIdId = value.SchemaId.Id, SchemaIdId = value.SchemaId.Id,
IsDeleted = value.IsDeleted, IsDeleted = value.IsDeleted,
DocumentId = key.ToString(),
DataText = idData?.ToFullText(), DataText = idData?.ToFullText(),
DataByIds = idData, DataByIds = idData,
ReferencedIds = idData?.ToReferencedIds(schema.SchemaDef), ReferencedIds = idData?.ToReferencedIds(schema.SchemaDef),
@ -71,14 +68,14 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
try 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) catch (MongoWriteException ex)
{ {
if (ex.WriteError.Category == ServerErrorCategory.DuplicateKey) if (ex.WriteError.Category == ServerErrorCategory.DuplicateKey)
{ {
var existingVersion = 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(); .FirstOrDefaultAsync();
if (existingVersion != null) if (existingVersion != null)
@ -91,8 +88,6 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
throw; throw;
} }
} }
document.DocumentId = $"{key}_{newVersion}";
} }
private async Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid schemaId) 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>() services.AddTransientAs<ConvertEventStoreAppId>()
.As<IMigration>(); .As<IMigration>();
services.AddTransientAs<ConvertOldSnapshotStores>() services.AddTransientAs<DeleteArchiveCollectionSetup>()
.As<IMigration>();
services.AddTransientAs<DeleteArchiveCollection>()
.As<IMigration>(); .As<IMigration>();
services.AddTransientAs<PopulateGrainIndexes>() 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.AspNetCore.Identity;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Migrate_01.Migrations;
using MongoDB.Driver; using MongoDB.Driver;
using Squidex.Domain.Apps.Entities; using Squidex.Domain.Apps.Entities;
using Squidex.Domain.Apps.Entities.Assets.Repositories; using Squidex.Domain.Apps.Entities.Assets.Repositories;
@ -107,6 +108,12 @@ namespace Squidex.Config.Domain
.As<ISnapshotStore<ContentState, Guid>>() .As<ISnapshotStore<ContentState, Guid>>()
.As<IEventConsumer>() .As<IEventConsumer>()
.As<IInitializable>(); .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) 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 securityDocs = LoadDocs("security");
var securityText = securityDocs.Replace("<TOKEN_URL>", tokenUrl); 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 public sealed class MigrationPath : IMigrationPath
{ {
private const int CurrentVersion = 9; private const int CurrentVersion = 10;
private readonly IServiceProvider serviceProvider; private readonly IServiceProvider serviceProvider;
public MigrationPath(IServiceProvider serviceProvider) public MigrationPath(IServiceProvider serviceProvider)
@ -32,6 +32,17 @@ namespace Migrate_01
var migrations = new List<IMigration>(); 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. // Version 6: Convert Event store. Must always be executed first.
if (version < 6) if (version < 6)
{ {
@ -53,7 +64,13 @@ namespace Migrate_01
// Version 9: Grain Indexes // Version 9: Grain Indexes
if (version < 9) if (version < 9)
{ {
migrations.Add(serviceProvider.GetRequiredService<ConvertOldSnapshotStores>()); var migration = serviceProvider.GetService<ConvertOldSnapshotStores>();
if (migration != null)
{
migrations.Add(migration);
}
migrations.Add(serviceProvider.GetRequiredService<PopulateGrainIndexes>()); migrations.Add(serviceProvider.GetRequiredService<PopulateGrainIndexes>());
} }
@ -66,7 +83,7 @@ namespace Migrate_01
// Version 8: Introduce Archive collection. // Version 8: Introduce Archive collection.
if (version < 8) if (version < 8)
{ {
migrations.Add(serviceProvider.GetRequiredService<DeleteArchiveCollection>()); migrations.Add(serviceProvider.GetRequiredService<DeleteArchiveCollectionSetup>());
} }
return (CurrentVersion, migrations); 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