11import { plural , singular } from 'pluralize' ;
2- import { tableFromDDL } from 'src/dialects/postgres/ddl' ;
3- import type { PostgresDDL } from 'src/ext/mover-postgres' ;
42import { paramNameFor } from '../../dialects/postgres/typescript' ;
53import { assertUnreachable } from '../../utils' ;
64import type { Casing } from '../validations/common' ;
@@ -19,15 +17,15 @@ const withCasing = (value: string, casing: Casing) => {
1917export type SchemaForPull = {
2018 schema ?: string ;
2119 foreignKeys : {
22- schema : string ;
20+ schema ? : string ;
2321 table : string ;
2422 nameExplicit : boolean ;
2523 columns : string [ ] ;
26- schemaTo : string ;
24+ schemaTo ? : string ;
2725 tableTo : string ;
2826 columnsTo : string [ ] ;
29- onUpdate : 'NO ACTION' | 'RESTRICT' | 'SET NULL' | 'CASCADE' | 'SET DEFAULT' | null ;
30- onDelete : 'NO ACTION' | 'RESTRICT' | 'SET NULL' | 'CASCADE' | 'SET DEFAULT' | null ;
27+ onUpdate ? : 'NO ACTION' | 'RESTRICT' | 'SET NULL' | 'CASCADE' | 'SET DEFAULT' | string | null ;
28+ onDelete ? : 'NO ACTION' | 'RESTRICT' | 'SET NULL' | 'CASCADE' | 'SET DEFAULT' | string | null ;
3129 name : string ;
3230 entityType : 'fks' ;
3331 } [ ] ;
@@ -37,34 +35,10 @@ export type SchemaForPull = {
3735 } [ ] ;
3836} [ ] ;
3937
40- function postgresToRelationsPull ( schema : PostgresDDL ) : SchemaForPull {
41- return Object . values ( schema . tables . list ( ) ) . map ( ( table ) => {
42- const rawTable = tableFromDDL ( table , schema ) ;
43- return {
44- schema : rawTable . schema ,
45- foreignKeys : rawTable . fks ,
46- uniques : [
47- ...Object . values ( rawTable . uniques ) . map ( ( unq ) => ( {
48- columns : unq . columns ,
49- } ) ) ,
50- ...Object . values ( rawTable . indexes ) . map ( ( idx ) => ( {
51- columns : idx . columns . map ( ( idxc ) => {
52- if ( ! idxc . isExpression && idx . isUnique ) {
53- return idxc . value ;
54- }
55- } ) . filter ( ( item ) => item !== undefined ) ,
56- } ) ) ,
57- ] ,
58- } ;
59- } ) ;
60- }
61-
62- // TODO: take from beta
6338export const relationsToTypeScript = (
64- schemaInput : PostgresDDL ,
39+ schema : SchemaForPull ,
6540 casing : Casing ,
6641) => {
67- const schema = postgresToRelationsPull ( schemaInput ) ;
6842 const imports : string [ ] = [ ] ;
6943 const tableRelations : Record <
7044 string ,
0 commit comments