1
Fork 0
mirror of https://github.com/Airsequel/AirGQL.git synced 2025-08-14 10:46:58 +03:00

Mark primary keys as UNIQUE

This commit is contained in:
prescientmoon 2024-05-27 12:55:43 +02:00
commit 3cef611c85

View file

@ -337,6 +337,13 @@ getColumnUniqueConstraint col_name = \case
{ name = getFirstName names
, columns = [col_name]
}
-- Primary keys are unique by default, even though they do not have an unique index
SQL.ColConstraintDef names (SQL.ColPrimaryKeyConstraint _) ->
Just $
UniqueConstraint
{ name = getFirstName names
, columns = [col_name]
}
_ -> Nothing
@ -348,6 +355,13 @@ tableUniqueConstraints = \case
, columns = P.fmap nameAsText columns
}
]
-- Primary keys are unique by default, even though they do not have an unique index
SQL.TableConstraintDef names (SQL.TablePrimaryKeyConstraint columns) ->
[ UniqueConstraint
{ name = getFirstName names
, columns = P.fmap nameAsText columns
}
]
SQL.TableColumnDef (SQL.ColumnDef col_name _ _ constraints) ->
P.mapMaybe (getColumnUniqueConstraint (nameAsText col_name)) constraints
_ -> []
@ -779,12 +793,8 @@ getColumnsFromParsedTableEntry connection tableEntry = do
, datatype = "INTEGER"
, datatype_gql = Just $ stringToGqlTypeName "Int"
, select_options = P.Nothing
, -- While the rowid is actually NOT NULL,
-- it must be set to false here
-- to show in the GraphQL docs that it can be omitted
-- since it will be set automatically.
notnull = False
, isUnique = False
, notnull = True
, isUnique = True
, isOmittable = True
, isGenerated = False
, dflt_value = P.Nothing