/*
 * $Id: migpost76.sql 84480 2007-07-24 06:34:27Z pca $
 *
 * Finish migrating a ManageSoft 7.5 database into ManageSoft 7.6 format.
 *
 * Use migprep.sql first, then schema.sql, then this, and finally
 * install Managesoft 7.6 which will create the stored procedures.
 *
 * Called after building the new tables, this script:
 * - migrates data from old tables
 *
 * Copyright 1995-2003 ManageSoft Corporation Ltd ABN 40 052 412 156. All rights reserved.
 */

USE ManageSoft
GO

/*
 * Check that we are upgrading from a 7.5 database...
 */
DECLARE @schema_version char(10)
SET @schema_version = (SELECT Value FROM DatabaseConfiguration
		WHERE Property = 'SchemaVersion')

IF (@schema_version = '7.5')
BEGIN
	PRINT 'Completing migration to ManageSoft 7.6 database information...'
END
ELSE IF (@schema_version = '7.6')
BEGIN
	RAISERROR ('Your ManageSoft database has already been migrated to 7.6', 16, 1)
	RAISERROR ('For more information on migrating your database, refer to the ManageSoft Upgrade Guide.', 16, 1)
END
ELSE
BEGIN
	RAISERROR ('This script can only migrate database information from ManageSoft 7.5, not from any previous versions.', 16, 1)
	RAISERROR ('Please migrate any previous versions of your ManageSoft database first.', 16, 1)
	RAISERROR ('For more information on migrating your database, refer to the ManageSoft Upgrade Guide.', 16, 1)
END
GO

--===========================================================================
--		Update the DatabaseConfiguration table
--
--		NOTE: do this last
--===========================================================================
PRINT 'Recording successful migration'
UPDATE DatabaseConfiguration SET Value = '7.6'
	WHERE Property = 'SchemaVersion'
GO

