-- 1.1.1 Power.TechnologicalConnection

-- Дата заявки на подключение.
alter table ConnectionApplications add ApplicationDate datetime
GO
-- Скан акта осуществления техприсоединения
ALTER TABLE TCApplications add TCImplementAttachID int
GO
ALTER TABLE TCApplications
	ADD FOREIGN KEY (TCImplementAttachID)
	REFERENCES StoreDocuments(DocumentID)	 
GO
INSERT INTO StoreDocumentTypes(StoreDocumentTypeID, Description) Values(7, 'TCImplementAttach')
GO
-- Добавляем флаг потери согласно договору
alter table Delineations add IsLossesFromContract bit
--Добавляем список документов-приложений объекта электроснабжения.
CREATE TABLE ConsumingObjectDocuments
(
	ConsumingObjectID int not null,
	StoreDocumentID int not null,
	DocumentTypeID	int not null,	
	PRIMARY KEY (ConsumingObjectID, StoreDocumentID)
)
GO
CREATE TABLE ConsumingObjectDocumentTypes
(
	DocumentTypeID	int IDENTITY(1,1),
	Description		nvarchar(100),
	PRIMARY KEY (DocumentTypeID)
)
GO
ALTER TABLE ConsumingObjectDocuments
	ADD FOREIGN KEY (ConsumingObjectID) 
	REFERENCES ConsumingObjects (ID)
	ON DELETE CASCADE
	
ALTER TABLE ConsumingObjectDocuments
	ADD FOREIGN KEY (StoreDocumentID) 
	REFERENCES StoreDocuments (DocumentID)
	ON DELETE CASCADE

ALTER TABLE ConsumingObjectDocuments
	ADD FOREIGN KEY (DocumentTypeID)
	REFERENCES ConsumingObjectDocumentTypes (DocumentTypeID)