50
50
* type_scheme: string|null,
51
51
* character_maximum_length: int,
52
52
* column_comment: string|null,
53
- * modifier: int,
54
53
* is_nullable: bool,
55
54
* column_default: string|null,
56
55
* is_autoinc: bool,
57
56
* sequence_name: string|null,
58
57
* enum_values: string|null,
59
- * numeric_precision: int|null,
60
- * numeric_scale: int|null,
61
58
* size: string|null,
62
- * is_pkey: bool|null,
59
+ * scale: int|null,
60
+ * contype: string|null,
63
61
* dimension: int
64
62
* }
65
63
* @psalm-type ConstraintArray = array<
@@ -623,7 +621,6 @@ protected function findColumns(TableSchemaInterface $table): bool
623
621
(SELECT nspname FROM pg_namespace WHERE oid = COALESCE(td.typnamespace, tb.typnamespace, t.typnamespace)) AS type_scheme,
624
622
a.attlen AS character_maximum_length,
625
623
pg_catalog.col_description(c.oid, a.attnum) AS column_comment,
626
- information_schema._pg_truetypmod(a, t) AS modifier,
627
624
NOT (a.attnotnull OR t.typnotnull) AS is_nullable,
628
625
COALESCE(t.typdefault, pg_get_expr(ad.adbin, ad.adrelid)) AS column_default,
629
626
COALESCE(pg_get_expr(ad.adbin, ad.adrelid) ~ 'nextval', false) $ orIdentity AS is_autoinc,
@@ -639,19 +636,25 @@ protected function findColumns(TableSchemaInterface $table): bool
639
636
',')
640
637
ELSE NULL
641
638
END AS enum_values,
642
- information_schema._pg_numeric_precision(
643
- COALESCE(td.oid, tb.oid, a.atttypid),
644
- information_schema._pg_truetypmod(a, t)
645
- ) AS numeric_precision,
639
+ COALESCE(
640
+ information_schema._pg_char_max_length(
641
+ COALESCE(td.oid, tb.oid, a.atttypid),
642
+ a.atttypmod
643
+ ),
644
+ information_schema._pg_datetime_precision(
645
+ COALESCE(td.oid, tb.oid, a.atttypid),
646
+ a.atttypmod
647
+ ),
648
+ CASE a.atttypmod
649
+ WHEN -1 THEN null
650
+ ELSE ((a.atttypmod - 4) >> 16) & 65535
651
+ END
652
+ ) AS size,
646
653
information_schema._pg_numeric_scale(
647
654
COALESCE(td.oid, tb.oid, a.atttypid),
648
- information_schema._pg_truetypmod(a, t)
649
- ) AS numeric_scale,
650
- information_schema._pg_char_max_length(
651
- COALESCE(td.oid, tb.oid, a.atttypid),
652
- information_schema._pg_truetypmod(a, t)
653
- ) AS size,
654
- ct.oid IS NOT NULL AS is_pkey,
655
+ a.atttypmod
656
+ ) AS scale,
657
+ ct.contype,
655
658
COALESCE(NULLIF(a.attndims, 0), NULLIF(t.typndims, 0), (t.typcategory='A')::int) AS dimension
656
659
FROM
657
660
pg_class c
@@ -663,11 +666,11 @@ protected function findColumns(TableSchemaInterface $table): bool
663
666
LEFT JOIN pg_type td ON t.typndims > 0 AND t.typbasetype > 0 AND tb.typelem = td.oid
664
667
LEFT JOIN pg_namespace d ON d.oid = c.relnamespace
665
668
LEFT JOIN pg_rewrite rw ON c.relkind = 'v' AND rw.ev_class = c.oid AND rw.rulename = '_RETURN'
666
- LEFT JOIN pg_constraint ct ON ct.conrelid = c.oid AND ct.contype = 'p ' AND a.attnum = ANY (ct.conkey)
667
- OR rw.ev_action IS NOT NULL AND ct.contype = 'p'
668
- AND (ARRAY(
669
+ LEFT JOIN pg_constraint ct ON ( ct.contype = 'p' OR ct.contype = 'u ' AND cardinality (ct.conkey) = 1 )
670
+ AND (ct.conrelid = c.oid AND a.attnum = ANY (ct.conkey)
671
+ OR rw.ev_action IS NOT NULL AND (ARRAY(
669
672
SELECT regexp_matches(rw.ev_action, '{TARGETENTRY .*? :resorigtbl (\d+) :resorigcol (\d+) ', 'g')
670
- ))[a.attnum:a.attnum] <@ (ct.conrelid::text || ct.conkey::text[])
673
+ ))[a.attnum:a.attnum] <@ (ct.conrelid::text || ct.conkey::text[]))
671
674
WHERE
672
675
a.attnum > 0 AND t.typname != '' AND NOT a.attisdropped
673
676
AND c.relname = :tableName
@@ -738,18 +741,19 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface
738
741
->fromDbType ($ dbType , ['dimension ' => $ info ['dimension ' ]]);
739
742
}
740
743
744
+ /** @psalm-suppress DeprecatedMethod */
741
745
$ column ->name ($ info ['column_name ' ]);
742
746
$ column ->dbType ($ dbType );
743
- $ column ->allowNull ( $ info ['is_nullable ' ]);
747
+ $ column ->notNull (! $ info ['is_nullable ' ]);
744
748
$ column ->autoIncrement ($ info ['is_autoinc ' ]);
745
749
$ column ->comment ($ info ['column_comment ' ]);
746
750
$ column ->enumValues ($ info ['enum_values ' ] !== null
747
751
? explode (', ' , str_replace (["'' " ], ["' " ], $ info ['enum_values ' ]))
748
752
: null );
749
- $ column ->primaryKey (( bool ) $ info ['is_pkey ' ] );
750
- $ column ->precision ($ info ['numeric_precision ' ] );
751
- $ column ->scale ($ info ['numeric_scale ' ]);
752
- $ column ->size ($ info ['size ' ] === null ? null : ( int ) $ info [ ' size ' ] );
753
+ $ column ->primaryKey ($ info ['contype ' ] === ' p ' );
754
+ $ column ->unique ($ info ['contype ' ] === ' u ' );
755
+ $ column ->scale ($ info ['scale ' ]);
756
+ $ column ->size ($ info ['size ' ]);
753
757
754
758
/**
755
759
* pg_get_serial_sequence() doesn't track DEFAULT value change.
@@ -771,9 +775,8 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface
771
775
$ arrayColumn = $ column ->getColumn ();
772
776
$ arrayColumn ->dbType ($ dbType );
773
777
$ arrayColumn ->enumValues ($ column ->getEnumValues ());
774
- $ arrayColumn ->precision ($ info ['numeric_precision ' ]);
775
- $ arrayColumn ->scale ($ info ['numeric_scale ' ]);
776
- $ arrayColumn ->size ($ info ['size ' ] === null ? null : (int ) $ info ['size ' ]);
778
+ $ arrayColumn ->scale ($ info ['scale ' ]);
779
+ $ arrayColumn ->size ($ info ['size ' ]);
777
780
}
778
781
779
782
$ column ->defaultValue ($ this ->normalizeDefaultValue ($ defaultValue , $ column ));
0 commit comments