Difference between revisions of "Heureka database upgrade script 0.5.2"

From Heureka Wiki
Jump to navigation Jump to search
(New page: Back to scripts <pre> IF (SELECT COUNT(*) FROM VERSION WHERE ApplicationVersion = '0.5.1.2' OR ApplicationVersion = '0.5.2' ) = 0 BEGIN PRINT 'Wrong...)
 
 
Line 1: Line 1:
[[Heureka database upgrade scripts | Back to scripts]]
+
[[:Category:Database scripts | Back to scripts]]
 
<pre>
 
<pre>
 
IF (SELECT COUNT(*) FROM VERSION WHERE ApplicationVersion = '0.5.1.2' OR ApplicationVersion = '0.5.2' ) = 0
 
IF (SELECT COUNT(*) FROM VERSION WHERE ApplicationVersion = '0.5.1.2' OR ApplicationVersion = '0.5.2' ) = 0
Line 41: Line 41:
 
</pre>
 
</pre>
  
[[Category:Database]]
+
[[Category:Database scripts]]

Latest revision as of 15:50, 14 July 2009

Back to scripts

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

	--1. Add columns to StandObject
	IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'StandObject' AND COLUMN_NAME = 'LastRegenerationYear')
	BEGIN
		ALTER TABLE StandObject ADD
			[LastRegenerationYear] [int] NULL
	END


	-- 2. Remove columns from StandObject
	IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'StandObject' AND COLUMN_NAME = 'TotalStandAge')
	BEGIN
		ALTER TABLE StandObject DROP COLUMN
			[TotalStandAge],
			[CleaningHistory],
			[FertilizationHistory]
	END

	--3. Rename InitialState_QModelData
	IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'InitialState_QModelData')
	BEGIN
		exec sp_rename 'InitialState_QModelData', 'InitialState_CarbonAndNitrogenData'
	END

	-- Update Version Table

	UPDATE Version SET ApplicationVersion = '0.5.2';

	PRINT 'Success! Database upgrade to version 0.5.2';

END