Skip to content

Commit

Permalink
Database configuration for plcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryba1986 committed Jul 4, 2022
1 parent daa3c97 commit 34488a6
Showing 1 changed file with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using MongoDB.Driver.Linq;
using Zeus.Domain.Devices;
using Zeus.Domain.Locations;
using Zeus.Domain.Plcs.Meters;
using Zeus.Domain.Plcs.Rvds;
using Zeus.Domain.Users;
using Zeus.Enums.Users;
using Zeus.Utilities.Extensions;
Expand All @@ -20,14 +22,20 @@ public static async Task SetupAsync(IMongoDatabase database)

private static async Task CreateIndexesAsync(IMongoDatabase database)
{
await CreateLocationIndexesAsync(database);
await CreateLocationHistoryIndexesAsync(database);
await Task.WhenAll(new Task[]
{
CreateLocationIndexesAsync(database),
CreateLocationHistoryIndexesAsync(database),

CreateDeviceIndexesAsync(database),
CreateDeviceHistoryIndexesAsync(database),

await CreateDeviceIndexesAsync(database);
await CreateDeviceHistoryIndexesAsync(database);
CreateUserIndexesAsync(database),
CreateUserHistoryIndexesAsync(database),

await CreateUserIndexesAsync(database);
await CreateUserHistoryIndexesAsync(database);
CreateMeterIndexesAsync(database),
CreateRvd145IndexesAsync(database),
});
}

private static Task CreateLocationIndexesAsync(IMongoDatabase database)
Expand Down Expand Up @@ -120,9 +128,37 @@ private static Task CreateUserHistoryIndexesAsync(IMongoDatabase database)
return CreateIndexesAsync(list, database);
}

private static async Task CreateDataAsync(IMongoDatabase database)
private static Task CreateMeterIndexesAsync(IMongoDatabase database)
{
await CreateUserDataAsync(database);
List<CreateIndexModel<Meter>> list = new()
{
new CreateIndexModel<Meter>(Builders<Meter>.IndexKeys.Combine(
Builders<Meter>.IndexKeys.Ascending(x => x.DeviceId),
Builders<Meter>.IndexKeys.Ascending(x => x.Date)
),
new CreateIndexOptions { Name = $"{nameof(Meter.DeviceId)}-{nameof(Meter.Date)}", Unique = true, Background = true })
};

return CreateIndexesAsync(list, database);
}

private static Task CreateRvd145IndexesAsync(IMongoDatabase database)
{
List<CreateIndexModel<Rvd145>> list = new()
{
new CreateIndexModel<Rvd145>(Builders<Rvd145>.IndexKeys.Combine(
Builders<Rvd145>.IndexKeys.Ascending(x => x.DeviceId),
Builders<Rvd145>.IndexKeys.Ascending(x => x.Date)
),
new CreateIndexOptions { Name = $"{nameof(Rvd145.DeviceId)}-{nameof(Rvd145.Date)}", Unique = true, Background = true })
};

return CreateIndexesAsync(list, database);
}

private static Task CreateDataAsync(IMongoDatabase database)
{
return CreateUserDataAsync(database);
}

private static async Task CreateUserDataAsync(IMongoDatabase database)
Expand Down Expand Up @@ -152,6 +188,5 @@ private static Task CreateIndexesAsync<T>(IEnumerable<CreateIndexModel<T>> index
IMongoCollection<T> collection = database.GetCollection<T>(typeof(T).Name);
return collection.Indexes.CreateManyAsync(indexModel);
}

}
}

0 comments on commit 34488a6

Please sign in to comment.