mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
[PM-10560] Create notification database storage (#4688)
* Add new tables * Add stored procedures * Add core entities and models * Setup EF * Add repository interfaces * Add dapper repos * Add EF repos * Add order by * EF updates * PM-10560: Notifications repository matching requirements. * PM-10560: Notifications repository matching requirements. * PM-10560: Migration scripts * PM-10560: EF index optimizations * PM-10560: Cleanup * PM-10560: Priority in natural order, Repository, sql simplifications * PM-10560: Title column update * PM-10560: Incorrect EF migration removal * PM-10560: EF migrations * PM-10560: Added views, SP naming simplification * PM-10560: Notification entity Title update, EF migrations * PM-10560: Removing Notification_ReadByUserId * PM-10560: Notification ReadByUserIdAndStatus fix * PM-10560: Notification ReadByUserIdAndStatus fix to be in line with requirements and EF --------- Co-authored-by: Maciej Zieniuk <mzieniuk@bitwarden.com> Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
parent
55bf815050
commit
4c0f8d54f3
27
src/Core/NotificationCenter/Entities/Notification.cs
Normal file
27
src/Core/NotificationCenter/Entities/Notification.cs
Normal file
@ -0,0 +1,27 @@
|
||||
#nullable enable
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.NotificationCenter.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.NotificationCenter.Entities;
|
||||
|
||||
public class Notification : ITableObject<Guid>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Priority Priority { get; set; }
|
||||
public bool Global { get; set; }
|
||||
public ClientType ClientType { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public Guid? OrganizationId { get; set; }
|
||||
[MaxLength(256)]
|
||||
public string? Title { get; set; }
|
||||
public string? Body { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb();
|
||||
}
|
||||
}
|
10
src/Core/NotificationCenter/Entities/NotificationStatus.cs
Normal file
10
src/Core/NotificationCenter/Entities/NotificationStatus.cs
Normal file
@ -0,0 +1,10 @@
|
||||
#nullable enable
|
||||
namespace Bit.Core.NotificationCenter.Entities;
|
||||
|
||||
public class NotificationStatus
|
||||
{
|
||||
public Guid NotificationId { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public DateTime? ReadDate { get; set; }
|
||||
public DateTime? DeletedDate { get; set; }
|
||||
}
|
18
src/Core/NotificationCenter/Enums/ClientType.cs
Normal file
18
src/Core/NotificationCenter/Enums/ClientType.cs
Normal file
@ -0,0 +1,18 @@
|
||||
#nullable enable
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.NotificationCenter.Enums;
|
||||
|
||||
public enum ClientType : byte
|
||||
{
|
||||
[Display(Name = "All")]
|
||||
All = 0,
|
||||
[Display(Name = "Web Vault")]
|
||||
Web = 1,
|
||||
[Display(Name = "Browser Extension")]
|
||||
Browser = 2,
|
||||
[Display(Name = "Desktop App")]
|
||||
Desktop = 3,
|
||||
[Display(Name = "Mobile App")]
|
||||
Mobile = 4
|
||||
}
|
18
src/Core/NotificationCenter/Enums/Priority.cs
Normal file
18
src/Core/NotificationCenter/Enums/Priority.cs
Normal file
@ -0,0 +1,18 @@
|
||||
#nullable enable
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.NotificationCenter.Enums;
|
||||
|
||||
public enum Priority : byte
|
||||
{
|
||||
[Display(Name = "Informational")]
|
||||
Informational = 0,
|
||||
[Display(Name = "Low")]
|
||||
Low = 1,
|
||||
[Display(Name = "Medium")]
|
||||
Medium = 2,
|
||||
[Display(Name = "High")]
|
||||
High = 3,
|
||||
[Display(Name = "Critical")]
|
||||
Critical = 4
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
#nullable enable
|
||||
namespace Bit.Core.NotificationCenter.Models.Filter;
|
||||
|
||||
public class NotificationStatusFilter
|
||||
{
|
||||
public bool? Read { get; set; }
|
||||
public bool? Deleted { get; set; }
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#nullable enable
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Enums;
|
||||
using Bit.Core.NotificationCenter.Models.Filter;
|
||||
using Bit.Core.Repositories;
|
||||
|
||||
namespace Bit.Core.NotificationCenter.Repositories;
|
||||
|
||||
public interface INotificationRepository : IRepository<Notification, Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get notifications for a user with the given filters.
|
||||
/// Includes global notifications.
|
||||
/// </summary>
|
||||
/// <param name="userId">User Id</param>
|
||||
/// <param name="clientType">
|
||||
/// Filter for notifications by client type. Always includes notifications with <see cref="ClientType.All"/>.
|
||||
/// </param>
|
||||
/// <param name="statusFilter">
|
||||
/// Filters notifications by status.
|
||||
/// If both <see cref="NotificationStatusFilter.Read"/> and <see cref="NotificationStatusFilter.Deleted"/>
|
||||
/// are not set, includes notifications without a status.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Ordered by priority (highest to lowest) and creation date (descending).
|
||||
/// </returns>
|
||||
Task<IEnumerable<Notification>> GetByUserIdAndStatusAsync(Guid userId, ClientType clientType,
|
||||
NotificationStatusFilter? statusFilter);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#nullable enable
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
|
||||
namespace Bit.Core.NotificationCenter.Repositories;
|
||||
|
||||
public interface INotificationStatusRepository
|
||||
{
|
||||
Task<NotificationStatus?> GetByNotificationIdAndUserIdAsync(Guid notificationId, Guid userId);
|
||||
Task<NotificationStatus> CreateAsync(NotificationStatus notificationStatus);
|
||||
Task UpdateAsync(NotificationStatus notificationStatus);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Auth.Repositories;
|
||||
using Bit.Core.Billing.Repositories;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.SecretsManager.Repositories;
|
||||
using Bit.Core.Tools.Repositories;
|
||||
@ -8,6 +9,7 @@ using Bit.Core.Vault.Repositories;
|
||||
using Bit.Infrastructure.Dapper.AdminConsole.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Auth.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Billing.Repositories;
|
||||
using Bit.Infrastructure.Dapper.NotificationCenter.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Repositories;
|
||||
using Bit.Infrastructure.Dapper.SecretsManager.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Tools.Repositories;
|
||||
@ -52,6 +54,8 @@ public static class DapperServiceCollectionExtensions
|
||||
services.AddSingleton<IWebAuthnCredentialRepository, WebAuthnCredentialRepository>();
|
||||
services.AddSingleton<IProviderPlanRepository, ProviderPlanRepository>();
|
||||
services.AddSingleton<IProviderInvoiceItemRepository, ProviderInvoiceItemRepository>();
|
||||
services.AddSingleton<INotificationRepository, NotificationRepository>();
|
||||
services.AddSingleton<INotificationStatusRepository, NotificationStatusRepository>();
|
||||
|
||||
if (selfHosted)
|
||||
{
|
||||
|
@ -0,0 +1,38 @@
|
||||
#nullable enable
|
||||
using System.Data;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Enums;
|
||||
using Bit.Core.NotificationCenter.Models.Filter;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Infrastructure.Dapper.Repositories;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.NotificationCenter.Repositories;
|
||||
|
||||
public class NotificationRepository : Repository<Notification, Guid>, INotificationRepository
|
||||
{
|
||||
public NotificationRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
{
|
||||
}
|
||||
|
||||
public NotificationRepository(string connectionString, string readOnlyConnectionString)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Notification>> GetByUserIdAndStatusAsync(Guid userId,
|
||||
ClientType clientType, NotificationStatusFilter? statusFilter)
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
|
||||
var results = await connection.QueryAsync<Notification>(
|
||||
"[dbo].[Notification_ReadByUserIdAndStatus]",
|
||||
new { UserId = userId, ClientType = clientType, statusFilter?.Read, statusFilter?.Deleted },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
#nullable enable
|
||||
using System.Data;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Infrastructure.Dapper.Repositories;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.NotificationCenter.Repositories;
|
||||
|
||||
public class NotificationStatusRepository : BaseRepository, INotificationStatusRepository
|
||||
{
|
||||
public NotificationStatusRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
{
|
||||
}
|
||||
|
||||
public NotificationStatusRepository(string connectionString, string readOnlyConnectionString)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<NotificationStatus?> GetByNotificationIdAndUserIdAsync(Guid notificationId, Guid userId)
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
|
||||
return await connection.QueryFirstOrDefaultAsync<NotificationStatus>(
|
||||
"[dbo].[NotificationStatus_ReadByNotificationIdAndUserId]",
|
||||
new { NotificationId = notificationId, UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
|
||||
public async Task<NotificationStatus> CreateAsync(NotificationStatus notificationStatus)
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
|
||||
await connection.ExecuteAsync("[dbo].[NotificationStatus_Create]",
|
||||
notificationStatus, commandType: CommandType.StoredProcedure);
|
||||
|
||||
return notificationStatus;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(NotificationStatus notificationStatus)
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
|
||||
await connection.ExecuteAsync("[dbo].[NotificationStatus_Update]",
|
||||
notificationStatus, commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using Bit.Core.Auth.Repositories;
|
||||
using Bit.Core.Billing.Repositories;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.SecretsManager.Repositories;
|
||||
using Bit.Core.Tools.Repositories;
|
||||
@ -9,6 +10,7 @@ using Bit.Core.Vault.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Billing.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.NotificationCenter.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.SecretsManager.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Tools.Repositories;
|
||||
@ -89,6 +91,8 @@ public static class EntityFrameworkServiceCollectionExtensions
|
||||
services.AddSingleton<IWebAuthnCredentialRepository, WebAuthnCredentialRepository>();
|
||||
services.AddSingleton<IProviderPlanRepository, ProviderPlanRepository>();
|
||||
services.AddSingleton<IProviderInvoiceItemRepository, ProviderInvoiceItemRepository>();
|
||||
services.AddSingleton<INotificationRepository, NotificationRepository>();
|
||||
services.AddSingleton<INotificationStatusRepository, NotificationStatusRepository>();
|
||||
|
||||
if (selfHosted)
|
||||
{
|
||||
|
@ -0,0 +1,35 @@
|
||||
#nullable enable
|
||||
using Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Configurations;
|
||||
|
||||
public class NotificationEntityTypeConfiguration : IEntityTypeConfiguration<Notification>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Notification> builder)
|
||||
{
|
||||
builder
|
||||
.Property(n => n.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder
|
||||
.HasKey(n => n.Id)
|
||||
.IsClustered();
|
||||
|
||||
builder
|
||||
.HasIndex(n => new { n.ClientType, n.Global, n.UserId, n.OrganizationId, n.Priority, n.CreationDate })
|
||||
.IsDescending(false, false, false, false, true, true)
|
||||
.IsClustered(false);
|
||||
|
||||
builder
|
||||
.HasIndex(n => n.OrganizationId)
|
||||
.IsClustered(false);
|
||||
|
||||
builder
|
||||
.HasIndex(n => n.UserId)
|
||||
.IsClustered(false);
|
||||
|
||||
builder.ToTable(nameof(Notification));
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
#nullable enable
|
||||
using Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Configurations;
|
||||
|
||||
public class NotificationStatusEntityTypeConfiguration : IEntityTypeConfiguration<NotificationStatus>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<NotificationStatus> builder)
|
||||
{
|
||||
builder
|
||||
.HasKey(ns => new { ns.UserId, ns.NotificationId })
|
||||
.IsClustered();
|
||||
|
||||
builder.ToTable(nameof(NotificationStatus));
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
|
||||
|
||||
public class Notification : Core.NotificationCenter.Entities.Notification
|
||||
{
|
||||
public virtual User User { get; set; }
|
||||
public virtual Organization Organization { get; set; }
|
||||
}
|
||||
|
||||
public class NotificationMapperProfile : Profile
|
||||
{
|
||||
public NotificationMapperProfile()
|
||||
{
|
||||
CreateMap<Core.NotificationCenter.Entities.Notification, Notification>()
|
||||
.PreserveReferences()
|
||||
.ReverseMap();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
|
||||
|
||||
public class NotificationStatus : Core.NotificationCenter.Entities.NotificationStatus
|
||||
{
|
||||
public virtual Notification Notification { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
}
|
||||
|
||||
public class NotificationStatusMapperProfile : Profile
|
||||
{
|
||||
public NotificationStatusMapperProfile()
|
||||
{
|
||||
CreateMap<Core.NotificationCenter.Entities.NotificationStatus, NotificationStatus>()
|
||||
.PreserveReferences()
|
||||
.ReverseMap();
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
#nullable enable
|
||||
using AutoMapper;
|
||||
using Bit.Core.NotificationCenter.Enums;
|
||||
using Bit.Core.NotificationCenter.Models.Filter;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Repositories;
|
||||
|
||||
public class NotificationRepository : Repository<Core.NotificationCenter.Entities.Notification, Notification, Guid>,
|
||||
INotificationRepository
|
||||
{
|
||||
public NotificationRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||
: base(serviceScopeFactory, mapper, context => context.Notifications)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Core.NotificationCenter.Entities.Notification>> GetByUserIdAsync(Guid userId,
|
||||
ClientType clientType)
|
||||
{
|
||||
return await GetByUserIdAndStatusAsync(userId, clientType, new NotificationStatusFilter());
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Core.NotificationCenter.Entities.Notification>> GetByUserIdAndStatusAsync(Guid userId,
|
||||
ClientType clientType, NotificationStatusFilter? statusFilter)
|
||||
{
|
||||
await using var scope = ServiceScopeFactory.CreateAsyncScope();
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var notificationQuery = BuildNotificationQuery(dbContext, userId, clientType);
|
||||
|
||||
if (statusFilter != null && (statusFilter.Read != null || statusFilter.Deleted != null))
|
||||
{
|
||||
notificationQuery = from n in notificationQuery
|
||||
join ns in dbContext.NotificationStatuses on n.Id equals ns.NotificationId
|
||||
where
|
||||
ns.UserId == userId &&
|
||||
(
|
||||
statusFilter.Read == null ||
|
||||
(statusFilter.Read == true ? ns.ReadDate != null : ns.ReadDate == null) ||
|
||||
statusFilter.Deleted == null ||
|
||||
(statusFilter.Deleted == true ? ns.DeletedDate != null : ns.DeletedDate == null)
|
||||
)
|
||||
select n;
|
||||
}
|
||||
|
||||
var notifications = await notificationQuery
|
||||
.OrderByDescending(n => n.Priority)
|
||||
.ThenByDescending(n => n.CreationDate)
|
||||
.ToListAsync();
|
||||
|
||||
return Mapper.Map<List<Core.NotificationCenter.Entities.Notification>>(notifications);
|
||||
}
|
||||
|
||||
private static IQueryable<Notification> BuildNotificationQuery(DatabaseContext dbContext, Guid userId,
|
||||
ClientType clientType)
|
||||
{
|
||||
var clientTypes = new[] { ClientType.All };
|
||||
if (clientType != ClientType.All)
|
||||
{
|
||||
clientTypes = [ClientType.All, clientType];
|
||||
}
|
||||
|
||||
return from n in dbContext.Notifications
|
||||
join ou in dbContext.OrganizationUsers.Where(ou => ou.UserId == userId)
|
||||
on n.OrganizationId equals ou.OrganizationId into grouping
|
||||
from ou in grouping.DefaultIfEmpty()
|
||||
where
|
||||
clientTypes.Contains(n.ClientType) &&
|
||||
(
|
||||
(
|
||||
n.Global &&
|
||||
n.UserId == null &&
|
||||
n.OrganizationId == null
|
||||
) ||
|
||||
(
|
||||
!n.Global &&
|
||||
n.UserId == userId &&
|
||||
(n.OrganizationId == null || ou != null)
|
||||
) ||
|
||||
(
|
||||
!n.Global &&
|
||||
n.UserId == null &&
|
||||
ou != null
|
||||
)
|
||||
)
|
||||
select n;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
#nullable enable
|
||||
using AutoMapper;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Repositories;
|
||||
|
||||
public class NotificationStatusRepository : BaseEntityFrameworkRepository, INotificationStatusRepository
|
||||
{
|
||||
public NotificationStatusRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) : base(
|
||||
serviceScopeFactory,
|
||||
mapper)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<Bit.Core.NotificationCenter.Entities.NotificationStatus?> GetByNotificationIdAndUserIdAsync(Guid notificationId, Guid userId)
|
||||
{
|
||||
await using var scope = ServiceScopeFactory.CreateAsyncScope();
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var entity = await dbContext.NotificationStatuses
|
||||
.Where(ns =>
|
||||
ns.NotificationId == notificationId && ns.UserId == userId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return Mapper.Map<Bit.Core.NotificationCenter.Entities.NotificationStatus?>(entity);
|
||||
}
|
||||
|
||||
public async Task<Bit.Core.NotificationCenter.Entities.NotificationStatus> CreateAsync(Bit.Core.NotificationCenter.Entities.NotificationStatus notificationStatus)
|
||||
{
|
||||
await using var scope = ServiceScopeFactory.CreateAsyncScope();
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var entity = Mapper.Map<NotificationStatus>(notificationStatus);
|
||||
await dbContext.AddAsync(entity);
|
||||
await dbContext.SaveChangesAsync();
|
||||
return notificationStatus;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(Bit.Core.NotificationCenter.Entities.NotificationStatus notificationStatus)
|
||||
{
|
||||
await using var scope = ServiceScopeFactory.CreateAsyncScope();
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var entity = await dbContext.NotificationStatuses
|
||||
.Where(ns =>
|
||||
ns.NotificationId == notificationStatus.NotificationId && ns.UserId == notificationStatus.UserId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
entity.DeletedDate = notificationStatus.DeletedDate;
|
||||
entity.ReadDate = notificationStatus.ReadDate;
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ using Bit.Infrastructure.EntityFramework.Auth.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Converters;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
|
||||
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Vault.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -71,6 +72,8 @@ public class DatabaseContext : DbContext
|
||||
public DbSet<WebAuthnCredential> WebAuthnCredentials { get; set; }
|
||||
public DbSet<ProviderPlan> ProviderPlans { get; set; }
|
||||
public DbSet<ProviderInvoiceItem> ProviderInvoiceItems { get; set; }
|
||||
public DbSet<Notification> Notifications { get; set; }
|
||||
public DbSet<NotificationStatus> NotificationStatuses { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
@ -0,0 +1,22 @@
|
||||
CREATE PROCEDURE [dbo].[NotificationStatus_Create]
|
||||
@NotificationId UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@ReadDate DATETIME2(7),
|
||||
@DeletedDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[NotificationStatus] (
|
||||
[NotificationId],
|
||||
[UserId],
|
||||
[ReadDate],
|
||||
[DeletedDate]
|
||||
)
|
||||
VALUES (
|
||||
@NotificationId,
|
||||
@UserId,
|
||||
@ReadDate,
|
||||
@DeletedDate
|
||||
)
|
||||
END
|
@ -0,0 +1,12 @@
|
||||
CREATE PROCEDURE [dbo].[NotificationStatus_ReadByNotificationIdAndUserId]
|
||||
@NotificationId UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT TOP 1 *
|
||||
FROM [dbo].[NotificationStatusView]
|
||||
WHERE [NotificationId] = @NotificationId
|
||||
AND [UserId] = @UserId
|
||||
END
|
@ -0,0 +1,15 @@
|
||||
CREATE PROCEDURE [dbo].[NotificationStatus_Update]
|
||||
@NotificationId UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@ReadDate DATETIME2(7),
|
||||
@DeletedDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE [dbo].[NotificationStatus]
|
||||
SET [ReadDate] = @ReadDate,
|
||||
[DeletedDate] = @DeletedDate
|
||||
WHERE [NotificationId] = @NotificationId
|
||||
AND [UserId] = @UserId
|
||||
END
|
@ -0,0 +1,40 @@
|
||||
CREATE PROCEDURE [dbo].[Notification_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@Priority TINYINT,
|
||||
@Global BIT,
|
||||
@ClientType TINYINT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Title NVARCHAR(256),
|
||||
@Body NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[Notification] (
|
||||
[Id],
|
||||
[Priority],
|
||||
[Global],
|
||||
[ClientType],
|
||||
[UserId],
|
||||
[OrganizationId],
|
||||
[Title],
|
||||
[Body],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
VALUES (
|
||||
@Id,
|
||||
@Priority,
|
||||
@Global,
|
||||
@ClientType,
|
||||
@UserId,
|
||||
@OrganizationId,
|
||||
@Title,
|
||||
@Body,
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
END
|
@ -0,0 +1,10 @@
|
||||
CREATE PROCEDURE [dbo].[Notification_ReadById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT *
|
||||
FROM [dbo].[NotificationView]
|
||||
WHERE [Id] = @Id
|
||||
END
|
@ -0,0 +1,34 @@
|
||||
CREATE PROCEDURE [dbo].[Notification_ReadByUserIdAndStatus]
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@ClientType TINYINT,
|
||||
@Read BIT,
|
||||
@Deleted BIT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT n.*
|
||||
FROM [dbo].[NotificationView] n
|
||||
LEFT JOIN [dbo].[OrganizationUserView] ou ON n.[OrganizationId] = ou.[OrganizationId]
|
||||
AND ou.[UserId] = @UserId
|
||||
LEFT JOIN [dbo].[NotificationStatusView] ns ON n.[Id] = ns.[NotificationId]
|
||||
AND ns.[UserId] = @UserId
|
||||
WHERE [ClientType] IN (0, CASE WHEN @ClientType != 0 THEN @ClientType END)
|
||||
AND ([Global] = 1
|
||||
OR (n.[UserId] = @UserId
|
||||
AND (n.[OrganizationId] IS NULL
|
||||
OR ou.[OrganizationId] IS NOT NULL))
|
||||
OR (n.[UserId] IS NULL
|
||||
AND ou.[OrganizationId] IS NOT NULL))
|
||||
AND ((@Read IS NULL AND @Deleted IS NULL)
|
||||
OR (ns.[NotificationId] IS NOT NULL
|
||||
AND ((@Read IS NULL
|
||||
OR IIF((@Read = 1 AND ns.[ReadDate] IS NOT NULL) OR
|
||||
(@Read = 0 AND ns.[ReadDate] IS NULL),
|
||||
1, 0) = 1)
|
||||
OR (@Deleted IS NULL
|
||||
OR IIF((@Deleted = 1 AND ns.[DeletedDate] IS NOT NULL) OR
|
||||
(@Deleted = 0 AND ns.[DeletedDate] IS NULL),
|
||||
1, 0) = 1))))
|
||||
ORDER BY [Priority] DESC, n.[CreationDate] DESC
|
||||
END
|
@ -0,0 +1,27 @@
|
||||
CREATE PROCEDURE [dbo].[Notification_Update]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@Priority TINYINT,
|
||||
@Global BIT,
|
||||
@ClientType TINYINT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Title NVARCHAR(256),
|
||||
@Body NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE [dbo].[Notification]
|
||||
SET [Priority] = @Priority,
|
||||
[Global] = @Global,
|
||||
[ClientType] = @ClientType,
|
||||
[UserId] = @UserId,
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[Title] = @Title,
|
||||
[Body] = @Body,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE [Id] = @Id
|
||||
END
|
32
src/Sql/NotificationCenter/dbo/Tables/Notification.sql
Normal file
32
src/Sql/NotificationCenter/dbo/Tables/Notification.sql
Normal file
@ -0,0 +1,32 @@
|
||||
CREATE TABLE [dbo].[Notification]
|
||||
(
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Priority] TINYINT NOT NULL,
|
||||
[Global] BIT NOT NULL,
|
||||
[ClientType] TINYINT NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NULL,
|
||||
[OrganizationId] UNIQUEIDENTIFIER NULL,
|
||||
[Title] NVARCHAR (256) NULL,
|
||||
[Body] NVARCHAR (MAX) NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_Notification] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_Notification_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
||||
CONSTRAINT [FK_Notification_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
);
|
||||
|
||||
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_Notification_Priority_CreationDate_ClientType_Global_UserId_OrganizationId]
|
||||
ON [dbo].[Notification]([Priority] DESC, [CreationDate] DESC, [ClientType], [Global], [UserId], [OrganizationId]);
|
||||
|
||||
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_Notification_UserId]
|
||||
ON [dbo].[Notification]([UserId] ASC) WHERE UserId IS NOT NULL;
|
||||
|
||||
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_Notification_OrganizationId]
|
||||
ON [dbo].[Notification]([OrganizationId] ASC) WHERE OrganizationId IS NOT NULL;
|
||||
|
@ -0,0 +1,9 @@
|
||||
CREATE TABLE [dbo].[NotificationStatus]
|
||||
(
|
||||
[NotificationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[ReadDate] DATETIME2 (7) NULL,
|
||||
[DeletedDate] DATETIME2 (7) NULL,
|
||||
CONSTRAINT [PK_NotificationStatus] PRIMARY KEY CLUSTERED ([NotificationId] ASC, [UserId] ASC),
|
||||
CONSTRAINT [FK_NotificationStatus_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
);
|
@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[NotificationStatusView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[NotificationStatus]
|
@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[NotificationView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[Notification]
|
295
util/Migrator/DbScripts/2024-09-06_00_NotificationCenter.sql
Normal file
295
util/Migrator/DbScripts/2024-09-06_00_NotificationCenter.sql
Normal file
@ -0,0 +1,295 @@
|
||||
-- Notification
|
||||
|
||||
-- Table Notification
|
||||
IF OBJECT_ID('[dbo].[Notification]') IS NULL
|
||||
BEGIN
|
||||
CREATE TABLE [dbo].[Notification]
|
||||
(
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Priority] TINYINT NOT NULL,
|
||||
[Global] BIT NOT NULL,
|
||||
[ClientType] TINYINT NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NULL,
|
||||
[OrganizationId] UNIQUEIDENTIFIER NULL,
|
||||
[Title] NVARCHAR(256) NULL,
|
||||
[Body] NVARCHAR(MAX) NULL,
|
||||
[CreationDate] DATETIME2(7) NOT NULL,
|
||||
[RevisionDate] DATETIME2(7) NOT NULL,
|
||||
CONSTRAINT [PK_Notification] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_Notification_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
||||
CONSTRAINT [FK_Notification_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
);
|
||||
|
||||
CREATE NONCLUSTERED INDEX [IX_Notification_Priority_CreationDate_ClientType_Global_UserId_OrganizationId]
|
||||
ON [dbo].[Notification] ([Priority] DESC, [CreationDate] DESC, [ClientType], [Global], [UserId],
|
||||
[OrganizationId]);
|
||||
|
||||
CREATE NONCLUSTERED INDEX [IX_Notification_UserId]
|
||||
ON [dbo].[Notification] ([UserId] ASC) WHERE UserId IS NOT NULL;
|
||||
|
||||
CREATE NONCLUSTERED INDEX [IX_Notification_OrganizationId]
|
||||
ON [dbo].[Notification] ([OrganizationId] ASC) WHERE OrganizationId IS NOT NULL;
|
||||
END
|
||||
GO
|
||||
|
||||
-- Table NotificationStatus
|
||||
IF OBJECT_ID('[dbo].[NotificationStatus]') IS NULL
|
||||
BEGIN
|
||||
CREATE TABLE [dbo].[NotificationStatus]
|
||||
(
|
||||
[NotificationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[ReadDate] DATETIME2(7) NULL,
|
||||
[DeletedDate] DATETIME2(7) NULL,
|
||||
CONSTRAINT [PK_NotificationStatus] PRIMARY KEY CLUSTERED ([NotificationId] ASC, [UserId] ASC),
|
||||
CONSTRAINT [FK_NotificationStatus_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
);
|
||||
END
|
||||
GO
|
||||
|
||||
-- View Notification
|
||||
IF EXISTS(SELECT *
|
||||
FROM sys.views
|
||||
WHERE [Name] = 'NotificationView')
|
||||
BEGIN
|
||||
DROP VIEW [dbo].[NotificationView]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE VIEW [dbo].[NotificationView]
|
||||
AS
|
||||
SELECT *
|
||||
FROM [dbo].[Notification]
|
||||
GO
|
||||
|
||||
-- View NotificationStatus
|
||||
IF EXISTS(SELECT *
|
||||
FROM sys.views
|
||||
WHERE [Name] = 'NotificationStatusView')
|
||||
BEGIN
|
||||
DROP VIEW [dbo].[NotificationStatusView]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE VIEW [dbo].[NotificationStatusView]
|
||||
AS
|
||||
SELECT *
|
||||
FROM [dbo].[NotificationStatus]
|
||||
GO
|
||||
|
||||
-- Stored Procedures: Create
|
||||
IF OBJECT_ID('[dbo].[Notification_Create]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Notification_Create]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Notification_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@Priority TINYINT,
|
||||
@Global BIT,
|
||||
@ClientType TINYINT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Title NVARCHAR(256),
|
||||
@Body NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[Notification] ([Id],
|
||||
[Priority],
|
||||
[Global],
|
||||
[ClientType],
|
||||
[UserId],
|
||||
[OrganizationId],
|
||||
[Title],
|
||||
[Body],
|
||||
[CreationDate],
|
||||
[RevisionDate])
|
||||
VALUES (@Id,
|
||||
@Priority,
|
||||
@Global,
|
||||
@ClientType,
|
||||
@UserId,
|
||||
@OrganizationId,
|
||||
@Title,
|
||||
@Body,
|
||||
@CreationDate,
|
||||
@RevisionDate)
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedure: ReadById
|
||||
IF OBJECT_ID('[dbo].[Notification_ReadById]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Notification_ReadById]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Notification_ReadById] @Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT *
|
||||
FROM [dbo].[NotificationView]
|
||||
WHERE [Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedure: ReadByUserIdAndStatus
|
||||
IF OBJECT_ID('[dbo].[Notification_ReadByUserIdAndStatus]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Notification_ReadByUserIdAndStatus]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Notification_ReadByUserIdAndStatus]
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@ClientType TINYINT,
|
||||
@Read BIT,
|
||||
@Deleted BIT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT n.*
|
||||
FROM [dbo].[NotificationView] n
|
||||
LEFT JOIN [dbo].[OrganizationUserView] ou ON n.[OrganizationId] = ou.[OrganizationId]
|
||||
AND ou.[UserId] = @UserId
|
||||
LEFT JOIN [dbo].[NotificationStatusView] ns ON n.[Id] = ns.[NotificationId]
|
||||
AND ns.[UserId] = @UserId
|
||||
WHERE [ClientType] IN (0, CASE WHEN @ClientType != 0 THEN @ClientType END)
|
||||
AND ([Global] = 1
|
||||
OR (n.[UserId] = @UserId
|
||||
AND (n.[OrganizationId] IS NULL
|
||||
OR ou.[OrganizationId] IS NOT NULL))
|
||||
OR (n.[UserId] IS NULL
|
||||
AND ou.[OrganizationId] IS NOT NULL))
|
||||
AND ((@Read IS NULL AND @Deleted IS NULL)
|
||||
OR (ns.[NotificationId] IS NOT NULL
|
||||
AND ((@Read IS NULL
|
||||
OR IIF((@Read = 1 AND ns.[ReadDate] IS NOT NULL) OR
|
||||
(@Read = 0 AND ns.[ReadDate] IS NULL),
|
||||
1, 0) = 1)
|
||||
OR (@Deleted IS NULL
|
||||
OR IIF((@Deleted = 1 AND ns.[DeletedDate] IS NOT NULL) OR
|
||||
(@Deleted = 0 AND ns.[DeletedDate] IS NULL),
|
||||
1, 0) = 1))))
|
||||
ORDER BY [Priority] DESC, n.[CreationDate] DESC
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedure: Update
|
||||
IF OBJECT_ID('[dbo].[Notification_Update]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Notification_Update]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Notification_Update]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@Priority TINYINT,
|
||||
@Global BIT,
|
||||
@ClientType TINYINT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Title NVARCHAR(256),
|
||||
@Body NVARCHAR(MAX),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE [dbo].[Notification]
|
||||
SET [Priority] = @Priority,
|
||||
[Global] = @Global,
|
||||
[ClientType] = @ClientType,
|
||||
[UserId] = @UserId,
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[Title] = @Title,
|
||||
[Body] = @Body,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE [Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
|
||||
-- NotificationStatus
|
||||
|
||||
-- Stored Procedure: Create
|
||||
IF OBJECT_ID('[dbo].[NotificationStatus_Create]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[NotificationStatus_Create]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[NotificationStatus_Create]
|
||||
@NotificationId UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@ReadDate DATETIME2(7),
|
||||
@DeletedDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[NotificationStatus] ([NotificationId],
|
||||
[UserId],
|
||||
[ReadDate],
|
||||
[DeletedDate])
|
||||
VALUES (@NotificationId,
|
||||
@UserId,
|
||||
@ReadDate,
|
||||
@DeletedDate)
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedure: ReadByNotificationIdAndUserId
|
||||
IF OBJECT_ID('[dbo].[NotificationStatus_ReadByNotificationIdAndUserId]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[NotificationStatus_ReadByNotificationIdAndUserId]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[NotificationStatus_ReadByNotificationIdAndUserId]
|
||||
@NotificationId UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT TOP 1 *
|
||||
FROM [dbo].[NotificationStatusView]
|
||||
WHERE [NotificationId] = @NotificationId
|
||||
AND [UserId] = @UserId
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedure: Update
|
||||
IF OBJECT_ID('[dbo].[NotificationStatus_Update]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[NotificationStatus_Update]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[NotificationStatus_Update]
|
||||
@NotificationId UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@ReadDate DATETIME2(7),
|
||||
@DeletedDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE [dbo].[NotificationStatus]
|
||||
SET [ReadDate] = @ReadDate,
|
||||
[DeletedDate] = @DeletedDate
|
||||
WHERE [NotificationId] = @NotificationId
|
||||
AND [UserId] = @UserId
|
||||
END
|
||||
GO
|
2798
util/MySqlMigrations/Migrations/20240909133252_NotificationCenter.Designer.cs
generated
Normal file
2798
util/MySqlMigrations/Migrations/20240909133252_NotificationCenter.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,104 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.MySqlMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class NotificationCenter : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Notification",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
Priority = table.Column<byte>(type: "tinyint unsigned", nullable: false),
|
||||
Global = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
ClientType = table.Column<byte>(type: "tinyint unsigned", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
|
||||
OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
|
||||
Title = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
Body = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
RevisionDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Notification", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Notification_Organization_OrganizationId",
|
||||
column: x => x.OrganizationId,
|
||||
principalTable: "Organization",
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
name: "FK_Notification_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id");
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "NotificationStatus",
|
||||
columns: table => new
|
||||
{
|
||||
NotificationId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
UserId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
ReadDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
DeletedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_NotificationStatus", x => new { x.UserId, x.NotificationId });
|
||||
table.ForeignKey(
|
||||
name: "FK_NotificationStatus_Notification_NotificationId",
|
||||
column: x => x.NotificationId,
|
||||
principalTable: "Notification",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_NotificationStatus_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_ClientType_Global_UserId_OrganizationId_Priorit~",
|
||||
table: "Notification",
|
||||
columns: new[] { "ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate" },
|
||||
descending: new[] { false, false, false, false, true, true });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_OrganizationId",
|
||||
table: "Notification",
|
||||
column: "OrganizationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_UserId",
|
||||
table: "Notification",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_NotificationStatus_NotificationId",
|
||||
table: "NotificationStatus",
|
||||
column: "NotificationId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "NotificationStatus");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Notification");
|
||||
}
|
||||
}
|
@ -1588,6 +1588,77 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.ToTable("User", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<byte>("ClientType")
|
||||
.HasColumnType("tinyint unsigned");
|
||||
|
||||
b.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<bool>("Global")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<Guid?>("OrganizationId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<byte>("Priority")
|
||||
.HasColumnType("tinyint unsigned");
|
||||
|
||||
b.Property<DateTime>("RevisionDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)");
|
||||
|
||||
b.Property<Guid?>("UserId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate")
|
||||
.IsDescending(false, false, false, false, true, true)
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("Notification", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid>("NotificationId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime?>("DeletedDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTime?>("ReadDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("UserId", "NotificationId")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("NotificationId");
|
||||
|
||||
b.ToTable("NotificationStatus", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.AccessPolicy", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@ -2380,6 +2451,40 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
.HasForeignKey("OrganizationId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Organization");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", "Notification")
|
||||
.WithMany()
|
||||
.HasForeignKey("NotificationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Notification");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ServiceAccount", "ServiceAccount")
|
||||
|
2804
util/PostgresMigrations/Migrations/20240909133245_NotificationCenter.Designer.cs
generated
Normal file
2804
util/PostgresMigrations/Migrations/20240909133245_NotificationCenter.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,100 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class NotificationCenter : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Notification",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Priority = table.Column<byte>(type: "smallint", nullable: false),
|
||||
Global = table.Column<bool>(type: "boolean", nullable: false),
|
||||
ClientType = table.Column<byte>(type: "smallint", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
OrganizationId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||
Body = table.Column<string>(type: "text", nullable: true),
|
||||
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
RevisionDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Notification", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Notification_Organization_OrganizationId",
|
||||
column: x => x.OrganizationId,
|
||||
principalTable: "Organization",
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
name: "FK_Notification_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "NotificationStatus",
|
||||
columns: table => new
|
||||
{
|
||||
NotificationId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
ReadDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
DeletedDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_NotificationStatus", x => new { x.UserId, x.NotificationId });
|
||||
table.ForeignKey(
|
||||
name: "FK_NotificationStatus_Notification_NotificationId",
|
||||
column: x => x.NotificationId,
|
||||
principalTable: "Notification",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_NotificationStatus_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_ClientType_Global_UserId_OrganizationId_Priori~",
|
||||
table: "Notification",
|
||||
columns: new[] { "ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate" },
|
||||
descending: new[] { false, false, false, false, true, true });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_OrganizationId",
|
||||
table: "Notification",
|
||||
column: "OrganizationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_UserId",
|
||||
table: "Notification",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_NotificationStatus_NotificationId",
|
||||
table: "NotificationStatus",
|
||||
column: "NotificationId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "NotificationStatus");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Notification");
|
||||
}
|
||||
}
|
@ -1594,6 +1594,77 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.ToTable("User", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<byte>("ClientType")
|
||||
.HasColumnType("smallint");
|
||||
|
||||
b.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("Global")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid?>("OrganizationId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<byte>("Priority")
|
||||
.HasColumnType("smallint");
|
||||
|
||||
b.Property<DateTime>("RevisionDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<Guid?>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate")
|
||||
.IsDescending(false, false, false, false, true, true)
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("Notification", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("NotificationId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime?>("DeletedDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("ReadDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("UserId", "NotificationId")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("NotificationId");
|
||||
|
||||
b.ToTable("NotificationStatus", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.AccessPolicy", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@ -2386,6 +2457,40 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
.HasForeignKey("OrganizationId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Organization");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", "Notification")
|
||||
.WithMany()
|
||||
.HasForeignKey("NotificationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Notification");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ServiceAccount", "ServiceAccount")
|
||||
|
2787
util/SqliteMigrations/Migrations/20240909133238_NotificationCenter.Designer.cs
generated
Normal file
2787
util/SqliteMigrations/Migrations/20240909133238_NotificationCenter.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,100 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.SqliteMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class NotificationCenter : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Notification",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Priority = table.Column<byte>(type: "INTEGER", nullable: false),
|
||||
Global = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
ClientType = table.Column<byte>(type: "INTEGER", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
OrganizationId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
Title = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
|
||||
Body = table.Column<string>(type: "TEXT", nullable: true),
|
||||
CreationDate = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
RevisionDate = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Notification", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Notification_Organization_OrganizationId",
|
||||
column: x => x.OrganizationId,
|
||||
principalTable: "Organization",
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
name: "FK_Notification_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "NotificationStatus",
|
||||
columns: table => new
|
||||
{
|
||||
NotificationId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
ReadDate = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
DeletedDate = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_NotificationStatus", x => new { x.UserId, x.NotificationId });
|
||||
table.ForeignKey(
|
||||
name: "FK_NotificationStatus_Notification_NotificationId",
|
||||
column: x => x.NotificationId,
|
||||
principalTable: "Notification",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_NotificationStatus_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_ClientType_Global_UserId_OrganizationId_Priority_CreationDate",
|
||||
table: "Notification",
|
||||
columns: new[] { "ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate" },
|
||||
descending: new[] { false, false, false, false, true, true });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_OrganizationId",
|
||||
table: "Notification",
|
||||
column: "OrganizationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notification_UserId",
|
||||
table: "Notification",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_NotificationStatus_NotificationId",
|
||||
table: "NotificationStatus",
|
||||
column: "NotificationId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "NotificationStatus");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Notification");
|
||||
}
|
||||
}
|
@ -1577,6 +1577,77 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.ToTable("User", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<byte>("ClientType")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("Global")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid?>("OrganizationId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<byte>("Priority")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("RevisionDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid?>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("ClientType", "Global", "UserId", "OrganizationId", "Priority", "CreationDate")
|
||||
.IsDescending(false, false, false, false, true, true)
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("Notification", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("NotificationId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("DeletedDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("ReadDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("UserId", "NotificationId")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("NotificationId");
|
||||
|
||||
b.ToTable("NotificationStatus", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.AccessPolicy", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@ -2369,6 +2440,40 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
.HasForeignKey("OrganizationId");
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Organization");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.NotificationStatus", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.NotificationCenter.Models.Notification", "Notification")
|
||||
.WithMany()
|
||||
.HasForeignKey("NotificationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Notification");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.SecretsManager.Models.ServiceAccount", "ServiceAccount")
|
||||
|
Loading…
Reference in New Issue
Block a user