-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added scripts for creating tables with logs #797
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,7 @@ public Course() | |
public virtual ICollection<MentorOfCourse> MentorsOfCourses { get; set; } | ||
|
||
public virtual ICollection<StudentGroup> StudentGroup { get; set; } | ||
|
||
public long UpdatedByAccountId { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please set property where needed. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,11 @@ public void Configure(EntityTypeBuilder<Course> entity) | |
{ | ||
entity.ToTable("Courses"); | ||
|
||
entity.Property(e => e.UpdatedByAccountId) | ||
.IsRequired() | ||
.HasColumnName("UpdatedByAccountId") | ||
.HasDefaultValueSql("1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove |
||
|
||
entity.Property(e => e.Id) | ||
.IsRequired() | ||
.HasColumnName("ID"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public static void AddServices(this IServiceCollection services, IConfiguration | |
|
||
services.AddHttpClient<IHttpUtil, HttpUtil>(client => | ||
{ | ||
client.BaseAddress = new Uri(configuration.GetSection("Urls:Api:Https").Value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please revert |
||
client.BaseAddress = new Uri(configuration.GetSection("Urls:Api:Http").Value); | ||
}) | ||
.SetHandlerLifetime(Timeout.InfiniteTimeSpan); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
USE `Soft`; | ||
|
||
LOCK TABLES `Accounts` WRITE; | ||
|
||
ALTER TABLE `Accounts` | ||
ADD `UpdatedByAccountId` BIGINT UNSIGNED NOT NULL DEFAULT 1; | ||
|
||
UNLOCK TABLES; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
USE `Soft`; | ||
|
||
DROP TABLE IF EXISTS `AccountsChanges`; | ||
|
||
CREATE TABLE `AccountsChanges` ( | ||
`ID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`AccountID` BIGINT UNSIGNED NOT NULL, | ||
`OldRole` TINYINT UNSIGNED DEFAULT NULL, | ||
`NewRole` TINYINT UNSIGNED DEFAULT NULL, | ||
`OldFirstName` VARCHAR(30) DEFAULT NULL, | ||
`NewFirstName` VARCHAR(30) DEFAULT NULL, | ||
`OldLastName` VARCHAR(30) DEFAULT NULL, | ||
`NewLastName` VARCHAR(30) DEFAULT NULL, | ||
`OldEmail` VARCHAR(50) DEFAULT NULL, | ||
`NewEmail` VARCHAR(50) DEFAULT NULL, | ||
`OldPasswordHash` VARCHAR(64) DEFAULT NULL, | ||
`NewPasswordHash` VARCHAR(64) DEFAULT NULL, | ||
`OldSalt` VARCHAR(32) DEFAULT NULL, | ||
`NewSalt` VARCHAR(32) DEFAULT NULL, | ||
`OldIsActive` BIT DEFAULT NULL, | ||
`NewIsActive` BIT DEFAULT NULL, | ||
`OldForgotPasswordToken` VARCHAR(36) DEFAULT NULL, | ||
`NewForgotPasswordToken` VARCHAR(36) DEFAULT NULL, | ||
`OldForgotTokenGenDate` DATETIME DEFAULT NULL, | ||
`NewForgotTokenGenDate` DATETIME DEFAULT NULL, | ||
`OldAvatarID` BIGINT UNSIGNED DEFAULT NULL, | ||
`NewAvatarID` BIGINT UNSIGNED DEFAULT NULL, | ||
`QueriedBy` BIGINT UNSIGNED NOT NULL, | ||
`DateTime` DATETIME DEFAULT NOW(), | ||
|
||
CONSTRAINT `PK_AccountsChanges` PRIMARY KEY (`ID`) | ||
); | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterAccountsInsert` | ||
AFTER INSERT | ||
ON `Accounts` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `AccountsChanges` | ||
(`AccountID`, `NewRole`, `NewFirstName`, `NewLastName`, `NewEmail`, `NewPasswordHash`, `NewSalt`, `NewIsActive`, `NewForgotPasswordToken`, `NewForgotTokenGenDate`, `NewAvatarID`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, NEW.`Role`, NEW.`FirstName`, NEW.`LastName`, NEW.`Email`, NEW.`PasswordHash`, NEW.`Salt`, NEW.`IsActive`, NEW.`ForgotPasswordToken`, NEW.`ForgotTokenGenDate`, NEW.`AvatarID`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterAccountsUpdate` | ||
AFTER UPDATE | ||
ON `Accounts` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `AccountsChanges` | ||
(`AccountID`, `OldRole`, `NewRole`, `OldFirstName`, `NewFirstName`, `OldLastName`, `NewLastName`, `OldEmail`, `NewEmail`, `OldPasswordHash`, `NewPasswordHash`, `OldSalt`, `NewSalt`, `OldIsActive`, `NewIsActive`, `OldForgotPasswordToken`, `NewForgotPasswordToken`, | ||
`OldForgotTokenGenDate`, `NewForgotTokenGenDate`, `OldAvatarID`, `NewAvatarID`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, OLD.`Role`, NEW.`Role`, OLD.`FirstName`, NEW.`FirstName`, OLD.`LastName`, NEW.`LastName`, OLD.`Email`, NEW.`Email`, OLD.`PasswordHash`, NEW.`PasswordHash`, OLD.`Salt`, NEW.`Salt`, OLD.`IsActive`, NEW.`IsActive`, OLD.`ForgotPasswordToken`, NEW.`ForgotPasswordToken`, | ||
OLD.`ForgotTokenGenDate`, NEW.`ForgotTokenGenDate`, OLD.`AvatarID`, NEW.`AvatarID`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
USE Soft; | ||
|
||
LOCK TABLES Courses WRITE; | ||
|
||
ALTER TABLE Courses | ||
|
||
ADD UpdatedByAccountId BIGINT UNSIGNED NOT NULL DEFAULT 1; | ||
|
||
UNLOCK TABLES; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
USE `Soft`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please do dev testing |
||
|
||
DROP TABLE IF EXISTS `CoursesChanges`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please rename courses -> course |
||
|
||
CREATE TABLE `CoursesChanges` ( | ||
`ID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`CourseID` BIGINT UNSIGNED NOT NULL, | ||
`OldName` TINYINT UNSIGNED DEFAULT NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please set appropriate types |
||
`NewName` TINYINT UNSIGNED DEFAULT NULL, | ||
`OldIsActive` BIT DEFAULT NULL, | ||
`NewIsActive` BIT DEFAULT NULL, | ||
`QueriedBy` BIGINT UNSIGNED NOT NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please rename to updated by account id |
||
`DateTime` DATETIME DEFAULT NOW(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update date |
||
|
||
CONSTRAINT `PK_CoursesChanges` PRIMARY KEY (`ID`) | ||
); | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterCoursesInsert` | ||
AFTER INSERT | ||
ON `Courses` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `CoursesChanges` | ||
(`CourseID`, `NewName`, `NewIsActive`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, NEW.`Name`, NEW.`IsActive`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterCoursesUpdate` | ||
AFTER UPDATE | ||
ON `Courses` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `CoursesChanges` | ||
(`CourseID`, `OldName`, `NewName`,`OldIsActive`, `NewIsActive`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, OLD.`Name`, NEW.`Name`, OLD.`IsActive`, NEW.`IsActive`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
USE Soft; | ||
|
||
LOCK TABLES Homeworks WRITE; | ||
|
||
ALTER TABLE Homeworks | ||
|
||
ADD UpdatedByAccountId BIGINT UNSIGNED NOT NULL DEFAULT 1; | ||
|
||
UNLOCK TABLES; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
USE `Soft`; | ||
|
||
DROP TABLE IF EXISTS `HomeworksChanges`; | ||
|
||
CREATE TABLE `HomeworksChanges` ( | ||
`ID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`HomeworkID` BIGINT UNSIGNED NOT NULL, | ||
`OldDueDate` DATETIME NOT NULL COMMENT 'Use UTC time', | ||
`NewDueDate` DATETIME NOT NULL COMMENT 'Use UTC time', | ||
`OldTaskText` VARCHAR(8000) NOT NULL, | ||
`NewTaskText` VARCHAR(8000) NOT NULL, | ||
`QueriedBy` BIGINT UNSIGNED NOT NULL, | ||
`DateTime` DATETIME DEFAULT NOW(), | ||
|
||
CONSTRAINT `PK_HomeworksChanges` PRIMARY KEY (`ID`) | ||
); | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterHomeworksInsert` | ||
AFTER INSERT | ||
ON `Homeworks` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `HomeworksChanges` | ||
(`HomeworkID`, `NewDueDate`, `NewTaskText`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, NEW.`DueDate`, NEW.`TaskText`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterHomeworksUpdate` | ||
AFTER UPDATE | ||
ON `Homeworks` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `HomeworksChanges` | ||
(`HomeworkID`, `OldDueDate`, `NewDueDate`,`OldTaskText`, `NewTaskText`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, OLD.`DueDate`, NEW.`DueDate`, OLD.`TaskText`, NEW.`TaskText`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
USE Soft; | ||
|
||
LOCK TABLES Studentgroups WRITE; | ||
|
||
ALTER TABLE Studentgroups | ||
|
||
ADD UpdatedByAccountId BIGINT UNSIGNED NOT NULL DEFAULT 1; | ||
|
||
UNLOCK TABLES; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
USE `Soft`; | ||
|
||
DROP TABLE IF EXISTS `StudentGroupsChanges`; | ||
|
||
CREATE TABLE `StudentGroupsChanges` ( | ||
`ID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, | ||
`StudentGroupID` BIGINT UNSIGNED NOT NULL, | ||
`OldName` VARCHAR(100) NOT NULL, | ||
`NewName` VARCHAR(100) NOT NULL, | ||
`OldStartDate` DATE NOT NULL, | ||
`NewStartDate` DATE NOT NULL, | ||
`OldFinishDate` DATE NOT NULL, | ||
`NewFinishDate` DATE NOT NULL, | ||
`OldIsActive` BIT DEFAULT NULL, | ||
`NewIsActive` BIT DEFAULT NULL, | ||
`QueriedBy` BIGINT UNSIGNED NOT NULL, | ||
`DateTime` DATETIME DEFAULT NOW(), | ||
CONSTRAINT `PK_StudentGroupsChanges` PRIMARY KEY (`ID`) | ||
); | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterStudentGroupsInsert` | ||
AFTER INSERT | ||
ON `studentgroups` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `StudentGroupsChanges` | ||
(`StudentGroupID`,`NewName`,`NewStartDate`,`NewFinishDate`, `NewIsActive`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, NEW.`Name`, NEW.`StartDate`, NEW.`FinishDate`, NEW.`IsActive`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; | ||
|
||
DELIMITER $$ | ||
|
||
CREATE TRIGGER `AfterStudentGroupsUpdate` | ||
AFTER UPDATE | ||
ON `studentgroups` FOR EACH ROW | ||
BEGIN | ||
INSERT INTO `StudentGroupsChanges` | ||
(`StudentGroupID`, `OldName`, `NewName`, `OldStartDate`, `NewStartDate`,`OldFinishDate`,`NewFinishDate`,`OldIsActive`, `NewIsActive`, `QueriedBy`) | ||
VALUES | ||
(NEW.`ID`, OLD.`Name`, NEW.`Name`, OLD.`StartDate`, NEW.`StartDate`,OLD.`FinishDate`,NEW.`FinishDate`, OLD.`IsActive`, NEW.`IsActive`, NEW.`UpdatedByAccountId`) | ||
; | ||
END$$ | ||
|
||
DELIMITER ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please find more places where account is modified.