mirror of
https://github.com/bitwarden/server.git
synced 2026-02-13 20:33:20 +08:00
[PM 30100][Server] Subscription Discount Database Infrastructure (#6936)
* Implement the detail Subscription Discount Database Infrastructure * Change string to string list * fix lint error * Create all missing database object definition files * Regenerate EF migrations with Designer files The previous migrations were missing .Designer.cs files. This commit: - Removes the incomplete migration files - Regenerates all three provider migrations (MySQL, Postgres, SQLite) with proper Designer files - Updates DatabaseContextModelSnapshot.cs for each provider 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix failing database * Resolve the lint warnings * Resolve the database failure * Fix the build Lint * resolve the dbops reviews * Add the default value --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
-- Table
|
||||
IF OBJECT_ID('[dbo].[SubscriptionDiscount]') IS NULL
|
||||
BEGIN
|
||||
CREATE TABLE [dbo].[SubscriptionDiscount] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[StripeCouponId] VARCHAR(50) NOT NULL,
|
||||
[StripeProductIds] NVARCHAR(MAX) NULL,
|
||||
[PercentOff] DECIMAL(5,2) NULL,
|
||||
[AmountOff] BIGINT NULL,
|
||||
[Currency] VARCHAR(10) NULL,
|
||||
[Duration] VARCHAR(20) NOT NULL,
|
||||
[DurationInMonths] INT NULL,
|
||||
[Name] NVARCHAR(100) NULL,
|
||||
[StartDate] DATETIME2(7) NOT NULL,
|
||||
[EndDate] DATETIME2(7) NOT NULL,
|
||||
[AudienceType] INT NOT NULL CONSTRAINT [DF_SubscriptionDiscount_AudienceType] DEFAULT (0),
|
||||
[CreationDate] DATETIME2(7) NOT NULL,
|
||||
[RevisionDate] DATETIME2(7) NOT NULL,
|
||||
CONSTRAINT [PK_SubscriptionDiscount] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [IX_SubscriptionDiscount_StripeCouponId] UNIQUE ([StripeCouponId])
|
||||
);
|
||||
END
|
||||
GO
|
||||
|
||||
-- Index for date range queries
|
||||
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'IX_SubscriptionDiscount_DateRange' AND object_id = OBJECT_ID('[dbo].[SubscriptionDiscount]'))
|
||||
BEGIN
|
||||
CREATE INDEX [IX_SubscriptionDiscount_DateRange] ON [dbo].[SubscriptionDiscount]
|
||||
([StartDate], [EndDate]);
|
||||
END
|
||||
GO
|
||||
|
||||
-- View
|
||||
CREATE OR ALTER VIEW [dbo].[SubscriptionDiscountView]
|
||||
AS
|
||||
SELECT *
|
||||
FROM
|
||||
[dbo].[SubscriptionDiscount]
|
||||
GO
|
||||
|
||||
-- Stored Procedures: Create
|
||||
CREATE OR ALTER PROCEDURE [dbo].[SubscriptionDiscount_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@StripeCouponId VARCHAR(50),
|
||||
@StripeProductIds NVARCHAR(MAX),
|
||||
@PercentOff DECIMAL(5,2),
|
||||
@AmountOff BIGINT,
|
||||
@Currency VARCHAR(10),
|
||||
@Duration VARCHAR(20),
|
||||
@DurationInMonths INT,
|
||||
@Name NVARCHAR(100),
|
||||
@StartDate DATETIME2(7),
|
||||
@EndDate DATETIME2(7),
|
||||
@AudienceType INT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[SubscriptionDiscount]
|
||||
(
|
||||
[Id],
|
||||
[StripeCouponId],
|
||||
[StripeProductIds],
|
||||
[PercentOff],
|
||||
[AmountOff],
|
||||
[Currency],
|
||||
[Duration],
|
||||
[DurationInMonths],
|
||||
[Name],
|
||||
[StartDate],
|
||||
[EndDate],
|
||||
[AudienceType],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@StripeCouponId,
|
||||
@StripeProductIds,
|
||||
@PercentOff,
|
||||
@AmountOff,
|
||||
@Currency,
|
||||
@Duration,
|
||||
@DurationInMonths,
|
||||
@Name,
|
||||
@StartDate,
|
||||
@EndDate,
|
||||
@AudienceType,
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: DeleteById
|
||||
CREATE OR ALTER PROCEDURE [dbo].[SubscriptionDiscount_DeleteById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[SubscriptionDiscount]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: ReadById
|
||||
CREATE OR ALTER PROCEDURE [dbo].[SubscriptionDiscount_ReadById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[SubscriptionDiscountView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: Update
|
||||
CREATE OR ALTER PROCEDURE [dbo].[SubscriptionDiscount_Update]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@StripeCouponId VARCHAR(50),
|
||||
@StripeProductIds NVARCHAR(MAX),
|
||||
@PercentOff DECIMAL(5,2),
|
||||
@AmountOff BIGINT,
|
||||
@Currency VARCHAR(10),
|
||||
@Duration VARCHAR(20),
|
||||
@DurationInMonths INT,
|
||||
@Name NVARCHAR(100),
|
||||
@StartDate DATETIME2(7),
|
||||
@EndDate DATETIME2(7),
|
||||
@AudienceType INT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[SubscriptionDiscount]
|
||||
SET
|
||||
[StripeCouponId] = @StripeCouponId,
|
||||
[StripeProductIds] = @StripeProductIds,
|
||||
[PercentOff] = @PercentOff,
|
||||
[AmountOff] = @AmountOff,
|
||||
[Currency] = @Currency,
|
||||
[Duration] = @Duration,
|
||||
[DurationInMonths] = @DurationInMonths,
|
||||
[Name] = @Name,
|
||||
[StartDate] = @StartDate,
|
||||
[EndDate] = @EndDate,
|
||||
[AudienceType] = @AudienceType,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: ReadActive (returns discounts within date range)
|
||||
CREATE OR ALTER PROCEDURE [dbo].[SubscriptionDiscount_ReadActive]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[SubscriptionDiscountView]
|
||||
WHERE
|
||||
[StartDate] <= GETUTCDATE()
|
||||
AND [EndDate] >= GETUTCDATE()
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: ReadByStripeCouponId
|
||||
CREATE OR ALTER PROCEDURE [dbo].[SubscriptionDiscount_ReadByStripeCouponId]
|
||||
@StripeCouponId VARCHAR(50)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[SubscriptionDiscountView]
|
||||
WHERE
|
||||
[StripeCouponId] = @StripeCouponId
|
||||
END
|
||||
GO
|
||||
Reference in New Issue
Block a user