Commits

Sean Ryan  committed 08a5657 Merge

Automated merge with file:%5C%5C192.168.0.203%5Cshared%5Chg_OdinCommon%5Cdeploysql

  • Participants
  • Parent commits 744d4f3, e1e38a7

Comments (0)

Files changed (4)

File scripts/DeploySQL.py

     print __doc__
 
 ###############################################################
+#self tests (unit tests!)
+def selfTestDeploySQL():
+	"""run some self-tests - basically unit tests"""
+	selfTestCommon()
+
+###############################################################
 #main() - main program entry point
 #args = <SQL Server>	<SQL user>	<SQL password>	<listfile of SQL scripts>		<output file of original database objects>
+selfTestDeploySQL()
+
 def main(argv):
 	
 	global sqlServerInstance, sqlDbName, sqlUser, sqlPassword, sqlScriptListfilePath, origOutputFilepath, pathToNewSqlDir, newOutputFilepath, sqlCmdDirPath, IsDummyRun
 	if os.path.exists(origOutputFilepath):
 		raise Exception("The output file of original objects, already exists: " + origOutputFilepath)
 
-
 ###############################################################
 #main
+
 validateArgs(sqlScriptListfilePath, origOutputFilepath)
 
 dbSettings = DatabaseConnectiongSettings(sqlServerInstance, sqlDbName, sqlUser, sqlPassword, sqlCmd, sqlCmdDirPath)
 dbConn = createConnection(dbSettings)
 dbVersion = getCurrentDatabaseVersion(dbConn)
 
+printOut("Current database version:" + str(dbVersion))
+
 dbObjects = readListfile(sqlScriptListfilePath)
 dbFilteredObjects = filterObjectsByDbVersion(dbVersion, dbObjects)
 

File scripts/clear_output_sql.bat

+del ..\database_scripts\*.sql  

File scripts/database_common.py

File contents unchanged.

File scripts/deploySQL_common.py

 def getNumWarnings():
 	return numWarnings
 
-def parseSchemaFromObjectName(sqlObjectName):
-	if "." in sqlObjectName:
-		iDotPos = sqlObjectName.find(".")
-		return sqlObjectName[0:iDotPos]
+def parseSchemaFromObjectName(sqlObjectNameFromFilename): #returns (schema, sqlObjectName)
+	schema = ""
+	sqlObjectName = ""
+	if "." in sqlObjectNameFromFilename:
+		iDotPos = sqlObjectNameFromFilename.find(".")
+		schema = sqlObjectNameFromFilename[0:iDotPos]
+		sqlObjectName = sqlObjectNameFromFilename[iDotPos + 1: ]
 	else:
-		return 'dbo' #default
+		schema = 'dbo' #default
+		sqlObjectName = sqlObjectNameFromFilename
+	return (schema, sqlObjectName)
 
-def parseSqlScriptName(dbObjectType, sqlScriptName):
+def parseSqlScriptName(dbObjectType, sqlScriptName): #returns (schema, sqlObjectName)
 	#we need to parse names like this:
 	#dbo.spLicenceDocLoader_IsLicenceTypeSigned.SQL
 	#dbo.spAmateurExam_Licence.StoredProcedure.sql
-	sqlObjectName = ""
+	sqlObjectNameFromFilename = ""
 	if (dbObjectType == 'SP'):
-		sqlObjectName = sqlScriptName.lower()
-		sqlObjectName = sqlObjectName.replace('.sql', '')
-		sqlObjectName = sqlObjectName.replace('.storedprocedure', '')
-	if (dbObjectType == 'UDF'):
-		sqlObjectName = sqlScriptName.lower()
-		sqlObjectName = sqlObjectName.replace('.sql', '')
-		sqlObjectName = sqlObjectName.replace('.UserDefinedFunction', '')
+		sqlObjectNameFromFilename = sqlScriptName.lower()
+		sqlObjectNameFromFilename = sqlObjectNameFromFilename.replace('.sql', '')
+		sqlObjectNameFromFilename = sqlObjectNameFromFilename.replace('.storedprocedure', '')
+	elif (dbObjectType == 'UDF'):
+		sqlObjectNameFromFilename = sqlScriptName.lower()
+		sqlObjectNameFromFilename = sqlObjectNameFromFilename.replace('.sql', '')
+		sqlObjectNameFromFilename = sqlObjectNameFromFilename.replace('.UserDefinedFunction', '')
 	elif (dbObjectType == 'VIEW'):
