-- 1.0.50 Power.TechnologicalConnection

-- Дополнительная информация, сделанная для актов разграничения не прошедших технологическое присоединение.
create table DelineationsExtraInfo
(
	DelineationID			int,	
	TCSpecNumber			nvarchar(50),
	TCSpecDate				datetime,
	PmaxSource				int not null,
	Pmax					float,
	Unom					float,
	PowerSource				nvarchar(1024),
	MainPowerSource			nvarchar(200),
	ReservePowerSource		nvarchar(200),
	InspectionEPUActNumber	nvarchar(50),
	InspectionEPUDate		datetime,
	Primary Key(DelineationID)
)
GO
insert into DelineationsExtraInfo(DelineationID, TCSpecNumber, Pmax, PmaxSource)
select DelineationID, SpecNumber, Pmax, 1 from Delineations where SpecNumber is not null or Pmax is not null
GO
ALTER TABLE DelineationsExtraInfo
	ADD FOREIGN KEY (DelineationID)
	REFERENCES Delineations (DelineationID)
	ON DELETE CASCADE
        ON UPDATE CASCADE
GO
alter table Delineations drop column Pmax
alter table Delineations drop column PmaxFromSpec
alter table Delineations drop column PmaxFromContract
alter table Delineations drop column PmaxFromNet
alter table Delineations add IsUseExtraInfo bit 
GO
-- Поля для заявки на подключение
alter table ConnectionApplications add ReadyForConnectionAppL datetime
alter table ConnectionApplications add ReadyForConnectionAppG datetime
alter table ConnectionApplications add ReadyForConnectionOrgL datetime
alter table ConnectionApplications add ReadyForConnectionOrgG datetime
