removed m2m markers

This commit is contained in:
2026-09-05 00:28:15 +02:00
parent 72b9a116be
commit fe83013c37
3 changed files with 2 additions and 65 deletions
+2 -24
View File
@@ -30,7 +30,7 @@ import PostgREST.Network (escapeHostName)
import PostgREST.Query.OpenApi (TableAccess (..), TablesAccess)
import PostgREST.SchemaCache (SchemaCache (..))
import PostgREST.SchemaCache.Identifiers (FieldName, QualifiedIdentifier (..))
import PostgREST.SchemaCache.Relationship (Cardinality (..), Junction (..),
import PostgREST.SchemaCache.Relationship (Cardinality (..),
Relationship (..), RelationshipsMap)
import PostgREST.SchemaCache.Routine (FuncVolatility (..), Routine (..),
RoutineParam (..))
@@ -110,35 +110,13 @@ parseDefault colType colDefault =
makeTableDef :: RelationshipsMap -> (Table, TableAccess) -> (Text, Schema)
makeTableDef rels (t, access) =
(tn, (mempty :: Schema)
& description .~ tblDescription
& description .~ tableDescription t
& type_ ?~ SwaggerObject
& properties .~ fromList (makeProperty t rels <$> cols)
& required .~ fmap colName (filter (not . colNullable) cols))
where
tn = tableName t
cols = accessibleCols t (taSelectCols access)
tblDescription = case m2mMarkers t rels of
[] -> tableDescription t
ms -> Just $ maybe "" (`T.append` "\n\n") (tableDescription t) <> T.intercalate "\n" ms
-- | Emits markers for the many-to-many relationships of a table, so that clients
-- can render these relations. The marker includes the target table(embedding key),
-- the junction table and the junction columns referencing source and target.
m2mMarkers :: Table -> RelationshipsMap -> [Text]
m2mMarkers tbl rels = mapMaybe m2mMarker searchedRels
where
searchedRels = fromMaybe mempty $ HM.lookup (QualifiedIdentifier (tableSchema tbl) (tableName tbl), tableSchema tbl) rels
m2mMarker Relationship{relForeignTable, relCardinality=M2M junction} =
Just $ T.intercalate ""
[ "<m2m table='", qiName relForeignTable
, "' junction='", qiName (junTable junction)
, "' source='", junctionSourceCols junction
, "' target='", junctionTargetCols junction
, "'/>"
]
m2mMarker _ = Nothing
junctionSourceCols junction = T.intercalate "," (snd <$> junColsSource junction)
junctionTargetCols junction = T.intercalate "," (snd <$> junColsTarget junction)
accessibleCols :: Table -> [FieldName] -> [Column]
accessibleCols t cols = filter ((`elem` cols) . colName) (tableColumnsList t)
-18
View File
@@ -361,15 +361,6 @@ spec withConfig = withConfig baseCfg $ describe "OpenAPI" $ do
}
|]
it "includes m2m relationship markers in the table description" $ do
r <- simpleBody <$> get "/"
let beingDescription = r ^? key "definitions" . key "being" . key "description"
liftIO $
beingDescription `shouldBe` Just
[aesonQQ|"<m2m table='part' junction='being_part' source='being' target='part'/>"|]
it "includes a composite foreign key marker with the full column mapping" $ do
r <- simpleBody <$> get "/"
@@ -400,15 +391,6 @@ spec withConfig = withConfig baseCfg $ describe "OpenAPI" $ do
}
|]
it "includes composite m2m relationship markers in the table description" $ do
r <- simpleBody <$> get "/"
let beingDescription = r ^? key "definitions" . key "comp_being" . key "description"
liftIO $
beingDescription `shouldBe` Just
[aesonQQ|"<m2m table='comp_thing' junction='comp_being_thing' source='a,b' target='x,y'/>"|]
describe "Foreign table" $
it "includes foreign table properties" $ do
-23
View File
@@ -1275,29 +1275,6 @@ create table test.comp_component_instance (
constraint comp_component_instance_component_fkey foreign key (product_id, component_id) references test.comp_component(product_id, component_id)
);
-- Tables for testing composite m2m relationships in the OpenAPI output
create table test.comp_being (
a int not null,
b int not null,
primary key(a, b)
);
create table test.comp_thing (
x int not null,
y int not null,
primary key(x, y)
);
create table test.comp_being_thing (
a int not null,
b int not null,
x int not null,
y int not null,
primary key(a, b, x, y),
constraint comp_being_thing_being_fkey foreign key (a, b) references test.comp_being(a, b),
constraint comp_being_thing_thing_fkey foreign key (x, y) references test.comp_thing(x, y)
);
create function test.single_out_param(num int, OUT num_plus_one int) AS $$
select num + 1;
$$ language sql;