﻿ALTER TABLE `Users` ADD `GroupId` int NULL;

ALTER TABLE `Users` ADD `GroupRank` int NOT NULL DEFAULT 0;

ALTER TABLE `ServerVehicles` ADD `GroupId` int NULL;

CREATE TABLE `Groups` (
    `Id` int NOT NULL AUTO_INCREMENT,
    `Name` longtext NULL,
    CONSTRAINT `PK_Groups` PRIMARY KEY (`Id`)
);

CREATE TABLE `GroupBankAccounts` (
    `Id` int NOT NULL AUTO_INCREMENT,
    `GroupId` int NULL,
    `Balance` int NOT NULL,
    CONSTRAINT `PK_GroupBankAccounts` PRIMARY KEY (`Id`),
    CONSTRAINT `FK_GroupBankAccounts_Groups_GroupId` FOREIGN KEY (`GroupId`) REFERENCES `Groups` (`Id`) ON DELETE RESTRICT
);

CREATE INDEX `IX_Users_GroupId` ON `Users` (`GroupId`);

CREATE INDEX `IX_ServerVehicles_GroupId` ON `ServerVehicles` (`GroupId`);

CREATE INDEX `IX_GroupBankAccounts_GroupId` ON `GroupBankAccounts` (`GroupId`);

ALTER TABLE `ServerVehicles` ADD CONSTRAINT `FK_ServerVehicles_Groups_GroupId` FOREIGN KEY (`GroupId`) REFERENCES `Groups` (`Id`) ON DELETE RESTRICT;

ALTER TABLE `Users` ADD CONSTRAINT `FK_Users_Groups_GroupId` FOREIGN KEY (`GroupId`) REFERENCES `Groups` (`Id`) ON DELETE RESTRICT;

INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('20190505154643_Groups', '2.2.0-rtm-35687');

