Skip to content

Commit

Permalink
Add models and initial migration for database (#24)
Browse files Browse the repository at this point in the history
* Add models and initial migration for database

* AddDbContext before builder.Build()

* Cleanup proj file

Co-authored-by: Brendan Enrick <[email protected]>
  • Loading branch information
kirkbrauer and benrick authored Nov 26, 2022
1 parent 81ae4e2 commit f02ab0e
Show file tree
Hide file tree
Showing 204 changed files with 23,765 additions and 14 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "7.0.0",
"commands": [
"dotnet-ef"
]
}
}
}
5 changes: 5 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0" />
<PackageVersion Include="EFCore.NamingConventions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="AutoFixture" Version="4.17.0" />
<PackageVersion Include="AutoFixture.Xunit2" Version="4.17.0" />
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ To run the WebApp, you can navigate to the `\WebApp` folder from your preferred
dotnet run watch
```

### Using Entity Framework Core

#### 1. Install EF Core CLI tool
```bash
dotnet tool restore
```

#### 2. Create a local database user for smilodon
```postgresql
CREATE USER smilodon WITH PASSWORD 'smilodon' CREATEDB;
CREATE DATABASE smilodon;
```

#### 3. Initialize your local database
```bash
cd ./src/Infrastructure/Persistence
dotnet ef database update
```

#### Creating a migration
```bash
cd ./src/Infrastructure/Persistence
dotnet ef migrations add <NAME>
```

## Project Documentation

For information about the project, see the [Smilodon Documentation](https://devchatter.github.io/Smilodon)
Expand Down
9 changes: 8 additions & 1 deletion Smilodon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9EC4E573-0
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApp.Test", "test\WebApp.Test\WebApp.Test.csproj", "{972B3171-DDE1-4CF8-863E-B45875440A80}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure.Database", "src\Infrastructure.Database\Infrastructure.Database.csproj", "{5D89CB6E-02DA-483F-B0CA-03E235EA795B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{5D89CB6E-02DA-483F-B0CA-03E235EA795B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActivityPub.Domain", "src\ActivityPub.Domain\ActivityPub.Domain.csproj", "{5538990A-29DE-448B-A5F3-30266AA66C17}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{46FC91AA-B4F6-4339-A414-5126474048C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -37,6 +39,10 @@ Global
{5538990A-29DE-448B-A5F3-30266AA66C17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5538990A-29DE-448B-A5F3-30266AA66C17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5538990A-29DE-448B-A5F3-30266AA66C17}.Release|Any CPU.Build.0 = Release|Any CPU
{46FC91AA-B4F6-4339-A414-5126474048C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46FC91AA-B4F6-4339-A414-5126474048C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46FC91AA-B4F6-4339-A414-5126474048C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46FC91AA-B4F6-4339-A414-5126474048C6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -46,6 +52,7 @@ Global
{972B3171-DDE1-4CF8-863E-B45875440A80} = {9EC4E573-048F-40B7-8721-E28857532DF0}
{5D89CB6E-02DA-483F-B0CA-03E235EA795B} = {74FC9674-053B-480C-84AC-F6AAF8B82239}
{5538990A-29DE-448B-A5F3-30266AA66C17} = {74FC9674-053B-480C-84AC-F6AAF8B82239}
{46FC91AA-B4F6-4339-A414-5126474048C6} = {74FC9674-053B-480C-84AC-F6AAF8B82239}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B464DC23-8514-4B57-BA12-524A7C3994FA}
Expand Down
32 changes: 25 additions & 7 deletions src/ActivityPub.Domain/Accounts/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@ namespace ActivityPub.Domain.Accounts;

public class Account
{
public Account(string id, string username, string accountUri,
string url, string displayName, string note, string avatar,
string avatarStatic, string headerImage, string headerStatic,
bool isLocked, ProfileField[] fields, Emoji[] emojis, bool isBot,
bool isGroup, bool? isDiscoverable, Account hasMovedTo, bool? isSuspended,
bool isLimited, DateTime createdAt, DateTime? lastStatusAt,
int statusCount, int followerCount, int followingCount)
public Account(
string id,
string username,
string accountUri,
string url,
string displayName,
string note,
string avatar,
string avatarStatic,
string headerImage,
string headerStatic,
bool isLocked,
ProfileField[] fields,
Emoji[] emojis,
bool isBot,
bool isGroup,
bool? isDiscoverable,
Account hasMovedTo,
bool? isSuspended,
bool isLimited,
DateTime createdAt,
DateTime? lastStatusAt,
int statusCount,
int followerCount,
int followingCount)
{
Id = id;
Username = username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<RootNamespace>Smilodon.Domain</RootNamespace>
</PropertyGroup>

</Project>
117 changes: 117 additions & 0 deletions src/Domain/Models/Account.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
namespace Smilodon.Domain.Models
{
public class Account
{
public long Id { get; set; }
public string Username { get; set; } = null!;
public string? Domain { get; set; }
public string? PrivateKey { get; set; }
public string PublicKey { get; set; } = null!;
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public string Note { get; set; } = null!;
public string DisplayName { get; set; } = null!;
public string Uri { get; set; } = null!;
public string? Url { get; set; }
public string? AvatarFileName { get; set; }
public string? AvatarContentType { get; set; }
public int? AvatarFileSize { get; set; }
public DateTime? AvatarUpdatedAt { get; set; }
public string? HeaderFileName { get; set; }
public string? HeaderContentType { get; set; }
public int? HeaderFileSize { get; set; }
public DateTime? HeaderUpdatedAt { get; set; }
public string? AvatarRemoteUrl { get; set; }
public bool Locked { get; set; }
public string HeaderRemoteUrl { get; set; } = null!;
public DateTime? LastWebfingeredAt { get; set; }
public string InboxUrl { get; set; } = null!;
public string OutboxUrl { get; set; } = null!;
public string SharedInboxUrl { get; set; } = null!;
public string FollowersUrl { get; set; } = null!;
public int Protocol { get; set; }
public bool Memorial { get; set; }
public long? MovedToAccountId { get; set; }
public string? FeaturedCollectionUrl { get; set; }
public string? Fields { get; set; }
public string? ActorType { get; set; }
public bool? Discoverable { get; set; }
public string[]? AlsoKnownAs { get; set; }
public DateTime? SilencedAt { get; set; }
public DateTime? SuspendedAt { get; set; }
public bool? HideCollections { get; set; }
public int? AvatarStorageSchemaVersion { get; set; }
public int? HeaderStorageSchemaVersion { get; set; }
public string? DevicesUrl { get; set; }
public int? SuspensionOrigin { get; set; }
public DateTime? SensitizedAt { get; set; }
public bool? Trendable { get; set; }
public DateTime? ReviewedAt { get; set; }
public DateTime? RequestedReviewAt { get; set; }

public virtual Account? MovedToAccount { get; set; }
public virtual AccountStat AccountStat { get; set; } = null!;
public virtual FollowRecommendationSuppression FollowRecommendationSuppression { get; set; } = null!;
public virtual ICollection<AccountAlias> AccountAliases { get; set; } = new HashSet<AccountAlias>();
public virtual ICollection<AccountConversation> AccountConversations { get; set; } = new HashSet<AccountConversation>();
public virtual ICollection<AccountDeletionRequest> AccountDeletionRequests { get; set; } = new HashSet<AccountDeletionRequest>();
public virtual ICollection<AccountDomainBlock> AccountDomainBlocks { get; set; } = new HashSet<AccountDomainBlock>();
public virtual ICollection<AccountMigration> AccountMigrationAccounts { get; set; } = new HashSet<AccountMigration>();
public virtual ICollection<AccountMigration> AccountMigrationTargetAccounts { get; set; } = new HashSet<AccountMigration>();
public virtual ICollection<AccountModerationNote> AccountModerationNoteAccounts { get; set; } = new HashSet<AccountModerationNote>();
public virtual ICollection<AccountModerationNote> AccountModerationNoteTargetAccounts { get; set; } = new HashSet<AccountModerationNote>();
public virtual ICollection<AccountNote> AccountNoteAccounts { get; set; } = new HashSet<AccountNote>();
public virtual ICollection<AccountNote> AccountNoteTargetAccounts { get; set; } = new HashSet<AccountNote>();
public virtual ICollection<AccountPin> AccountPinAccounts { get; set; } = new HashSet<AccountPin>();
public virtual ICollection<AccountPin> AccountPinTargetAccounts { get; set; } = new HashSet<AccountPin>();
public virtual ICollection<AccountStatusesCleanupPolicy> AccountStatusesCleanupPolicies { get; set; } = new HashSet<AccountStatusesCleanupPolicy>();
public virtual ICollection<AccountWarning> AccountWarningAccounts { get; set; } = new HashSet<AccountWarning>();
public virtual ICollection<AccountWarning> AccountWarningTargetAccounts { get; set; } = new HashSet<AccountWarning>();
public virtual ICollection<AdminActionLog> AdminActionLogs { get; set; } = new HashSet<AdminActionLog>();
public virtual ICollection<AnnouncementMute> AnnouncementMutes { get; set; } = new HashSet<AnnouncementMute>();
public virtual ICollection<AnnouncementReaction> AnnouncementReactions { get; set; } = new HashSet<AnnouncementReaction>();
public virtual ICollection<Appeal> AppealAccounts { get; set; } = new HashSet<Appeal>();
public virtual ICollection<Appeal> AppealApprovedByAccounts { get; set; } = new HashSet<Appeal>();
public virtual ICollection<Appeal> AppealRejectedByAccounts { get; set; } = new HashSet<Appeal>();
public virtual ICollection<Block> BlockAccounts { get; set; } = new HashSet<Block>();
public virtual ICollection<Block> BlockTargetAccounts { get; set; } = new HashSet<Block>();
public virtual ICollection<Bookmark> Bookmarks { get; set; } = new HashSet<Bookmark>();
public virtual ICollection<CanonicalEmailBlock> CanonicalEmailBlocks { get; set; } = new HashSet<CanonicalEmailBlock>();
public virtual ICollection<ConversationMute> ConversationMutes { get; set; } = new HashSet<ConversationMute>();
public virtual ICollection<CustomFilter> CustomFilters { get; set; } = new HashSet<CustomFilter>();
public virtual ICollection<Device> Devices { get; set; } = new HashSet<Device>();
public virtual ICollection<EncryptedMessage> EncryptedMessages { get; set; } = new HashSet<EncryptedMessage>();
public virtual ICollection<Favourite> Favourites { get; set; } = new HashSet<Favourite>();
public virtual ICollection<FeaturedTag> FeaturedTags { get; set; } = new HashSet<FeaturedTag>();
public virtual ICollection<Follow> FollowAccounts { get; set; } = new HashSet<Follow>();
public virtual ICollection<FollowRequest> FollowRequestAccounts { get; set; } = new HashSet<FollowRequest>();
public virtual ICollection<FollowRequest> FollowRequestTargetAccounts { get; set; } = new HashSet<FollowRequest>();
public virtual ICollection<Follow> FollowTargetAccounts { get; set; } = new HashSet<Follow>();
public virtual ICollection<Import> Imports { get; set; } = new HashSet<Import>();
public virtual ICollection<Account> InverseMovedToAccount { get; set; } = new HashSet<Account>();
public virtual ICollection<ListAccount> ListAccounts { get; set; } = new HashSet<ListAccount>();
public virtual ICollection<List> Lists { get; set; } = new HashSet<List>();
public virtual ICollection<MediaAttachment> MediaAttachments { get; set; } = new HashSet<MediaAttachment>();
public virtual ICollection<Mention> Mentions { get; set; } = new HashSet<Mention>();
public virtual ICollection<Mute> MuteAccounts { get; set; } = new HashSet<Mute>();
public virtual ICollection<Mute> MuteTargetAccounts { get; set; } = new HashSet<Mute>();
public virtual ICollection<Notification> NotificationAccounts { get; set; } = new HashSet<Notification>();
public virtual ICollection<Notification> NotificationFromAccounts { get; set; } = new HashSet<Notification>();
public virtual ICollection<PollVote> PollVotes { get; set; } = new HashSet<PollVote>();
public virtual ICollection<Poll> Polls { get; set; } = new HashSet<Poll>();
public virtual ICollection<Report> ReportAccounts { get; set; } = new HashSet<Report>();
public virtual ICollection<Report> ReportActionTakenByAccounts { get; set; } = new HashSet<Report>();
public virtual ICollection<Report> ReportAssignedAccounts { get; set; } = new HashSet<Report>();
public virtual ICollection<ReportNote> ReportNotes { get; set; } = new HashSet<ReportNote>();
public virtual ICollection<Report> ReportTargetAccounts { get; set; } = new HashSet<Report>();
public virtual ICollection<ScheduledStatus> ScheduledStatuses { get; set; } = new HashSet<ScheduledStatus>();
public virtual ICollection<Status> StatusAccounts { get; set; } = new HashSet<Status>();
public virtual ICollection<StatusEdit> StatusEdits { get; set; } = new HashSet<StatusEdit>();
public virtual ICollection<Status> StatusInReplyToAccounts { get; set; } = new HashSet<Status>();
public virtual ICollection<StatusPin> StatusPins { get; set; } = new HashSet<StatusPin>();
public virtual ICollection<StatusTrend> StatusTrends { get; set; } = new HashSet<StatusTrend>();
public virtual ICollection<TagFollow> TagFollows { get; set; } = new HashSet<TagFollow>();
public virtual ICollection<Tombstone> Tombstones { get; set; } = new HashSet<Tombstone>();
public virtual ICollection<User> Users { get; set; } = new HashSet<User>();
}
}
14 changes: 14 additions & 0 deletions src/Domain/Models/AccountAlias.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Smilodon.Domain.Models
{
public class AccountAlias
{
public long Id { get; set; }
public long? AccountId { get; set; }
public string Acct { get; set; } = null!;
public string Uri { get; set; } = null!;
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

public virtual Account? Account { get; set; }
}
}
17 changes: 17 additions & 0 deletions src/Domain/Models/AccountConversation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Smilodon.Domain.Models
{
public class AccountConversation
{
public long Id { get; set; }
public long? AccountId { get; set; }
public long? ConversationId { get; set; }
public long[] ParticipantAccountIds { get; set; } = null!;
public long[] StatusIds { get; set; } = null!;
public long? LastStatusId { get; set; }
public int LockVersion { get; set; }
public bool Unread { get; set; }

public virtual Account? Account { get; set; }
public virtual Conversation? Conversation { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/Domain/Models/AccountDeletionRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Smilodon.Domain.Models
{
public class AccountDeletionRequest
{
public long Id { get; set; }
public long? AccountId { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

public virtual Account? Account { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/Domain/Models/AccountDomainBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Smilodon.Domain.Models
{
public class AccountDomainBlock
{
public long Id { get; set; }
public string? Domain { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public long? AccountId { get; set; }

public virtual Account? Account { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Domain/Models/AccountMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Smilodon.Domain.Models
{
public class AccountMigration
{
public long Id { get; set; }
public long? AccountId { get; set; }
public string Acct { get; set; } = null!;
public long FollowersCount { get; set; }
public long? TargetAccountId { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

public virtual Account? Account { get; set; }
public virtual Account? TargetAccount { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/Domain/Models/AccountModerationNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Smilodon.Domain.Models
{
public class AccountModerationNote
{
public long Id { get; set; }
public string Content { get; set; } = null!;
public long AccountId { get; set; }
public long TargetAccountId { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

public virtual Account Account { get; set; } = null!;
public virtual Account TargetAccount { get; set; } = null!;
}
}
15 changes: 15 additions & 0 deletions src/Domain/Models/AccountNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Smilodon.Domain.Models
{
public class AccountNote
{
public long Id { get; set; }
public long? AccountId { get; set; }
public long? TargetAccountId { get; set; }
public string Comment { get; set; } = null!;
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

public virtual Account? Account { get; set; }
public virtual Account? TargetAccount { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/Domain/Models/AccountPin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Smilodon.Domain.Models
{
public class AccountPin
{
public long Id { get; set; }
public long? AccountId { get; set; }
public long? TargetAccountId { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }

public virtual Account? Account { get; set; }
public virtual Account? TargetAccount { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Domain/Models/AccountStat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Smilodon.Domain.Models
{
public class AccountStat
{
public long Id { get; set; }
public long AccountId { get; set; }
public long StatusesCount { get; set; }
public long FollowingCount { get; set; }
public long FollowersCount { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public DateTime? LastStatusAt { get; set; }

public virtual Account Account { get; set; } = null!;
}
}
Loading

0 comments on commit f02ab0e

Please sign in to comment.