Skip to content

Commit ee71b0a

Browse files
Fix: PRIMARY KEY implies NOT NULL in SQL parser
1 parent 57c2b4a commit ee71b0a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/schemaforge/parsers/sql_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,16 @@ def _parse_column_def(self, defn: str) -> Column | None:
228228
# Parse constraints
229229
constraints = " ".join(tokens[type_start+1:]) if type_start + 1 < len(tokens) else ""
230230

231+
is_pk = "PRIMARY KEY" in constraints.upper()
232+
is_not_null = "NOT NULL" in constraints.upper()
233+
231234
col = Column(
232235
name=col_name,
233236
type=col_type,
234237
type_args=type_args,
235-
nullable="NOT NULL" not in constraints.upper(),
236-
unique="UNIQUE" in constraints.upper(),
237-
primary_key="PRIMARY KEY" in constraints.upper(),
238+
nullable=not (is_not_null or is_pk),
239+
unique="UNIQUE" in constraints.upper() and not is_pk,
240+
primary_key=is_pk,
238241
)
239242

240243
# Extract default

0 commit comments

Comments
 (0)