Repository navigation
A Postgres table constraint written UNIQUE(a, b) is no longer read as a column - #28
Merged
Merged
Conversation
… a column Postgres needs no space between a constraint keyword and its parenthesis, and Mattermost's migrations use that form throughout: UNIQUE(name, deleteat), PRIMARY KEY(id, channelid). The word splitter keeps a parenthesised group glued to the word before it, so the reader saw a column named "UNIQUE(name, deleteat)" (an info line for a column that does not exist) and a word "KEY(id, channelid)" that hid the primary key. The same held for CHECK( on a column and for ALTER TABLE ... ADD UNIQUE( / ADD CHECK(, which added a column. Keywords in the Postgres reader are now compared up to a parenthesis. The helper stays in this reader: the shared ddl.HasPrefixFold is also used by the ClickHouse reader, where a word like Kafka(...) is compared whole. Measured on all 280 of Mattermost v10.11.0's Postgres migration files: nine made-up columns before (channels, emoji, PropertyGroups, roles, schemes, sharedchannelremotes, teams, usergroups twice), none after, and no real column lost. RefuseRadar unchanged at 162 info. Not done here: Postgres folds unquoted identifiers to lower case, and the reader keeps CREATE TABLE PropertyGroups as written. Its own change.
This was referenced Nov 14, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
The Postgres reader compares keywords up to a
(. Postgres allowsUNIQUE(name, deleteat)andPRIMARY KEY(id, channelid)with no space, and Mattermost's migrations use that form throughout.ddl.Wordskeeps a parenthesised group glued to the word before it, so:UNIQUE(channelid, remoteid)was read as a column with that name, producing an info line for a column that does not exist;PRIMARY KEY(id, channelid)becamePRIMARY+KEY(id, channelid), so the primary key was lost. The replica-identity rule needs it;CHECK(...)ended up in the column's type;ALTER TABLE ... ADD UNIQUE(...)andADD CHECK(...)added a column.The helper
keywordstays in the Postgres reader.ddl.HasPrefixFoldis shared with the ClickHouse reader, which compares words likeKafka(...)whole.Corpus and tests first
corpus/postgres-glued-constraints: Mattermost v10.11.0's000006(emoji) and000037(sharedchannelremotes) with the real names. On main it printed two info lines forpublic.emoji.UNIQUE(name, deleteat)andpublic.sharedchannelremotes.UNIQUE(channelid, remoteid). Now it printsok.TestAConstraintGluedToItsParenthesisIsNotAColumncovers the cases the output doesn't show: the primary key[id channelid], a column-levelCHECK(,ADD UNIQUE(,ADD CHECK(, and a realADD COLUMNthat still works. It failed on main.Verified
gofmt -l .is clean;go vet,go buildandgo test ./...pass.idso that every other column is listed:channels,emoji,PropertyGroups,roles,schemes,sharedchannelremotes,teams,usergroupsx2);0 error(s), 0 warning(s), 162 info, the same with both builds.Found, not fixed here
Postgres folds unquoted identifiers to lower case, but the reader keeps
CREATE TABLE IF NOT EXISTS PropertyGroupsas written (Mattermost). That is its own change, with its own corpus entry.