-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from romfabbro/transect
Transect
- Loading branch information
Showing
9 changed files
with
615 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
|
||
INSERT INTO ProtocoleType | ||
Values ('SubTransect',6,NULL) | ||
|
||
INSERT INTO ObservationDynProp | ||
VALUES ('nb_contact','Integer') | ||
|
||
DECLARE @type int SET @type = (SELECT ID FROM ProtocoleType WHERE Name = 'SubTransect') | ||
DECLARE @contact int SET @contact = (SELECT ID FROM ObservationDynProp WHERE Name = 'nb_contact') | ||
|
||
INSERT INTO ProtocoleType_ObservationDynProp (Required,FK_ProtocoleType,FK_ObservationDynProp) | ||
VALUES | ||
(1,@type,@contact), | ||
(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'taxon')), | ||
(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'validator')), | ||
(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'sampled')), | ||
(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'picture')), | ||
(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'cultivated')) | ||
|
||
|
||
|
||
INSERT INTO ModuleForms ( | ||
[module_id] | ||
,[TypeObj] | ||
,[Name] | ||
,[Label] | ||
,[Required] | ||
,[FieldSizeEdit] | ||
,[FieldSizeDisplay] | ||
,[InputType] | ||
,[editorClass] | ||
,[FormRender] | ||
,[FormOrder] | ||
,[Legend] | ||
,[Options] | ||
,[Validators] | ||
,[displayClass] | ||
,[EditClass] | ||
,[Status] | ||
,[Locked] | ||
,[DefaultValue] ) | ||
VALUES | ||
(1,@type,'taxon','Taxon',1,6,6,'AutocompTreeEditor','form-control',2,10,NULL,'204089',NULL,'fixedCol','fixedCol',1,NULL,NULL), | ||
(1,@type,'autoRanged','',0,3,3,'GridRanged','form-control',2,200,NULL,'{"range":200,"prefixLabel":"P","inputType":"Number"}',NULL,NULL,NULL,1,NULL,NULL), | ||
(1,@type,'FK_ProtocoleType','FK_ProtocoleType',0,3,3,'Number','form-control',0,3000,NULL,NULL,NULL,'hide','hide',1,NULL,231), | ||
|
||
|
||
(1,@type,'validator','Validator',0,6,6,'Select','form-control',2,1020,NULL,'SELECT ID as val, Login as label From [User] Union all select -1 as val, '' '' as label' ,NULL,NULL,NULL,1,1,NULL), | ||
(1,@type,'sampled','Sampled',0,4,4,'Checkbox','form-control',2,1025,NULL,NULL,NULL,'','',1,1,NULL), | ||
(1,@type,'picture','Picture',0,3,3,'Checkbox','form-control',2,1031,NULL,'',NULL,'','',1,NULL,NULL), | ||
|
||
(1,@type,'cultivated','Cultivated',0,4,4,'Checkbox','form-control',2,1035,NULL,'',NULL,'','',1,1,NULL), | ||
(1,@type,'nb_contact','nb contact',0,4,4,'Number','form-control',2,1040,NULL,'',NULL,'','',1,1,NULL), | ||
|
||
(1,@type,'Comments','Comments',0,6,6,'TextArea','form-control',2,2000,NULL,NULL,NULL,'','',1,1,NULL) | ||
|
||
|
||
GO | ||
|
||
INSERT INTO ModuleForms ( | ||
[module_id] | ||
,[TypeObj] | ||
,[Name] | ||
,[Label] | ||
,[Required] | ||
,[FieldSizeEdit] | ||
,[FieldSizeDisplay] | ||
,[InputType] | ||
,[editorClass] | ||
,[FormRender] | ||
,[FormOrder] | ||
,[Legend] | ||
,[Options] | ||
,[Validators] | ||
,[displayClass] | ||
,[EditClass] | ||
,[Status] | ||
,[Locked] | ||
,[DefaultValue] ) | ||
VALUES | ||
(1,220,'SubTransect','',0,3,3,'GridFormEditor','form-control',2,200,NULL,231,NULL,NULL,NULL,1,NULL,NULL) | ||
|
||
GO | ||
|
||
INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('64_Create_TransectForm',GETDATE(),(SELECT db_name())) | ||
|
||
|
||
GO |
123 changes: 123 additions & 0 deletions
123
Back/database/Pipe/DB_Mother/065_Migration_SubTransect.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
|
||
|
||
declare @proto int SET @proto = (SELECT ID FROM ProtocoleType WHERE Name = 'SubTransect') | ||
|
||
|
||
INSERT INTO Observation | ||
(creationDate,FK_ProtocoleType,Comments,original_id,Parent_Observation) | ||
SELECT o.creationDate,@proto,sub.Comments,sub.PK,o.ID | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.FK_ProtocoleType = 220 and o.original_id = sub.Fk_Trans | ||
|
||
|
||
declare @proto int SET @proto = (SELECT ID FROM ProtocoleType WHERE Name = 'SubTransect') | ||
INSERT INTO ObservationDynPropValue | ||
(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) | ||
SELECT o.creationDate,Cultivated,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'cultivated') | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto | ||
|
||
|
||
INSERT INTO ObservationDynPropValue | ||
(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) | ||
SELECT o.creationDate,identity_sure,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'identity_sure') | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto | ||
|
||
INSERT INTO ObservationDynPropValue | ||
(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) | ||
SELECT o.creationDate,picture,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'picture') | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto | ||
|
||
|
||
INSERT INTO ObservationDynPropValue | ||
(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) | ||
SELECT o.creationDate,sampled,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'sampled') | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto | ||
|
||
|
||
INSERT INTO ObservationDynPropValue | ||
(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) | ||
SELECT o.creationDate,nb_contact,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'nb_contact') | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto | ||
|
||
INSERT INTO ObservationDynPropValue | ||
(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) | ||
SELECT o.creationDate,NULL,Name_Taxon,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'taxon') | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto | ||
|
||
|
||
INSERT INTO ObservationDynPropValue | ||
(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) | ||
SELECT o.creationDate,NULL,validator,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'validator') | ||
FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub | ||
JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto | ||
|
||
|
||
---------------------------- INSERT transect occurence value ------------------------ | ||
USE [ECWP-eReleveData] | ||
|
||
BEGIN | ||
IF OBJECT_ID('tempdb..#tempSubTransValue') IS NOT NULL | ||
DROP TABLE #tempSubTransValue | ||
|
||
|
||
CREATE Table #tempSubTransValue (col varchar(10),value decimal, original_ID int ) | ||
|
||
DECLARE @ListCol VARCHAR(MAX) = STUFF((SELECT DISTINCT ',' + name --replace(replace(QUOTENAME(name),'[',''),']','') | ||
FROM sys.columns | ||
WHERE objecT_id = OBJECT_ID('TSubProtocol_Transect') | ||
AND name like 'P%' and name not in ('Picture','PK') | ||
FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)') | ||
,1,1,'') | ||
,@sql VARCHAR(MAX) | ||
|
||
|
||
print(@ListCol) | ||
|
||
SET @sql = 'INSERT INTO #tempSubTransValue | ||
SELECT col,value,pk | ||
FROM (SELECT * FROM TSubProtocol_Transect) p | ||
UNPIVOT (value FOR col IN ('+@ListCol+')) as unpvt | ||
where value != 0 | ||
' | ||
print(@sql) | ||
EXEC (@sql) | ||
|
||
|
||
UPDATE #tempSubTransValue SET col = 'C'+CAST( CONVERT(INT,replace(col,'P',''))-1 AS VARCHAR(10)) | ||
|
||
USE EcoReleve_ECWP | ||
INSERT INTO ObservationDynPropSubValue (FieldName,ValueNumeric,FK_Observation) | ||
select col,value,o.ID | ||
FROM #tempSubTransValue v | ||
JOIN Observation o ON o.original_id = v.original_ID | ||
|
||
Update v set ValueString = CASE WHEN th.TTop_FullPath IS NOT NULL THEN th.TTop_FullPath ELSE ValueString END | ||
FROM ObserVationDynPropValue v | ||
LEFT JOIN THESAURUS.dbo.TTopic th on v.ValueString = th.TTop_Name | ||
WHERE EXISTS ( | ||
SELECT * FROM Observation o | ||
WHERE v.FK_Observation = o.ID and o.FK_ProtocoleType = (SELECT ID FROM ProtocoleType WHERE NAme = 'SubTransect') | ||
) | ||
AND | ||
FK_ObservationDynProp = (SELECT ID FROM ObservationDynProp WHERE NAme = 'taxon') | ||
|
||
|
||
|
||
END | ||
GO | ||
|
||
UPDATE ModuleForms SET Options = 204083 | ||
WHERE TypeObj = 231 and name = 'taxon' | ||
|
||
GO | ||
|
||
INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('65_Migration_SubTransect',GETDATE(),(SELECT db_name())) | ||
|
||
|
||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.