Heureka database upgrade script 0.5.3.1

From Heureka Wiki
Revision as of 13:13, 6 May 2009 by Cawa2 (talk | contribs) (New page: Back to scripts <pre> IF (SELECT COUNT(*) FROM VERSION WHERE ApplicationVersion = '0.5.3' OR ApplicationVersion = '0.5.3.1' ) = 0 BEGIN PRINT 'Wron...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Back to scripts


IF (SELECT COUNT(*) FROM VERSION WHERE ApplicationVersion = '0.5.3' OR ApplicationVersion = '0.5.3.1' ) = 0
BEGIN
	PRINT 'Wrong Version of database. You must upgrade to version 0.5.3 before running this script.';
	SELECT ApplicationVersion FROM VERSION;
END
ELSE 
BEGIN		

	-- 1. Add table TreatmentUnitNeighbour

	IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TreatmentUnitNeighbour')
	BEGIN
		CREATE TABLE [dbo].[TreatmentUnitNeighbour](
			[TreatmentUnitGUID] [uniqueidentifier] NOT NULL,
			[TreatmentUnitNeighbourGUID] [uniqueidentifier] NOT NULL,
			[CommonBorderLength] [int] NOT NULL,
		 CONSTRAINT [PK_TreatmentUnitNeighbour] PRIMARY KEY CLUSTERED 
		(
			[TreatmentUnitGUID] ASC,
			[TreatmentUnitNeighbourGUID] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
		) ON [PRIMARY]
		ALTER TABLE [dbo].[TreatmentUnitNeighbour]  WITH CHECK ADD  CONSTRAINT [FK_TreatmentUnitNeighbour_TreatmentUnit] FOREIGN KEY([TreatmentUnitGUID])
		REFERENCES [dbo].[TreatmentUnit] ([TreatmentUnitGUID]) ON DELETE CASCADE
		ALTER TABLE [dbo].[TreatmentUnitNeighbour] CHECK CONSTRAINT [FK_TreatmentUnitNeighbour_TreatmentUnit]
	END

	-- Update Version Table

	UPDATE Version SET ApplicationVersion = '0.5.3.1';

	PRINT 'Success! Database upgrade to version 0.5.3.1';

END