Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Add user rank
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabriguglia committed Feb 15, 2022
1 parent 1d76124 commit 152ad59
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 152 deletions.
68 changes: 36 additions & 32 deletions sql/AtlesConnection.Migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GO
BEGIN TRANSACTION;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [PermissionSet] (
[Id] uniqueidentifier NOT NULL,
Expand All @@ -23,7 +23,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [Site] (
[Id] uniqueidentifier NOT NULL,
Expand All @@ -42,7 +42,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [User] (
[Id] uniqueidentifier NOT NULL,
Expand All @@ -59,19 +59,21 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [UserRank] (
[Id] uniqueidentifier NOT NULL,
[Name] nvarchar(max) NULL,
[Order] int NOT NULL,
[Description] nvarchar(max) NULL,
[SortOrder] int NOT NULL,
[Badge] nvarchar(max) NULL,
[Role] nvarchar(max) NULL,
CONSTRAINT [PK_UserRank] PRIMARY KEY ([Id])
);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [Permission] (
[Type] int NOT NULL,
Expand All @@ -83,7 +85,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [Category] (
[Id] uniqueidentifier NOT NULL,
Expand All @@ -101,7 +103,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [Event] (
[Id] uniqueidentifier NOT NULL,
Expand All @@ -118,7 +120,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [Subscription] (
[UserId] uniqueidentifier NOT NULL,
Expand All @@ -130,20 +132,22 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [UserLevel] (
CREATE TABLE [UserRankRule] (
[UserRankId] uniqueidentifier NOT NULL,
[Type] int NOT NULL,
[Name] nvarchar(max) NULL,
[Description] nvarchar(max) NULL,
[Count] int NOT NULL,
[Badge] nvarchar(max) NULL,
CONSTRAINT [PK_UserLevel] PRIMARY KEY ([UserRankId], [Type]),
CONSTRAINT [FK_UserLevel_UserRank_UserRankId] FOREIGN KEY ([UserRankId]) REFERENCES [UserRank] ([Id]) ON DELETE CASCADE
CONSTRAINT [PK_UserRankRule] PRIMARY KEY ([UserRankId], [Type]),
CONSTRAINT [FK_UserRankRule_UserRank_UserRankId] FOREIGN KEY ([UserRankId]) REFERENCES [UserRank] ([Id]) ON DELETE CASCADE
);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [Forum] (
[Id] uniqueidentifier NOT NULL,
Expand All @@ -164,7 +168,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [Post] (
[Id] uniqueidentifier NOT NULL,
Expand Down Expand Up @@ -194,7 +198,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [PostReaction] (
[PostId] uniqueidentifier NOT NULL,
Expand All @@ -208,7 +212,7 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE TABLE [PostReactionSummary] (
[PostId] uniqueidentifier NOT NULL,
Expand All @@ -220,88 +224,88 @@ BEGIN
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Category_PermissionSetId] ON [Category] ([PermissionSetId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Category_SiteId] ON [Category] ([SiteId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Event_UserId] ON [Event] ([UserId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Forum_CategoryId] ON [Forum] ([CategoryId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Forum_LastPostId] ON [Forum] ([LastPostId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Forum_PermissionSetId] ON [Forum] ([PermissionSetId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Post_CreatedBy] ON [Post] ([CreatedBy]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Post_ForumId] ON [Post] ([ForumId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Post_LastReplyId] ON [Post] ([LastReplyId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Post_ModifiedBy] ON [Post] ([ModifiedBy]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_Post_TopicId] ON [Post] ([TopicId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
CREATE INDEX [IX_PostReaction_UserId] ON [PostReaction] ([UserId]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
ALTER TABLE [Forum] ADD CONSTRAINT [FK_Forum_Post_LastPostId] FOREIGN KEY ([LastPostId]) REFERENCES [Post] ([Id]);
END;
GO

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220209153725_InitialCreate')
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20220215094044_InitialCreate')
BEGIN
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20220209153725_InitialCreate', N'6.0.1');
VALUES (N'20220215094044_InitialCreate', N'6.0.1');
END;
GO

Expand Down
8 changes: 5 additions & 3 deletions src/Atles.Data/Configurations/UserRankConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ public void Configure(EntityTypeBuilder<UserRank> builder)
{
builder.ToTable("UserRank");

builder.OwnsMany(s => s.UserLevels, b =>
builder.OwnsMany(s => s.UserRankRules, b =>
{
b.ToTable("UserLevel")
b.ToTable("UserRankRule")
.HasKey("UserRankId", "Type");

b.Property(e => e.Name);
b.Property(e => e.Description);
b.Property(e => e.UserRankId);
b.Property(e => e.Type);
b.Property(e => e.Count);
b.Property(e => e.Badge);
});

var navigation = builder.Metadata.FindNavigation(nameof(UserRank.UserLevels));
var navigation = builder.Metadata.FindNavigation(nameof(UserRank.UserRankRules));
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Order = table.Column<int>(type: "int", nullable: false),
Badge = table.Column<string>(type: "nvarchar(max)", nullable: true)
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
SortOrder = table.Column<int>(type: "int", nullable: false),
Badge = table.Column<string>(type: "nvarchar(max)", nullable: true),
Role = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
Expand Down Expand Up @@ -166,19 +168,21 @@ protected override void Up(MigrationBuilder migrationBuilder)
});

migrationBuilder.CreateTable(
name: "UserLevel",
name: "UserRankRule",
columns: table => new
{
UserRankId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Type = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Count = table.Column<int>(type: "int", nullable: false),
Badge = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UserLevel", x => new { x.UserRankId, x.Type });
table.PrimaryKey("PK_UserRankRule", x => new { x.UserRankId, x.Type });
table.ForeignKey(
name: "FK_UserLevel_UserRank_UserRankId",
name: "FK_UserRankRule_UserRank_UserRankId",
column: x => x.UserRankId,
principalTable: "UserRank",
principalColumn: "Id",
Expand Down Expand Up @@ -420,7 +424,7 @@ protected override void Down(MigrationBuilder migrationBuilder)
name: "Subscription");

migrationBuilder.DropTable(
name: "UserLevel");
name: "UserRankRule");

migrationBuilder.DropTable(
name: "UserRank");
Expand Down
Loading

0 comments on commit 152ad59

Please sign in to comment.