Skip to content

Commit

Permalink
Handle tables without a primary key
Browse files Browse the repository at this point in the history
Fixes issue obsidiansystems#25
  • Loading branch information
mightybyte committed Jul 28, 2021
1 parent 3728df4 commit 0fd33d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Database/Beam/AutoMigrate/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ mkTableEntryNoFkDiscovery ::
mkTableEntryNoFkDiscovery annEntity =
let entity = annEntity ^. deannotate
tName = entity ^. dbEntityDescriptor . dbEntityName
pks = S.singleton (PrimaryKey (tName <> "_pkey") (S.fromList $ pkFieldNames entity))
pkColSet = S.fromList $ pkFieldNames entity
pks = if S.null pkColSet then mempty else S.singleton (PrimaryKey (tName <> "_pkey") pkColSet)
(columns, seqs) = gColumns (Proxy @ 'GenSequences) (TableName tName) . from $ dbAnnotatedSchema (annEntity ^. annotatedDescriptor)
annotatedCons = dbAnnotatedConstraints (annEntity ^. annotatedDescriptor)
in ((TableName tName, Table (pks <> annotatedCons) columns), seqs)
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Beam/AutoMigrate/Postgres.hs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ getAllConstraints conn = do
let columnSet = S.fromList . V.toList $ sqlCon_fk_colums
case sqlCon_constraint_type of
SQL_raw_unique -> addTableConstraint currentTable (Unique sqlCon_name columnSet)
SQL_raw_pk -> addTableConstraint currentTable (PrimaryKey sqlCon_name columnSet)
SQL_raw_pk -> if S.null columnSet then pure () else
addTableConstraint currentTable (PrimaryKey sqlCon_name columnSet)

newtype ReferenceActions = ReferenceActions {getActions :: Map Text Actions}

Expand Down

0 comments on commit 0fd33d6

Please sign in to comment.