Skip to content

Commit

Permalink
new migration, logs added
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-baran committed Apr 28, 2022
1 parent 7f5ab47 commit df8c3ab
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 35 deletions.
9 changes: 9 additions & 0 deletions CloudDrive.Dictionaries/CloudDrive.Dictionaries.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions CloudDrive.Dictionaries/Enums/OperationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;

namespace CloudDrive.Dictionaries
{
public enum OperationType
{
[Display(Name = "Dodawanie")]
Add = 0,
[Display(Name = "Aktualizacja")]
Update = 1,
[Display(Name = "Usuwanie")]
Remove = 2
}
}
4 changes: 4 additions & 0 deletions CloudDrive.Domain/CloudDrive.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CloudDrive.Dictionaries\CloudDrive.Dictionaries.csproj" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions CloudDrive.Domain/Models/FileOperationsLogs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using CloudDrive.Dictionaries;

namespace CloudDrive.Domain
{
public class FileOperationsLogs
{
public Guid Id { get; set; }
public OperationType OperationType { get; set; }
public DateTime Date { get; set; }
public Guid UserFileId { get; set; }
public virtual UserFile UserFile { get; set; }
}
}
3 changes: 3 additions & 0 deletions CloudDrive.Domain/Models/UserFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public class UserFile
public string Name { get; set; }
public long Size { get; set; }
public long FileVersion { get; set; }
public string RelativePath { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime UpdatedDate { get; set; }
public virtual ICollection<FileOperationsLogs> FileOperationsLogs { get; set; }
}
}
2 changes: 2 additions & 0 deletions CloudDrive.EntityFramework/Contexts/MainDatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public MainDatabaseContext(DbContextOptions options) : base(options)
// dotnet ef database update

public DbSet<UserFile> Files { get; set; }
public DbSet<FileOperationsLogs> FileOperationsLogs { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<UserFile>().HasKey(x => x.Id);
modelBuilder.Entity<FileOperationsLogs>().HasKey(x => x.Id);
}
}
}

This file was deleted.

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
@@ -0,0 +1,64 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CloudDrive.EntityFramework.Migrations.MainDatabaseMigrations
{
public partial class Init : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Files",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Size = table.Column<long>(type: "bigint", nullable: false),
FileVersion = table.Column<long>(type: "bigint", nullable: false),
RelativePath = table.Column<string>(type: "nvarchar(max)", nullable: false),
CreatedDate = table.Column<DateTime>(type: "datetime2", nullable: false),
UpdatedDate = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Files", x => x.Id);
});

migrationBuilder.CreateTable(
name: "FileOperationsLogs",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
OperationType = table.Column<int>(type: "int", nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
UserFileId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FileOperationsLogs", x => x.Id);
table.ForeignKey(
name: "FK_FileOperationsLogs_Files_UserFileId",
column: x => x.UserFileId,
principalTable: "Files",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_FileOperationsLogs_UserFileId",
table: "FileOperationsLogs",
column: "UserFileId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "FileOperationsLogs");

migrationBuilder.DropTable(
name: "Files");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ protected override void BuildModel(ModelBuilder modelBuilder)

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);

modelBuilder.Entity("CloudDrive.Domain.FileOperationsLogs", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");

b.Property<DateTime>("Date")
.HasColumnType("datetime2");

b.Property<int>("OperationType")
.HasColumnType("int");

b.Property<Guid>("UserFileId")
.HasColumnType("uniqueidentifier");

b.HasKey("Id");

b.HasIndex("UserFileId");

b.ToTable("FileOperationsLogs");
});

modelBuilder.Entity("CloudDrive.Domain.UserFile", b =>
{
b.Property<Guid>("Id")
Expand All @@ -38,13 +60,36 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("RelativePath")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<long>("Size")
.HasColumnType("bigint");

b.Property<DateTime>("UpdatedDate")
.HasColumnType("datetime2");

b.HasKey("Id");

b.ToTable("Files");
});

modelBuilder.Entity("CloudDrive.Domain.FileOperationsLogs", b =>
{
b.HasOne("CloudDrive.Domain.UserFile", "UserFile")
.WithMany("FileOperationsLogs")
.HasForeignKey("UserFileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("UserFile");
});

modelBuilder.Entity("CloudDrive.Domain.UserFile", b =>
{
b.Navigation("FileOperationsLogs");
});
#pragma warning restore 612, 618
}
}
Expand Down
7 changes: 7 additions & 0 deletions CloudDrive.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudDrive.Application.Serv
EndProject
Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "CloudDrive.Vue", "CloudDrive.Vue\CloudDrive.Vue.esproj", "{546BB76B-9B2D-4D27-BC58-5103E4FED781}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudDrive.Dictionaries", "CloudDrive.Dictionaries\CloudDrive.Dictionaries.csproj", "{5DA61A8C-16BC-4608-B00D-6B064D351342}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -75,6 +77,10 @@ Global
{546BB76B-9B2D-4D27-BC58-5103E4FED781}.Release|Any CPU.ActiveCfg = Release|Any CPU
{546BB76B-9B2D-4D27-BC58-5103E4FED781}.Release|Any CPU.Build.0 = Release|Any CPU
{546BB76B-9B2D-4D27-BC58-5103E4FED781}.Release|Any CPU.Deploy.0 = Release|Any CPU
{5DA61A8C-16BC-4608-B00D-6B064D351342}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DA61A8C-16BC-4608-B00D-6B064D351342}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DA61A8C-16BC-4608-B00D-6B064D351342}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DA61A8C-16BC-4608-B00D-6B064D351342}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -89,6 +95,7 @@ Global
{7DDC6C76-2605-41D7-82BD-A4C101388693} = {26BFFE0C-3173-435E-A521-661B5E1E65C9}
{7F562B80-9452-42F8-AD22-DD589BD9E868} = {26BFFE0C-3173-435E-A521-661B5E1E65C9}
{546BB76B-9B2D-4D27-BC58-5103E4FED781} = {9A76DF35-1027-489E-8894-825D3FBFB7F4}
{5DA61A8C-16BC-4608-B00D-6B064D351342} = {B3CC7786-15BD-46A1-AF58-7902088C6862}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {64EA95DE-F32A-47F3-97BF-13ACE0D34C95}
Expand Down

0 comments on commit df8c3ab

Please sign in to comment.