sql update script 1.0.0
This commit is contained in:
parent
c5f9f73410
commit
efc540467f
3 changed files with 314 additions and 2 deletions
63
SQLUpdates/SQLUpdates.sqlproj
Normal file
63
SQLUpdates/SQLUpdates.sqlproj
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<Name>SQLUpdates</Name>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>4.1</ProjectVersion>
|
||||
<ProjectGuid>{331288f7-0a1c-4795-bd75-5ffd5c31b2da}</ProjectGuid>
|
||||
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql170DatabaseSchemaProvider</DSP>
|
||||
<OutputType>Database</OutputType>
|
||||
<RootPath>
|
||||
</RootPath>
|
||||
<RootNamespace>SQLUpdates</RootNamespace>
|
||||
<AssemblyName>SQLUpdates</AssemblyName>
|
||||
<ModelCollation>1033, CI</ModelCollation>
|
||||
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
|
||||
<DeployToDatabase>True</DeployToDatabase>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetLanguage>CS</TargetLanguage>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<SqlServerVerification>False</SqlServerVerification>
|
||||
<IncludeCompositeObjects>True</IncludeCompositeObjects>
|
||||
<TargetDatabaseSet>True</TargetDatabaseSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
|
||||
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
|
||||
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
|
||||
<Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Update-1-0-0.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
238
SQLUpdates/Update-1-0-0.sql
Normal file
238
SQLUpdates/Update-1-0-0.sql
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
IF OBJECT_ID('dbo.SchemaVersion', 'U') IS NULL
|
||||
BEGIN
|
||||
CREATE TABLE dbo.SchemaVersion (
|
||||
VersionNumber VARCHAR(20) NOT NULL PRIMARY KEY,
|
||||
AppliedOn DATETIME2 NOT NULL DEFAULT GETDATE(),
|
||||
AppliedBy VARCHAR(100) NOT NULL DEFAULT SUSER_SNAME(),
|
||||
ScriptDescription VARCHAR(255) NULL
|
||||
);
|
||||
PRINT 'Table dbo.SchemaVersion created successfully.';
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
PRINT 'Table dbo.SchemaVersion already exists.';
|
||||
END
|
||||
GO
|
||||
|
||||
|
||||
--SCRIPT template
|
||||
SET NOCOUNT ON;
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
DECLARE @CurrentVersion VARCHAR(20) = '1.0.0'; -- Set your script's target version
|
||||
|
||||
-- Check if this update has already been applied
|
||||
IF EXISTS (SELECT 1 FROM dbo.SchemaVersion WHERE VersionNumber = @CurrentVersion)
|
||||
BEGIN
|
||||
PRINT 'Version ' + @CurrentVersion + ' has already been applied. Skipping script.';
|
||||
ROLLBACK TRANSACTION;
|
||||
RETURN;
|
||||
END
|
||||
|
||||
BEGIN TRY
|
||||
-- =========================================================
|
||||
-- MIGRATION SQL
|
||||
-- =========================================================
|
||||
|
||||
EXEC sp_executesql N'
|
||||
ALTER PROCEDURE [dbo].[RegistrySelect]
|
||||
AS
|
||||
SELECT [r].[RegistryID],
|
||||
[r].[IdentificatieToestel],
|
||||
[ParentID] = NULL,
|
||||
[r].[TypeAanduiding],
|
||||
[TypeAanduidingNaam] = [tl].[ToestelModelNaam],
|
||||
[r].[SerieNummer],
|
||||
[Eigenaar] = ISNULL([r].[Eigenaar], ''HPH''),
|
||||
[CCWBS_ID] = ISNULL([r].[CCWBS_ID], 1),
|
||||
[cw].[WBSCC_nr],
|
||||
[r].[NaamFabrikant],
|
||||
[r].[NaamLeverancier],
|
||||
[r].[DatumInGebruik], --= Today (Default + aanpassing mogelijk)
|
||||
[r].[DatumUitGebruik],
|
||||
[r].[Lokaal_ID],
|
||||
[lk].[LokaalNaam], --– SELECT [dbo_Lokaal].[Lokaal_ID], [dbo_Lokaal].[LokaalNaam] FROM dbo_Lokaal ORDER BY [LokaalNaam];
|
||||
[r].[id_statuslijst],
|
||||
[sl].[RegisterStatus],
|
||||
[r].[DefinitieNummerKal],
|
||||
[r].[KalibratieFrequentie],
|
||||
[r].[KalibratieFrequentieUnit],
|
||||
[KalibratieFrequentieUnitName] = [fe].[description],
|
||||
[r].[KalibratieVerantw],
|
||||
[KalibratieVerantwAfkorting] = [kv].[Afkorting], [r].[Assetnr]
|
||||
FROM [dbo].[Register] [r]
|
||||
LEFT JOIN [dbo].[Toestelmodel] AS [tl]
|
||||
ON [tl].[TypeAanduiding] = [r].[TypeAanduiding]
|
||||
LEFT JOIN [dbo].[Lokaal] AS [lk]
|
||||
ON [lk].[Lokaal_ID] = [r].[Lokaal_ID]
|
||||
LEFT JOIN [dbo].[Statuslijst] [sl]
|
||||
ON [sl].[ID_statuslijst] = [r].[id_statuslijst]
|
||||
LEFT JOIN [dbo].[frequentieEenheid] [fe]
|
||||
ON [fe].[FrequentieEenheid] = [r].[KalibratieFrequentieUnit]
|
||||
LEFT JOIN [dbo].[KCO_verantw] [kv]
|
||||
ON [kv].[ID_KCO_Verantw] = [r].[KalibratieVerantw]
|
||||
LEFT JOIN [dbo].[CCWBS] [cw]
|
||||
ON [cw].[CCWBS_ID] = [r].[CCWBS_ID]
|
||||
WHERE [r].[deleted] = 0;
|
||||
'
|
||||
|
||||
EXEC sp_executesql N'
|
||||
ALTER PROCEDURE [dbo].[RegistryInsert]
|
||||
@IdentificatieToestel VARCHAR(20) = NULL,
|
||||
@TypeAanduiding VARCHAR(4) = NULL,
|
||||
@SerieNummer VARCHAR(25) = NULL,
|
||||
@Eigenaar VARCHAR(50) = NULL,
|
||||
@CCWBS_ID INT = NULL,
|
||||
@NaamFabrikant VARCHAR(50) = NULL,
|
||||
@NaamLeverancier VARCHAR(50) = NULL,
|
||||
@DatumInGebruik DATETIME = NULL,
|
||||
@DatumUitGebruik DATETIME = NULL,
|
||||
@Lokaal_ID INT = NULL,
|
||||
@id_statuslijst INT = NULL,
|
||||
@DefinitieNummerKal INT = NULL,
|
||||
@KalibratieFrequentie INT = NULL,
|
||||
@KalibratieFrequentieUnit CHAR(1) = NULL,
|
||||
@KalibratieVerantw INT = NULL,@Assetnr varchar(20)=null
|
||||
AS
|
||||
DECLARE @RegistryID INT;
|
||||
INSERT [dbo].[Register]
|
||||
(
|
||||
[IdentificatieToestel],
|
||||
[TypeAanduiding],
|
||||
[SerieNummer],
|
||||
[Eigenaar],
|
||||
[CCWBS_ID],
|
||||
[NaamFabrikant],
|
||||
[NaamLeverancier],
|
||||
[DatumInGebruik],
|
||||
[DatumUitGebruik],
|
||||
[Lokaal_ID],
|
||||
[id_statuslijst],
|
||||
[DefinitieNummerKal],
|
||||
[KalibratieFrequentie],
|
||||
[KalibratieFrequentieUnit],
|
||||
[KalibratieVerantw],
|
||||
[deleted],[Assetnr]
|
||||
)
|
||||
VALUES
|
||||
(@IdentificatieToestel, @TypeAanduiding, @SerieNummer, @Eigenaar, @CCWBS_ID, @NaamFabrikant, @NaamLeverancier,
|
||||
@DatumInGebruik, @DatumUitGebruik, @Lokaal_ID, @id_statuslijst, @DefinitieNummerKal, @KalibratieFrequentie,
|
||||
@KalibratieFrequentieUnit, @KalibratieVerantw, 0,@Assetnr);
|
||||
SET @RegistryID = SCOPE_IDENTITY();
|
||||
SELECT [r].[RegistryID],
|
||||
[r].[IdentificatieToestel],
|
||||
[r].[TypeAanduiding],
|
||||
[TypeAanduidingNaam] = [tl].[ToestelModelNaam],
|
||||
[r].[SerieNummer],
|
||||
[Eigenaar] = ISNULL([r].[Eigenaar], ''HPH''),
|
||||
[CCWBS_ID] = ISNULL([r].[CCWBS_ID], 1),
|
||||
[cw].[WBSCC_nr],
|
||||
[r].[NaamFabrikant],
|
||||
[r].[NaamLeverancier],
|
||||
[r].[DatumInGebruik], --= Today (Default + aanpassing mogelijk)
|
||||
[r].[DatumUitGebruik],
|
||||
[r].[Lokaal_ID],
|
||||
[lk].[LokaalNaam], --– SELECT [dbo_Lokaal].[Lokaal_ID], [dbo_Lokaal].[LokaalNaam] FROM dbo_Lokaal ORDER BY [LokaalNaam];
|
||||
[r].[id_statuslijst],
|
||||
[sl].[RegisterStatus] [DefinitieNummerKal],
|
||||
[r].[KalibratieFrequentie],
|
||||
[r].[KalibratieFrequentieUnit],
|
||||
[KalibratieFrequentieUnitName] = [fe].[description],
|
||||
[r].[KalibratieVerantw],
|
||||
[KalibratieVerantwAfkorting] = [kv].[Afkorting], [r].[Assetnr]
|
||||
FROM [dbo].[Register] [r]
|
||||
LEFT JOIN [dbo].[Toestelmodel] AS [tl]
|
||||
ON [tl].[TypeAanduiding] = [r].[TypeAanduiding]
|
||||
LEFT JOIN [dbo].[Lokaal] AS [lk]
|
||||
ON [lk].[Lokaal_ID] = [r].[Lokaal_ID]
|
||||
LEFT JOIN [dbo].[Statuslijst] [sl]
|
||||
ON [sl].[ID_statuslijst] = [r].[id_statuslijst]
|
||||
LEFT JOIN [dbo].[frequentieEenheid] [fe]
|
||||
ON [fe].[FrequentieEenheid] = [r].[KalibratieFrequentieUnit]
|
||||
LEFT JOIN [dbo].[KCO_verantw] [kv]
|
||||
ON [kv].[ID_KCO_Verantw] = [r].[KalibratieVerantw]
|
||||
LEFT JOIN [dbo].[CCWBS] [cw]
|
||||
ON [cw].[CCWBS_ID] = [r].[CCWBS_ID]
|
||||
WHERE [r].[RegistryID] = @RegistryID;
|
||||
'
|
||||
|
||||
EXEC sp_executesql N'
|
||||
ALTER PROCEDURE [dbo].[RegistryUpdate]
|
||||
@RegistryID INT,
|
||||
@IdentificatieToestel VARCHAR(20) = NULL,
|
||||
@TypeAanduiding VARCHAR(4) = NULL,
|
||||
@SerieNummer VARCHAR(25) = NULL,
|
||||
@Eigenaar VARCHAR(50) = NULL,
|
||||
@CCWBS_ID INT = NULL,
|
||||
@NaamFabrikant VARCHAR(50) = NULL,
|
||||
@NaamLeverancier VARCHAR(50) = NULL,
|
||||
@DatumInGebruik DATETIME = NULL,
|
||||
@DatumUitGebruik DATETIME = NULL,
|
||||
@Lokaal_ID INT = NULL, ----niet meer update , is via tabel
|
||||
@id_statuslijst INT = NULL, --niet meer update
|
||||
@DefinitieNummerKal INT = NULL,
|
||||
@KalibratieFrequentie INT = NULL,
|
||||
@KalibratieFrequentieUnit CHAR(1) = NULL,
|
||||
@KalibratieVerantw INT = NULL,
|
||||
@Assetnr VARCHAR(20) = NULL
|
||||
AS
|
||||
DECLARE @now DATETIME = GETDATE();
|
||||
|
||||
DECLARE @id_status INT;
|
||||
DECLARE @usr VARCHAR(20) = LEFT(SYSTEM_USER, 20);
|
||||
INSERT [dbo].[Status]
|
||||
(
|
||||
[RegistryID],
|
||||
[Datum],
|
||||
[id_statuslijst],
|
||||
[lokaalInfo],
|
||||
[opmerking],
|
||||
[creator],
|
||||
[created],
|
||||
[changer],
|
||||
[changed]
|
||||
)
|
||||
VALUES
|
||||
(@RegistryID, @now, @id_statuslijst, @Lokaal_ID, ''initial'', @usr, @now, @usr, @now);
|
||||
SET @id_status = SCOPE_IDENTITY();
|
||||
|
||||
|
||||
UPDATE [dbo].[Register]
|
||||
SET [IdentificatieToestel] = @IdentificatieToestel,
|
||||
[TypeAanduiding] = @TypeAanduiding,
|
||||
[SerieNummer] = @SerieNummer,
|
||||
[Eigenaar] = @Eigenaar,
|
||||
[CCWBS_ID] = @CCWBS_ID,
|
||||
[NaamFabrikant] = @NaamFabrikant,
|
||||
[NaamLeverancier] = @NaamLeverancier,
|
||||
[DefinitieNummerKal] = @DefinitieNummerKal,
|
||||
[KalibratieFrequentie] = @KalibratieFrequentie,
|
||||
[KalibratieFrequentieUnit] = @KalibratieFrequentieUnit,
|
||||
[KalibratieVerantw] = @KalibratieVerantw,
|
||||
[id_statuslijst] = @id_statuslijst,
|
||||
[Last_ID_Status] = @id_status,
|
||||
[Last_Date_Status] = @now,
|
||||
--,[Lokaal_ID]= @Lokaal_ID
|
||||
[DatumInGebruik] = @DatumInGebruik,
|
||||
[DatumUitGebruik] = @DatumUitGebruik,
|
||||
[Assetnr] = ISNULL(@Assetnr, [Assetnr])
|
||||
WHERE [RegistryID] = @RegistryID;
|
||||
'
|
||||
|
||||
-- =========================================================
|
||||
-- RECORD SUCCESSFUL VERSION UPDATE
|
||||
-- =========================================================
|
||||
INSERT INTO dbo.SchemaVersion (VersionNumber, ScriptDescription)
|
||||
VALUES (@CurrentVersion, 'Added Assetnr to Registryxxx sp');
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
PRINT 'Successfully applied update to version ' + @CurrentVersion;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
ROLLBACK TRANSACTION;
|
||||
|
||||
-- Print exception details
|
||||
DECLARE @ErrorMessage NVARCHAR(4000) = ERROR_MESSAGE();
|
||||
RAISERROR('Failed to apply version %s. Error: %s', 16, 1, @CurrentVersion, @ErrorMessage);
|
||||
END CATCH;
|
||||
GO
|
||||
15
Safety.sln
15
Safety.sln
|
|
@ -1,12 +1,14 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.32413.119
|
||||
# Visual Studio Version 18
|
||||
VisualStudioVersion = 18.9.12105.275 stable
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Safety", "Safety\Safety.csproj", "{5099A83B-4C18-45E6-8548-B59036CB28CC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitmap", "Bitmap\Bitmap.csproj", "{8FEA7C86-2680-40AB-BF06-78E6324D1594}"
|
||||
EndProject
|
||||
Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "SQLUpdates", "SQLUpdates\SQLUpdates.sqlproj", "{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -26,6 +28,15 @@ Global
|
|||
{8FEA7C86-2680-40AB-BF06-78E6324D1594}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8FEA7C86-2680-40AB-BF06-78E6324D1594}.TestServer|Any CPU.ActiveCfg = TestServer|Any CPU
|
||||
{8FEA7C86-2680-40AB-BF06-78E6324D1594}.TestServer|Any CPU.Build.0 = TestServer|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.TestServer|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.TestServer|Any CPU.Build.0 = Release|Any CPU
|
||||
{331288F7-0A1C-4795-BD75-5FFD5C31B2DA}.TestServer|Any CPU.Deploy.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue