Skip to content

Commit

Permalink
Db cleanup
Browse files Browse the repository at this point in the history
might wanna take a look at this
  • Loading branch information
LuisMend12 committed Jan 25, 2025
1 parent 7e14ab4 commit b16bd1a
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Valour/Database/PermissionsNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Valour.Shared.Models;

namespace Valour.Database;
Expand Down Expand Up @@ -67,5 +68,56 @@ public class PermissionsNode : ISharedPermissionsNode
/// </summary>
[Column("target_type")]
public ChannelTypeEnum TargetType { get; set; }


public static void SetUpDbModel(ModelBuilder builder)
{
builder.Entity<PermissionsNode>(e =>
{
// ToTable
e.ToTable("permissions_nodes");

// Key
e.HasKey(x => x.Id);

// Properties

e.Property(x => x.Id)
.HasColumnName("id");

e.Property(x => x.PlanetId)
.HasColumnName("planet_id");

e.Property(x => x.Code)
.HasColumnName("code");

e.Property(x => x.Mask)
.HasColumnName("mask");

e.Property(x => x.RoleId)
.HasColumnName("role_id");

e.Property(x => x.TargetId)
.HasColumnName("target_id");

e.Property(x => x.TargetType)
.HasColumnName("target_type");

// Relationships

e.HasOne(x => x.Planet)
.WithMany(x => x.PlanetNodes)
.HasForeignKey(x => x.PlanetId);


e.HasOne(x => x.Role)
.WithMany(x => x.PermissionNodes)
.HasForeignKey(x => x.RoleId);

e.HasOne(x => x.Target)
.WithMany(x => x.Permissions)
.HasForeignKey(x => x.TargetId);
});
}
}

3 changes: 3 additions & 0 deletions Valour/Database/Planet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class Planet : ISharedPlanet
[InverseProperty("Planet")]
public virtual ICollection<Channel> Channels { get; set; }

[InverseProperty("Planet")]
public virtual ICollection<PermissionsNode> PlanetNodes { get; set; }

[InverseProperty("Planet")]
public virtual ICollection<PlanetInvite> Invites { get; set; }

Expand Down
91 changes: 91 additions & 0 deletions Valour/Database/PlanetRole.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Valour.Shared.Authorization;
using Valour.Shared.Models;

Expand Down Expand Up @@ -102,4 +103,94 @@ public uint GetAuthority() =>

public bool HasPermission(PlanetPermission perm) =>
ISharedPlanetRole.HasPermission(this, perm);


public static void SetUpDbModel(ModelBuilder builder)
{
builder.Entity<PlanetRole>(e =>
{
// ToTable
e.ToTable("planet_roles");

// Key

e.HasKey(x => x.Id);

// Properties

e.Property(x => x.Id)
.HasColumnName("id");

e.Property(x => x.IsAdmin)
.HasColumnName("is_admin");

e.Property(x => x.PlanetId)
.HasColumnName("planet_id");

e.Property(x => x.Position)
.HasColumnName("position");

e.Property(x => x.IsDefault)
.HasColumnName("is_default");

e.Property(x => x.Permissions)
.HasColumnName("permissions");

e.Property(x => x.ChatPermissions)
.HasColumnName("chat_perms");

e.Property(x => x.CategoryPermissions)
.HasColumnName("category_perms");

e.Property(x => x.VoicePermissions)
.HasColumnName("voice_perms");

e.Property(x => x.Color)
.HasColumnName("color");

e.Property(x => x.Bold)
.HasColumnName("bold");

e.Property(x => x.Italics)
.HasColumnName("italics");

e.Property(x => x.Name)
.HasColumnName("name");

e.Property(x => x.AnyoneCanMention)
.HasColumnName("anyone_can_mention");

// Relationships

e.HasOne(x => x.Planet)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.PlanetId);

// Indices

e.HasIndex(x => x.Position);

e.HasIndex(x => x.IsDefault);

e.HasIndex(x => x.Permissions);

e.HasIndex(x => x.ChatPermissions);

e.HasIndex(x => x.CategoryPermissions);

e.HasIndex(x => x.VoicePermissions);

e.HasIndex(x => x.Color);

e.HasIndex(x => x.Bold);

e.HasIndex(x => x.Italics);

e.HasIndex(x => x.PlanetId);




});
}
}
38 changes: 38 additions & 0 deletions Valour/Database/PrimaryNodeConnection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace Valour.Database;

Expand Down Expand Up @@ -38,4 +39,41 @@ public class PrimaryNodeConnection
/// </summary>
[Column("open_time")]
public DateTime OpenTime { get; set; }


public static void SetUpDbModel(ModelBuilder builder)
{
builder.Entity<PrimaryNodeConnection>(e =>
{
// ToTable
e.ToTable("primary_node_connections");

// Key
e.HasKey(x => x.ConnectionId);

// Properties

e.Property(x => x.ConnectionId)
.HasColumnName("connection_id");

e.Property(x => x.NodeId)
.HasColumnName("node_id");

e.Property(x => x.UserId)
.HasColumnName("user_id");

e.Property(x => x.OpenTime)
.HasColumnName("open_time")
.HasConversion(
x => x,
x => new DateTime(x.Ticks, DateTimeKind.Utc)
);

// Relationships

// Indices

e.HasIndex(x => x.UserId);
});
}
}
25 changes: 25 additions & 0 deletions Valour/Database/UserFriend.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Valour.Shared.Models;

namespace Valour.Database;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class UserFriend : ISharedUserFriend
/// <summary>
/// The id of the user friend model
/// </summary>
[Column("model_id")]
public long Id { get; set; }

/// <summary>
Expand All @@ -55,4 +57,27 @@ public object GetId()
{
return (UserId, FriendId);
}

public static void SetUpDbModel(ModelBuilder builder)
{
builder.Entity<UserFriend>(e =>
{
// ToTable
e.ToTable("user_friends");

// Key
e.HasKey(x => x.GetId());

// Properties
e.Property(x => x.UserId)
.HasColumnName("user_id");

e.Property(x => x.FriendId)
.HasColumnName("friend_id");

e.Property(x => x.Id)
.HasColumnName("id");

});
}
}

0 comments on commit b16bd1a

Please sign in to comment.