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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Sql/dbo/Stored Procedures/Event_Create.sql b/src/Sql/dbo/Stored Procedures/Event_Create.sql
index 9b55c7fb6f..665d6a12c9 100644
--- a/src/Sql/dbo/Stored Procedures/Event_Create.sql
+++ b/src/Sql/dbo/Stored Procedures/Event_Create.sql
@@ -3,6 +3,7 @@
@Type INT,
@UserId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
+ @InstallationId UNIQUEIDENTIFIER,
@ProviderId UNIQUEIDENTIFIER,
@CipherId UNIQUEIDENTIFIER,
@CollectionId UNIQUEIDENTIFIER,
@@ -25,6 +26,7 @@ BEGIN
[Type],
[UserId],
[OrganizationId],
+ [InstallationId],
[ProviderId],
[CipherId],
[CollectionId],
@@ -44,6 +46,7 @@ BEGIN
@Type,
@UserId,
@OrganizationId,
+ @InstallationId,
@ProviderId,
@CipherId,
@CollectionId,
diff --git a/src/Sql/dbo/Stored Procedures/Event_ReadById.sql b/src/Sql/dbo/Stored Procedures/Event_ReadById.sql
new file mode 100644
index 0000000000..e14790b934
--- /dev/null
+++ b/src/Sql/dbo/Stored Procedures/Event_ReadById.sql
@@ -0,0 +1,13 @@
+CREATE PROCEDURE [dbo].[Event_ReadById]
+ @Id UNIQUEIDENTIFIER
+AS
+BEGIN
+ SET NOCOUNT ON
+
+ SELECT
+ *
+ FROM
+ [dbo].[Event]
+ WHERE
+ [Id] = @Id
+END
diff --git a/src/Sql/dbo/Stored Procedures/OrganizationSponsorship_ReadLatestBySponsoringOrganizationId.sql b/src/Sql/dbo/Stored Procedures/OrganizationSponsorship_ReadLatestBySponsoringOrganizationId.sql
new file mode 100644
index 0000000000..90449ce835
--- /dev/null
+++ b/src/Sql/dbo/Stored Procedures/OrganizationSponsorship_ReadLatestBySponsoringOrganizationId.sql
@@ -0,0 +1,13 @@
+CREATE PROCEDURE [dbo].[OrganizationSponsorship_ReadLatestBySponsoringOrganizationId]
+ @SponsoringOrganizationId UNIQUEIDENTIFIER
+AS
+BEGIN
+ SELECT TOP 1
+ [LastSyncDate]
+ FROM
+ [dbo].[OrganizationSponsorshipView]
+ WHERE
+ [SponsoringOrganizationId] = @SponsoringOrganizationId AND
+ [LastSyncDate] IS NOT NULL
+ ORDER BY [LastSyncDate] DESC
+END
diff --git a/src/Sql/dbo/Stored Procedures/SsoConfig_ReadById.sql b/src/Sql/dbo/Stored Procedures/SsoConfig_ReadById.sql
index fbca19bf15..077632d0a0 100644
--- a/src/Sql/dbo/Stored Procedures/SsoConfig_ReadById.sql
+++ b/src/Sql/dbo/Stored Procedures/SsoConfig_ReadById.sql
@@ -1,4 +1,4 @@
-CREATE PROCEDURE [dbo].[SsoUser_ReadById]
+CREATE PROCEDURE [dbo].[SsoConfig_ReadById]
@Id BIGINT
AS
BEGIN
@@ -7,7 +7,7 @@ BEGIN
SELECT
*
FROM
- [dbo].[SsoUserView]
+ [dbo].[SsoConfigView]
WHERE
[Id] = @Id
-END
\ No newline at end of file
+END
diff --git a/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByOrganizationUserIds.sql b/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByOrganizationUserIds.sql
index 9daa82fcc7..ea43263484 100644
--- a/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByOrganizationUserIds.sql
+++ b/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByOrganizationUserIds.sql
@@ -4,15 +4,24 @@ AS
BEGIN
SET NOCOUNT ON
+ SELECT
+ OU.UserId
+ INTO
+ #UserIds
+ FROM
+ [dbo].[OrganizationUser] OU
+ INNER JOIN
+ @OrganizationUserIds OUIds ON OUIds.Id = OU.Id
+ WHERE
+ OU.[Status] = 2 -- Confirmed
+
UPDATE
U
SET
U.[AccountRevisionDate] = GETUTCDATE()
FROM
- @OrganizationUserIds OUIDs
+ [dbo].[User] U
INNER JOIN
- [dbo].[OrganizationUser] OU ON OUIDs.Id = OU.Id AND OU.[Status] = 2 -- Confirmed
- INNER JOIN
- [dbo].[User] U ON OU.UserId = U.Id
+ #UserIds ON U.[Id] = #UserIds.[UserId]
END
GO
diff --git a/src/Sql/dbo/Tables/OrganizationSponsorship.sql b/src/Sql/dbo/Tables/OrganizationSponsorship.sql
index 79c92edcee..7377162b5c 100644
--- a/src/Sql/dbo/Tables/OrganizationSponsorship.sql
+++ b/src/Sql/dbo/Tables/OrganizationSponsorship.sql
@@ -6,7 +6,7 @@ CREATE TABLE [dbo].[OrganizationSponsorship] (
[FriendlyName] NVARCHAR(256) NULL,
[OfferedToEmail] NVARCHAR (256) NULL,
[PlanSponsorshipType] TINYINT NULL,
- [ToDelete] BIT NULL,
+ [ToDelete] BIT DEFAULT (0) NOT NULL,
[LastSyncDate] DATETIME2 (7) NULL,
[ValidUntil] DATETIME2 (7) NULL,
CONSTRAINT [PK_OrganizationSponsorship] PRIMARY KEY CLUSTERED ([Id] ASC),
diff --git a/src/Sql/dbo/Tables/User.sql b/src/Sql/dbo/Tables/User.sql
index 13f7048115..ddc0b8ab35 100644
--- a/src/Sql/dbo/Tables/User.sql
+++ b/src/Sql/dbo/Tables/User.sql
@@ -1,40 +1,40 @@
CREATE TABLE [dbo].[User] (
- [Id] UNIQUEIDENTIFIER NOT NULL,
- [Name] NVARCHAR (50) NULL,
- [Email] NVARCHAR (256) NOT NULL,
- [EmailVerified] BIT NOT NULL,
- [MasterPassword] NVARCHAR (300) NULL,
- [MasterPasswordHint] NVARCHAR (50) NULL,
- [Culture] NVARCHAR (10) NOT NULL,
- [SecurityStamp] NVARCHAR (50) NOT NULL,
- [TwoFactorProviders] NVARCHAR (MAX) NULL,
- [TwoFactorRecoveryCode] NVARCHAR (32) NULL,
- [EquivalentDomains] NVARCHAR (MAX) NULL,
- [ExcludedGlobalEquivalentDomains] NVARCHAR (MAX) NULL,
- [AccountRevisionDate] DATETIME2 (7) NOT NULL,
- [Key] VARCHAR (MAX) NULL,
- [PublicKey] VARCHAR (MAX) NULL,
- [PrivateKey] VARCHAR (MAX) NULL,
- [Premium] BIT NOT NULL,
- [PremiumExpirationDate] DATETIME2 (7) NULL,
- [RenewalReminderDate] DATETIME2 (7) NULL,
- [Storage] BIGINT NULL,
- [MaxStorageGb] SMALLINT NULL,
- [Gateway] TINYINT NULL,
- [GatewayCustomerId] VARCHAR (50) NULL,
- [GatewaySubscriptionId] VARCHAR (50) NULL,
- [ReferenceData] NVARCHAR (MAX) NULL,
- [LicenseKey] VARCHAR (100) NULL,
- [Kdf] TINYINT NOT NULL,
- [KdfIterations] INT NOT NULL,
- [CreationDate] DATETIME2 (7) NOT NULL,
- [RevisionDate] DATETIME2 (7) NOT NULL,
- [ApiKey] VARCHAR (30) NOT NULL,
- [ForcePasswordReset] BIT NOT NULL,
- [UsesKeyConnector] BIT NOT NULL,
- [FailedLoginCount] INT NOT NULL,
- [LastFailedLoginDate] DATETIME2 (7) NULL,
- [UnknownDeviceVerificationEnabled] BIT NULL,
+ [Id] UNIQUEIDENTIFIER NOT NULL,
+ [Name] NVARCHAR (50) NULL,
+ [Email] NVARCHAR (256) NOT NULL,
+ [EmailVerified] BIT NOT NULL,
+ [MasterPassword] NVARCHAR (300) NULL,
+ [MasterPasswordHint] NVARCHAR (50) NULL,
+ [Culture] NVARCHAR (10) NOT NULL,
+ [SecurityStamp] NVARCHAR (50) NOT NULL,
+ [TwoFactorProviders] NVARCHAR (MAX) NULL,
+ [TwoFactorRecoveryCode] NVARCHAR (32) NULL,
+ [EquivalentDomains] NVARCHAR (MAX) NULL,
+ [ExcludedGlobalEquivalentDomains] NVARCHAR (MAX) NULL,
+ [AccountRevisionDate] DATETIME2 (7) NOT NULL,
+ [Key] VARCHAR (MAX) NULL,
+ [PublicKey] VARCHAR (MAX) NULL,
+ [PrivateKey] VARCHAR (MAX) NULL,
+ [Premium] BIT NOT NULL,
+ [PremiumExpirationDate] DATETIME2 (7) NULL,
+ [RenewalReminderDate] DATETIME2 (7) NULL,
+ [Storage] BIGINT NULL,
+ [MaxStorageGb] SMALLINT NULL,
+ [Gateway] TINYINT NULL,
+ [GatewayCustomerId] VARCHAR (50) NULL,
+ [GatewaySubscriptionId] VARCHAR (50) NULL,
+ [ReferenceData] NVARCHAR (MAX) NULL,
+ [LicenseKey] VARCHAR (100) NULL,
+ [Kdf] TINYINT NOT NULL,
+ [KdfIterations] INT NOT NULL,
+ [CreationDate] DATETIME2 (7) NOT NULL,
+ [RevisionDate] DATETIME2 (7) NOT NULL,
+ [ApiKey] VARCHAR (30) NOT NULL,
+ [ForcePasswordReset] BIT NOT NULL,
+ [UsesKeyConnector] BIT NOT NULL,
+ [FailedLoginCount] INT CONSTRAINT [D_User_FailedLoginCount] DEFAULT ((0)) NOT NULL,
+ [LastFailedLoginDate] DATETIME2 (7) NULL,
+ [UnknownDeviceVerificationEnabled] BIT CONSTRAINT [D_User_UnknownDeviceVerificationEnabled] DEFAULT ((1)) NOT NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ([Id] ASC)
);
diff --git a/src/Sql/dbo/Views/OrganizationSponsorship.sql b/src/Sql/dbo/Views/OrganizationSponsorship.sql
new file mode 100644
index 0000000000..8135d207d9
--- /dev/null
+++ b/src/Sql/dbo/Views/OrganizationSponsorship.sql
@@ -0,0 +1,6 @@
+CREATE VIEW [dbo].[OrganizationSponsorshipView]
+AS
+SELECT
+ *
+FROM
+ [dbo].[OrganizationSponsorship]
diff --git a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql
index 01f327b085..edfb7e0f63 100644
--- a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql
+++ b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql
@@ -40,7 +40,7 @@ SELECT
OS.[ValidUntil] FamilySponsorshipValidUntil
FROM
[dbo].[OrganizationUser] OU
-INNER JOIN
+LEFT JOIN
[dbo].[Organization] O ON O.[Id] = OU.[OrganizationId]
LEFT JOIN
[dbo].[SsoUser] SU ON SU.[UserId] = OU.[UserId] AND SU.[OrganizationId] = OU.[OrganizationId]
diff --git a/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql b/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql
index 8f9dd88feb..21ce0d2da9 100644
--- a/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql
+++ b/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql
@@ -8,7 +8,10 @@ SELECT
PO.[Key],
PO.[Settings],
PO.[CreationDate],
- PO.[RevisionDate]
+ PO.[RevisionDate],
+ (SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status = 2) UserCount,
+ O.[Seats],
+ O.[Plan]
FROM
[dbo].[ProviderOrganization] PO
LEFT JOIN
diff --git a/util/Migrator/DbScripts/2018-02-28_00_LoginUris.sql b/util/Migrator/DbScripts/2018-02-28_00_LoginUris.sql
index 6e03d5c9fc..d2b3172def 100644
--- a/util/Migrator/DbScripts/2018-02-28_00_LoginUris.sql
+++ b/util/Migrator/DbScripts/2018-02-28_00_LoginUris.sql
@@ -14,6 +14,8 @@
}
*/
+SET NOCOUNT ON;
+
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'CompletedIds')
BEGIN
CREATE TABLE [CompletedIds] ([Id] UNIQUEIDENTIFIER PRIMARY KEY)
diff --git a/util/Migrator/DbScripts/2018-03-12_00_FixLoginUris.sql b/util/Migrator/DbScripts/2018-03-12_00_FixLoginUris.sql
index d45592dc2c..40599f346b 100644
--- a/util/Migrator/DbScripts/2018-03-12_00_FixLoginUris.sql
+++ b/util/Migrator/DbScripts/2018-03-12_00_FixLoginUris.sql
@@ -14,6 +14,8 @@
}
*/
+SET NOCOUNT ON;
+
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'CompletedIds')
BEGIN
CREATE TABLE [CompletedIds] ([Id] UNIQUEIDENTIFIER PRIMARY KEY)