text: ﻿/*
  Deployment script for ObservationsFynbos
  
  This code was generated by a tool.
  Changes to this file may cause incorrect behavior and will be lost if
  the code is regenerated.
  */
  
  GO
  SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
  
  SET NUMERIC_ROUNDABORT OFF;
  
  
  GO
  :setvar DatabaseName "ObservationsFynbos"
  :setvar DefaultFilePrefix "ObservationsFynbos"
  :setvar DefaultDataPath "D:\Program Files\Microsoft SQL Server\MSSQL14.SAEON\MSSQL\DATA\"
  :setvar DefaultLogPath "D:\Program Files\Microsoft SQL Server\MSSQL14.SAEON\MSSQL\DATA\"
  
  GO
  :on error exit
  GO
  /*
  Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
  To re-enable the script after enabling SQLCMD mode, execute the following:
  SET NOEXEC OFF; 
  */
  :setvar __IsSqlCmdEnabled "True"
  GO
  IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
      BEGIN
          PRINT N'SQLCMD mode must be enabled to successfully execute this script.';
          SET NOEXEC ON;
      END
  
  
  GO
  USE [$(DatabaseName)];
  
  
  --GO
  --IF EXISTS (SELECT 1
  --           FROM   [master].[dbo].[sysdatabases]
  --           WHERE  [name] = N'$(DatabaseName)')
  --    BEGIN
  --        ALTER DATABASE [$(DatabaseName)]
  --            SET TEMPORAL_HISTORY_RETENTION ON 
  --            WITH ROLLBACK IMMEDIATE;
  --    END
  
  
  GO
  PRINT N'Dropping [dbo].[Observation].[IX_Observation_ValueDecade]...';
  
  
  GO
  DROP INDEX [IX_Observation_ValueDecade]
      ON [dbo].[Observation];
  
  
  GO
  PRINT N'Dropping [dbo].[Observation].[IX_Observation_ValueYear]...';
  
  
  GO
  DROP INDEX [IX_Observation_ValueYear]
      ON [dbo].[Observation];
  
  
  GO
  PRINT N'Altering [dbo].[DataSource]...';
  
  
  GO
  ALTER TABLE [dbo].[DataSource] ALTER COLUMN [Url] VARCHAR (250) NULL;
  
  
  GO
  PRINT N'Altering [dbo].[Observation]...';
  
  
  GO
  ALTER TABLE [dbo].[Observation] DROP COLUMN [ValueYear], COLUMN [ValueDecade];
  
  
  GO
  ALTER TABLE [dbo].[Observation]
      ADD [ValueYear]   AS (Year([ValueDate])),
          [ValueDecade] AS (Year([ValueDate]) / 10 * 10);
  
  
  GO
  PRINT N'Creating [dbo].[Observation].[IX_Observation_ValueDecade]...';
  
  
  GO
  CREATE NONCLUSTERED INDEX [IX_Observation_ValueDecade]
      ON [dbo].[Observation]([ValueDecade] ASC)
      ON [Observations];
  
  
  GO
  PRINT N'Creating [dbo].[Observation].[IX_Observation_ValueYear]...';
  
  
  GO
  CREATE NONCLUSTERED INDEX [IX_Observation_ValueYear]
      ON [dbo].[Observation]([ValueYear] ASC)
      ON [Observations];
  
  
  GO
  PRINT N'Refreshing [dbo].[vDataSource]...';
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vDataSource]';
  
  
  GO
  PRINT N'Refreshing [dbo].[vDataSourceTransformation]...';
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vDataSourceTransformation]';
  
  
  GO
  PRINT N'Refreshing [dbo].[vImportBatch]...';
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vImportBatch]';
  
  
  GO
  PRINT N'Refreshing [dbo].[vSensor]...';
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vSensor]';
  
  
  GO
  PRINT N'Refreshing [dbo].[vObservationExpansion]...';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER OFF;
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vObservationExpansion]';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER ON;
  
  
  GO
  PRINT N'Refreshing [dbo].[vSensorThingsAPIObservations]...';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER OFF;
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vSensorThingsAPIObservations]';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER ON;
  
  
  GO
  PRINT N'Refreshing [dbo].[vObservationJSON]...';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER OFF;
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vObservationJSON]';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER ON;
  
  
  GO
  PRINT N'Refreshing [dbo].[vStationObservations]...';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER OFF;
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vStationObservations]';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER ON;
  
  
  GO
  PRINT N'Refreshing [dbo].[vObservation]...';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER OFF;
  
  
  GO
  EXECUTE sp_refreshsqlmodule N'[dbo].[vObservation]';
  
  
  GO
  SET ANSI_NULLS, QUOTED_IDENTIFIER ON;
  
  
  GO
  PRINT N'Update complete.';
  
  
  GO
  