Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- Bug #456: Fix typecasting bit columns' values with big size (@Tigrov)
- Chg #460: Throw exception on "unsigned" column usage (@vjik)
- New #307: Add range and multirange columns support (@vjik, @Gerych1984)
- Enh #464: Load column's check expressions for table schema (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
12 changes: 12 additions & 0 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Implements the PostgreSQL Server specific schema, supporting PostgreSQL Server version 9.6 and above.
*
* @psalm-type ColumnArray = array{
* check: string|null,
* column_name: string,
* data_type: string,
* type_type: string|null,
Expand Down Expand Up @@ -311,6 +312,7 @@ protected function findColumns(TableSchemaInterface $table): bool
a.atttypmod
) AS scale,
ct.contype,
pg_get_constraintdef(chk.oid) AS "check",
COALESCE(NULLIF(a.attndims, 0), NULLIF(t.typndims, 0), (t.typcategory='A')::int) AS dimension,
co.collname AS collation,
nco.nspname AS collation_schema
Expand All @@ -333,6 +335,15 @@ protected function findColumns(TableSchemaInterface $table): bool
|| ct.conrelid || ' :resorigcol (?:'
|| replace(substr(ct.conkey::text, 2, length(ct.conkey::text) - 2), ',', '|') || ') .*')
)
LEFT JOIN pg_constraint chk ON (chk.contype = 'c' AND cardinality(chk.conkey) = 1)
AND (
chk.conrelid = c.oid AND a.attnum = ANY (chk.conkey)
OR rw.ev_action IS NOT NULL AND chk.conrelid != 0
AND strpos(rw.ev_action, ':resorigtbl ' || chk.conrelid || ' ') > 0
AND rw.ev_action ~ ('.* :resno ' || a.attnum || ' :resname \S+ :ressortgroupref \d+ :resorigtbl '
|| chk.conrelid || ' :resorigcol (?:'
|| replace(substr(chk.conkey::text, 2, length(chk.conkey::text) - 2), ',', '|') || ') .*')
)
LEFT JOIN (pg_collation co JOIN pg_namespace nco ON co.collnamespace = nco.oid)
ON a.attcollation = co.oid AND (nco.nspname != 'pg_catalog' OR co.collname != 'default')
WHERE
Expand Down Expand Up @@ -510,6 +521,7 @@ private function loadColumn(array $info): ColumnInterface

$columnInfo = [
'autoIncrement' => (bool) $info['is_autoinc'],
'check' => !empty($info['check']) ? substr($info['check'], 8, -2) : null,
'collation' => $collation,
'comment' => $info['column_comment'],
'dbType' => $dbType,
Expand Down
1 change: 1 addition & 0 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public static function columns(): array
scale: 0,
),
'C_check' => new StringColumn(
check: '("C_check")::text <> \'\'::text',
dbType: 'varchar',
size: 255,
),
Expand Down