/plugins/dbmigrate/adapters/PostgreSQL.cfc

http://raihan.googlecode.com/ · ColdFusion CFScript · 61 lines · 46 code · 15 blank · 0 comment · 1 complexity · c975093af6ff8ad3ed055f3c1bfa9230 MD5 · raw file

  1. <cfcomponent extends="Abstract">
  2. <cfset variables.sqlTypes = {}>
  3. <cfset variables.sqlTypes['primaryKey'] = "SERIAL PRIMARY KEY">
  4. <cfset variables.sqlTypes['binary'] = {name='BYTEA'}>
  5. <cfset variables.sqlTypes['boolean'] = {name='BOOLEAN'}>
  6. <cfset variables.sqlTypes['date'] = {name='DATE'}>
  7. <cfset variables.sqlTypes['datetime'] = {name='TIMESTAMP'}>
  8. <cfset variables.sqlTypes['decimal'] = {name='DECIMAL'}>
  9. <cfset variables.sqlTypes['float'] = {name='FLOAT'}>
  10. <cfset variables.sqlTypes['integer'] = {name='INTEGER'}>
  11. <cfset variables.sqlTypes['string'] = {name='CHARACTER VARYING',limit=255}>
  12. <cfset variables.sqlTypes['text'] = {name='TEXT'}>
  13. <cfset variables.sqlTypes['time'] = {name='TIME'}>
  14. <cfset variables.sqlTypes['timestamp'] = {name='TIMESTAMP'}>
  15. <cffunction name="adapterName" returntype="string" access="public" hint="name of database adapter">
  16. <cfreturn "PostgreSQL">
  17. </cffunction>
  18. <!--- postgres uses double quotes --->
  19. <cffunction name="quoteColumnName" returntype="string" access="public" hint="surrounds column names with quotes">
  20. <cfargument name="name" type="string" required="true" hint="column name">
  21. <cfreturn '"#arguments.name#"'>
  22. </cffunction>
  23. <!--- createTable - use default --->
  24. <cffunction name="renameTable" returntype="string" access="public" hint="generates sql to rename a table">
  25. <cfargument name="oldName" type="string" required="true" hint="old table name">
  26. <cfargument name="newName" type="string" required="true" hint="new table name">
  27. <cfreturn "ALTER TABLE #quoteTableName(arguments.oldName)# RENAME TO #quoteTableName(arguments.newName)#">
  28. </cffunction>
  29. <!--- dropTable - use default --->
  30. <!--- NOTE FOR addColumnToTable & changeColumnInTable
  31. Rails adaptor appears to be applying default/nulls in separate queries
  32. Need to check if that is necessary --->
  33. <!--- addColumnToTable - ? --->
  34. <!--- changeColumnInTable - ? --->
  35. <!--- renameColumnInTable - use default --->
  36. <!--- dropColumnFromTable - use default --->
  37. <!--- addForeignKeyToTable - use default --->
  38. <cffunction name="dropForeignKeyFromTable" returntype="string" access="public" hint="generates sql to add a foreign key constraint to a table">
  39. <cfargument name="name" type="string" required="true" hint="table name">
  40. <cfargument name="keyName" type="any" required="true" hint="foreign key name">
  41. <cfreturn "ALTER TABLE #quoteTableName(LCase(arguments.name))# DROP CONSTRAINT #quoteTableName(arguments.keyname)#">
  42. </cffunction>
  43. <!--- foreignKeySQL - use default --->
  44. <!--- addIndex - use default --->
  45. <!--- removeIndex - use default --->
  46. </cfcomponent>