-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Device deactivation * Check active status in service * Format and work around potential deadlocks
- Loading branch information
1 parent
751fd33
commit a04df4b
Showing
19 changed files
with
8,801 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
CREATE TABLE [dbo].[Device] ( | ||
[Id] UNIQUEIDENTIFIER NOT NULL, | ||
[UserId] UNIQUEIDENTIFIER NOT NULL, | ||
[Name] NVARCHAR (50) NOT NULL, | ||
[Type] SMALLINT NOT NULL, | ||
[Identifier] NVARCHAR (50) NOT NULL, | ||
[PushToken] NVARCHAR (255) NULL, | ||
[CreationDate] DATETIME2 (7) NOT NULL, | ||
[RevisionDate] DATETIME2 (7) NOT NULL, | ||
[EncryptedUserKey] VARCHAR (MAX) NULL, | ||
[EncryptedPublicKey] VARCHAR (MAX) NULL, | ||
[EncryptedPrivateKey] VARCHAR (MAX) NULL, | ||
[Id] UNIQUEIDENTIFIER NOT NULL, | ||
[UserId] UNIQUEIDENTIFIER NOT NULL, | ||
[Name] NVARCHAR (50) NOT NULL, | ||
[Type] SMALLINT NOT NULL, | ||
[Identifier] NVARCHAR (50) NOT NULL, | ||
[PushToken] NVARCHAR (255) NULL, | ||
[CreationDate] DATETIME2 (7) NOT NULL, | ||
[RevisionDate] DATETIME2 (7) NOT NULL, | ||
[EncryptedUserKey] VARCHAR (MAX) NULL, | ||
[EncryptedPublicKey] VARCHAR (MAX) NULL, | ||
[EncryptedPrivateKey] VARCHAR (MAX) NULL, | ||
[Active] BIT NOT NULL CONSTRAINT [DF_Device_Active] DEFAULT (1), | ||
CONSTRAINT [PK_Device] PRIMARY KEY CLUSTERED ([Id] ASC), | ||
CONSTRAINT [FK_Device_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) | ||
); | ||
|
||
|
||
GO | ||
CREATE UNIQUE NONCLUSTERED INDEX [UX_Device_UserId_Identifier] | ||
ON [dbo].[Device]([UserId] ASC, [Identifier] ASC); | ||
|
||
|
||
GO | ||
CREATE NONCLUSTERED INDEX [IX_Device_Identifier] | ||
ON [dbo].[Device]([Identifier] ASC); |
118 changes: 118 additions & 0 deletions
118
util/Migrator/DbScripts/2024-10-31-00_DeviceActivation.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
SET DEADLOCK_PRIORITY HIGH | ||
GO | ||
|
||
-- add column | ||
IF COL_LENGTH('[dbo].[Device]', 'Active') IS NULL | ||
BEGIN | ||
ALTER TABLE | ||
[dbo].[Device] | ||
ADD | ||
[Active] BIT NOT NULL CONSTRAINT [DF_Device_Active] DEFAULT (1) | ||
END | ||
GO | ||
|
||
-- refresh view | ||
CREATE OR ALTER VIEW [dbo].[DeviceView] | ||
AS | ||
SELECT | ||
* | ||
FROM | ||
[dbo].[Device] | ||
GO | ||
|
||
-- drop now-unused proc for deletion | ||
IF OBJECT_ID('[dbo].[Device_DeleteById]') IS NOT NULL | ||
BEGIN | ||
DROP PROCEDURE [dbo].[Device_DeleteById] | ||
END | ||
GO | ||
|
||
-- refresh procs | ||
CREATE OR ALTER PROCEDURE [dbo].[Device_Create] | ||
@Id UNIQUEIDENTIFIER OUTPUT, | ||
@UserId UNIQUEIDENTIFIER, | ||
@Name NVARCHAR(50), | ||
@Type TINYINT, | ||
@Identifier NVARCHAR(50), | ||
@PushToken NVARCHAR(255), | ||
@CreationDate DATETIME2(7), | ||
@RevisionDate DATETIME2(7), | ||
@EncryptedUserKey VARCHAR(MAX) = NULL, | ||
@EncryptedPublicKey VARCHAR(MAX) = NULL, | ||
@EncryptedPrivateKey VARCHAR(MAX) = NULL, | ||
@Active BIT = 1 | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON | ||
|
||
INSERT INTO [dbo].[Device] | ||
( | ||
[Id], | ||
[UserId], | ||
[Name], | ||
[Type], | ||
[Identifier], | ||
[PushToken], | ||
[CreationDate], | ||
[RevisionDate], | ||
[EncryptedUserKey], | ||
[EncryptedPublicKey], | ||
[EncryptedPrivateKey], | ||
[Active] | ||
) | ||
VALUES | ||
( | ||
@Id, | ||
@UserId, | ||
@Name, | ||
@Type, | ||
@Identifier, | ||
@PushToken, | ||
@CreationDate, | ||
@RevisionDate, | ||
@EncryptedUserKey, | ||
@EncryptedPublicKey, | ||
@EncryptedPrivateKey, | ||
@Active | ||
) | ||
END | ||
GO | ||
|
||
CREATE OR ALTER PROCEDURE [dbo].[Device_Update] | ||
@Id UNIQUEIDENTIFIER, | ||
@UserId UNIQUEIDENTIFIER, | ||
@Name NVARCHAR(50), | ||
@Type TINYINT, | ||
@Identifier NVARCHAR(50), | ||
@PushToken NVARCHAR(255), | ||
@CreationDate DATETIME2(7), | ||
@RevisionDate DATETIME2(7), | ||
@EncryptedUserKey VARCHAR(MAX) = NULL, | ||
@EncryptedPublicKey VARCHAR(MAX) = NULL, | ||
@EncryptedPrivateKey VARCHAR(MAX) = NULL, | ||
@Active BIT = 1 | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON | ||
|
||
UPDATE | ||
[dbo].[Device] | ||
SET | ||
[UserId] = @UserId, | ||
[Name] = @Name, | ||
[Type] = @Type, | ||
[Identifier] = @Identifier, | ||
[PushToken] = @PushToken, | ||
[CreationDate] = @CreationDate, | ||
[RevisionDate] = @RevisionDate, | ||
[EncryptedUserKey] = @EncryptedUserKey, | ||
[EncryptedPublicKey] = @EncryptedPublicKey, | ||
[EncryptedPrivateKey] = @EncryptedPrivateKey, | ||
[Active] = @Active | ||
WHERE | ||
[Id] = @Id | ||
END | ||
GO | ||
|
||
SET DEADLOCK_PRIORITY NORMAL | ||
GO |
Oops, something went wrong.