Skip to content

Add support for ADD UNIQUE indexes#3

Open
dmytroun1q wants to merge 1 commit intomasterfrom
add-unique
Open

Add support for ADD UNIQUE indexes#3
dmytroun1q wants to merge 1 commit intomasterfrom
add-unique

Conversation

@dmytroun1q
Copy link

@dmytroun1q dmytroun1q commented Jan 29, 2026

Resolve issue when ADD UNIQUE skipped

@dmytroun1q dmytroun1q self-assigned this Jan 29, 2026
Comment on lines +154 to +196
# Check if it's a single-line statement (ends with semicolon)
if( /;$/ ) {
# Process immediately

# Check if this is ADD INDEX or ADD UNIQUE
if( /ADD INDEX|add index|ADD UNIQUE|add unique/ ) {
isAddIndex = 1

# Extract table name
if( match( $0, /`[^`]+/ ) ){
alterTableName = substr( $0, RSTART+1, RLENGTH-1 )
}

# Extract index name
if( match( $0, /(ADD INDEX|add index|ADD UNIQUE|add unique) `[^`]+/ ) ){
indexMatch = substr( $0, RSTART, RLENGTH )
if( match( indexMatch, /`[^`]+$/ ) ){
alterIndexName = substr( indexMatch, RSTART+1, RLENGTH-1 )
}
}

# Extract column list
if( isAddIndex && alterTableName != "" && alterIndexName != "" ) {
if( match( alterStatement, /\([^)]+\)/ ) ){
columnList = substr( alterStatement, RSTART+1, RLENGTH-2 )
gsub( /[ \t\n\r]+/, " ", columnList )
gsub( /^ +| +$/, "", columnList )
gsub( /`/, "\"", columnList )

# Check if UNIQUE
uniquePrefix = ""
if( alterStatement ~ /ADD UNIQUE|add unique/ ) {
uniquePrefix = "UNIQUE "
}

print "CREATE " uniquePrefix "INDEX \"idx_" alterTableName "_" alterIndexName "\" ON \"" alterTableName "\" (" columnList ");"
}
}
}

# Reset
inAlterTable = 0
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand why all these lines need to be added: seems that unique indexes are handled a bit lower in this file.

Copy link
Author

@dmytroun1q dmytroun1q Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, can't say too much about this, but as I see according to the search over the previous version - ADD UNIQUE / UNIQUE does not appear anywhere in a file and current include. I tested several times and no error occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants