Last active
July 28, 2016 02:18
-
-
Save pinzolo/1fa93e8daa967eabd6643b5592744a33 to your computer and use it in GitHub Desktop.
serialのシーケンスがなが~い名前になる場合の命名ロジック(pg_get_serial_sequenceの中身を想像)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MAX_SEQ_NAME_LENGTH = 63; | |
var PARTS_LENGTH_THRESHOLD = 29; | |
function getSerialSequence(tableName, columnName) { | |
t = tableName; | |
c = columnName; | |
if (tableName.length + columnName.length + 5 > MAX_SEQ_NAME_LENGTH) { | |
if (tableName.length > PARTS_LENGTH_THRESHOLD) { | |
if (columnName.length > PARTS_LENGTH_THRESHOLD) { | |
t = tableName.substring(0, PARTS_LENGTH_THRESHOLD); | |
c = columnName.substring(0, PARTS_LENGTH_THRESHOLD); | |
} else { | |
t = tableName.substring(0, PARTS_LENGTH_THRESHOLD + (PARTS_LENGTH_THRESHOLD - columnName.length)); | |
} | |
} else { | |
c = columnName.substring(0, PARTS_LENGTH_THRESHOLD + (PARTS_LENGTH_THRESHOLD - tableName.length)); | |
} | |
} | |
return t + "_" + c + "_seq"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment