Skip to content

Commit

Permalink
Database configuration for devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryba1986 committed Jul 4, 2022
1 parent 0e11748 commit 50f1cfb
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Zeus.Domain.Devices;
using Zeus.Domain.Locations;
using Zeus.Domain.Users;
using Zeus.Enums.Users;
Expand All @@ -22,6 +23,9 @@ private static async Task CreateIndexesAsync(IMongoDatabase database)
await CreateLocationIndexesAsync(database);
await CreateLocationHistoryIndexesAsync(database);

await CreateDeviceIndexesAsync(database);
await CreateDeviceHistoryIndexesAsync(database);

await CreateUserIndexesAsync(database);
await CreateUserHistoryIndexesAsync(database);
}
Expand Down Expand Up @@ -56,6 +60,40 @@ private static Task CreateLocationHistoryIndexesAsync(IMongoDatabase database)
return CreateIndexesAsync(list, database);
}

private static Task CreateDeviceIndexesAsync(IMongoDatabase database)
{
List<CreateIndexModel<Device>> list = new()
{
new CreateIndexModel<Device>(Builders<Device>.IndexKeys.Combine(
Builders<Device>.IndexKeys.Ascending(x => x.LocationId),
Builders<Device>.IndexKeys.Ascending(x => x.ModbusId)
),
new CreateIndexOptions { Name = $"{nameof(Device.LocationId)}-{nameof(Device.ModbusId)}", Unique = true, Background = true }),

new CreateIndexModel<Device>(Builders<Device>.IndexKeys.Combine(
Builders<Device>.IndexKeys.Ascending(x => x.LocationId),
Builders<Device>.IndexKeys.Ascending(x => x.Name)
),
new CreateIndexOptions { Name = $"{nameof(Device.LocationId)}-{nameof(Device.Name)}", Unique = true, Background = true })
};

return CreateIndexesAsync(list, database);
}

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

return CreateIndexesAsync(list, database);
}

private static Task CreateUserIndexesAsync(IMongoDatabase database)
{
List<CreateIndexModel<User>> list = new()
Expand Down

0 comments on commit 50f1cfb

Please sign in to comment.