-		sqlObjectName = sqlScriptName.lower()
-		sqlObjectName = sqlObjectName.replace('.sql', '')
-		sqlObjectName = sqlObjectName.replace('.view', '')
+		sqlObjectNameFromFilename = sqlScriptName.lower()
+		sqlObjectNameFromFilename = sqlObjectNameFromFilename.replace('.sql', '')
+		sqlObjectNameFromFilename = sqlObjectNameFromFilename.replace('.view', '')
 	else:
 		if dbObjectType != 'SP_NEW' and dbObjectType != 'UDF_NEW' and dbObjectType != 'VIEW_NEW':
 			addWarning("Cannot determine original object for the SQL script " + sqlScriptName)
-	return sqlObjectName
+			
+	#remove the schema prefix, if it is present:
+	(schema, sqlObjectName) = parseSchemaFromObjectName(sqlObjectNameFromFilename)
+	
+	return (schema, sqlObjectName)
 
 #printOut()
 #this function prints out, according to user's options for verbosity
 				continue # a comment line
 			dbObjectType = row[1]
 			sqlScriptName = row[2]
-			sqlObjectName = parseSqlScriptName(dbObjectType, sqlScriptName)
+			(schema, sqlObjectName) = parseSqlScriptName(dbObjectType, sqlScriptName)
 			#printOut("dbObjectType = " + dbObjectType + " sqlScriptName = " + sqlScriptName + " sqlObjectName = " + sqlObjectName)
-			dbObjects.append(DatabaseObject(dbVersion,dbObjectType, sqlObjectName, sqlScriptName, parseSchemaFromObjectName(sqlObjectName)))
+			dbObjects.append(DatabaseObject(dbVersion,dbObjectType, sqlObjectName, sqlScriptName, schema))
 	return dbObjects
 
 def runExe(targetScriptName, targetScriptDirPath, args):
 def setLogVerbosity(verbosity):
 	global logVerbosity
 	logVerbosity = verbosity
+
+###############################################################
+#self tests - SUPPORT
+def checkEquals(testName, expected, actual):
+	if(expected != actual):
+		raise Exception("!!!TEST FAIL - "+testName+" - expected value:" + str(expected) + " actual value:" + str(actual) )
+
+def checkEqualsCaseInsensitive(testName, expected, actual):
+	checkEquals(testName, expected.lower(), actual.lower())
+
+###############################################################
+#self tests (unit tests!)
+
+def selfTestCommon():
+	"""run some self-tests - basically unit tests - for COMMON"""
+	test_parseSqlScriptName()
+
+def test_parseSqlScriptName_runner(dbObjectType, sqlScriptFilename, expectedSchema, expectedSqlObjectName):
+	testName = 'test_parseSqlScriptName_runner'
+	(actualSchema, actualSqlObjectName) = parseSqlScriptName(dbObjectType, sqlScriptFilename) #returns (schema, sqlObjectName)
+	checkEqualsCaseInsensitive(testName, expectedSchema, actualSchema)
+	checkEqualsCaseInsensitive(testName, expectedSqlObjectName, actualSqlObjectName)
+	return
+
+def test_parseSqlScriptName():
+	test_parseSqlScriptName_runner('SP', 'dbo.spAmateurExam_Licence.StoredProcedure.sql', 'dbo', 'spAmateurExam_Licence')
+	test_parseSqlScriptName_runner('SP', 'spLicenceDocumentation_GetPDFfilenameSuffix.StoredProcedure.sql', 'dbo', 'spLicenceDocumentation_GetPDFfilenameSuffix')
+	test_parseSqlScriptName_runner('SP', 'prs.uspPRSLicence_Report.StoredProcedure.sql', 'PRS', 'uspPRSLicence_Report')
+	test_parseSqlScriptName_runner('SP', 'prs.uspPRSLicence_Report.sql', 'PRS', 'uspPRSLicence_Report')
+	return