Skip to content

Commit 70ba291

Browse files
committed
refactor(codegen): replace pgTypesFile with metaFile / --dump-meta approach
- Expand MetaTableInfo to include fields[] with type.pgType from _meta - Replace enrichPgTypes(PgTypesMap) with enrichPgTypesFromMeta(MetaTableInfo[]) - Rename pgTypesFile -> metaFile in config (full _meta dump, not pgType-specific) - Rename --dump-pg-types -> --dump-meta in CLI (dumps MetaTableInfo[]) - Pipeline now auto-enriches pgType from _meta in database mode - metaFile serves as sidecar for file/schemaDir/endpoint modes - Heuristic fallbacks still work when no _meta is available - Update all tests to match new API (19 tests passing)
1 parent 3c545da commit 70ba291

9 files changed

Lines changed: 317 additions & 267 deletions

File tree

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildPgTypesMap } from '../../core/dump-pg-types';
1+
import { buildMetaFromTables } from '../../core/dump-pg-types';
22
import type { Table } from '../../types/schema';
33

44
function makeField(name: string, gqlType: string, isArray = false, pgType?: string | null) {
@@ -20,8 +20,8 @@ function makeTable(name: string, fields: ReturnType<typeof makeField>[]): Table
2020
};
2121
}
2222

23-
describe('buildPgTypesMap', () => {
24-
it('should build map from tables with pgType', () => {
23+
describe('buildMetaFromTables', () => {
24+
it('should build MetaTableInfo[] from tables with pgType', () => {
2525
const tables = [
2626
makeTable('Document', [
2727
makeField('id', 'UUID', false, 'uuid'),
@@ -30,67 +30,71 @@ describe('buildPgTypesMap', () => {
3030
]),
3131
];
3232

33-
const result = buildPgTypesMap(tables);
34-
expect(result).toEqual({
35-
Document: {
36-
id: { pgType: 'uuid' },
37-
vectorEmbedding: { pgType: 'vector' },
38-
tsvContent: { pgType: 'tsvector' },
39-
},
40-
});
33+
const result = buildMetaFromTables(tables);
34+
expect(result).toHaveLength(1);
35+
expect(result[0].name).toBe('Document');
36+
expect(result[0].fields).toEqual([
37+
{ name: 'id', type: { pgType: 'uuid', gqlType: 'UUID', isArray: false } },
38+
{ name: 'vectorEmbedding', type: { pgType: 'vector', gqlType: 'Float', isArray: true } },
39+
{ name: 'tsvContent', type: { pgType: 'tsvector', gqlType: 'FullText', isArray: false } },
40+
]);
4141
});
4242

43-
it('should set pgType to null when not available (template mode)', () => {
43+
it('should set pgType to "unknown" when not available', () => {
4444
const tables = [
4545
makeTable('User', [
4646
makeField('id', 'UUID'),
4747
makeField('name', 'String'),
4848
]),
4949
];
5050

51-
const result = buildPgTypesMap(tables);
52-
expect(result).toEqual({
53-
User: {
54-
id: { pgType: null },
55-
name: { pgType: null },
56-
},
57-
});
51+
const result = buildMetaFromTables(tables);
52+
expect(result).toHaveLength(1);
53+
expect(result[0].fields).toEqual([
54+
{ name: 'id', type: { pgType: 'unknown', gqlType: 'UUID', isArray: false } },
55+
{ name: 'name', type: { pgType: 'unknown', gqlType: 'String', isArray: false } },
56+
]);
5857
});
5958

60-
it('should include pgAlias and typmod when present', () => {
59+
it('should preserve relations', () => {
6160
const tables: Table[] = [
6261
{
6362
name: 'Article',
6463
fields: [
65-
{
66-
name: 'embedding',
67-
type: {
68-
gqlType: 'Float',
69-
isArray: true,
70-
pgType: 'vector',
71-
pgAlias: 'vector',
72-
typmod: 768,
73-
},
74-
},
64+
{ name: 'id', type: { gqlType: 'UUID', isArray: false, pgType: 'uuid' } },
7565
],
76-
relations: { belongsTo: [], hasOne: [], hasMany: [], manyToMany: [] },
66+
relations: {
67+
belongsTo: [],
68+
hasOne: [],
69+
hasMany: [],
70+
manyToMany: [{
71+
fieldName: 'tags',
72+
rightTable: 'Tag',
73+
junctionTable: 'ArticleTag',
74+
type: 'Tag',
75+
junctionLeftKeyFields: ['articleId'],
76+
junctionRightKeyFields: ['tagId'],
77+
leftKeyFields: ['id'],
78+
rightKeyFields: ['id'],
79+
}],
80+
},
7781
},
7882
];
7983

80-
const result = buildPgTypesMap(tables);
81-
expect(result.Article.embedding).toEqual({
82-
pgType: 'vector',
83-
pgAlias: 'vector',
84-
typmod: 768,
85-
});
84+
const result = buildMetaFromTables(tables);
85+
expect(result[0].relations.manyToMany).toHaveLength(1);
86+
expect(result[0].relations.manyToMany[0].junctionTable.name).toBe('ArticleTag');
87+
expect(result[0].relations.manyToMany[0].rightTable.name).toBe('Tag');
8688
});
8789

8890
it('should handle empty tables array', () => {
89-
expect(buildPgTypesMap([])).toEqual({});
91+
expect(buildMetaFromTables([])).toEqual([]);
9092
});
9193

9294
it('should handle tables with no fields', () => {
9395
const tables = [makeTable('Empty', [])];
94-
expect(buildPgTypesMap(tables)).toEqual({});
96+
const result = buildMetaFromTables(tables);
97+
expect(result).toHaveLength(1);
98+
expect(result[0].fields).toEqual([]);
9599
});
96100
});

0 commit comments

Comments
 (0)