Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
DBDiff/tests/RoutineOverloadPostgresTest.php at master · DBDiff/DBDiff · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
DBDiff
DBDiff
Repository navigation
Code
Issues
3
(3)
Pull requests
Actions
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
DBDiff
/
tests
/
RoutineOverloadPostgresTest.php
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
157 lines (141 loc) · 6.05 KB
master
Breadcrumbs
DBDiff
/
tests
/
RoutineOverloadPostgresTest.php
Copy path
Top
File metadata and controls
Code
Blame
157 lines (141 loc) · 6.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
use
DBDiff
\
DB
\
Adapters
\
PostgresAdapter
;
use
Illuminate
\
Database
\
Capsule
\
Manager
as
Capsule
;
use
Illuminate
\
Database
\
Events
\
StatementPrepared
;
use
Illuminate
\
Events
\
Dispatcher
;
use
PHPUnit
\
Framework
\
TestCase
;
/**
* Live-server regression tests for issue #187.
*
* getRoutines() keyed its map on proname, so overloaded functions overwrote
* each other: N-1 overloads were invisible to the diff, and which one survived
* depended on row order — which differs between databases. Two identical
* schemas reported drift, and the migration dropped every overload.
*
* The same applied to triggers, whose names are unique per table, not per
* schema.
*
* Skips automatically without pdo_pgsql or DB_HOST_POSTGRES.
*/
class
RoutineOverloadPostgresTest
extends
TestCase
{
private
string
$
db
=
'
dbdiff_overloads
'
;
private
?
PDO
$
adminDb
=
null
;
private
$
capsule
;
private
$
connection
;
private
PostgresAdapter
$
adapter
;
protected
function
setUp
():
void
{
if
(!
extension_loaded
(
'
pdo_pgsql
'
)) {
$
this
->
markTestSkipped
(
'
pdo_pgsql extension not loaded.
'
);
}
$
host
=
getenv
(
'
DB_HOST_POSTGRES
'
) ?:
null
;
if
(!
$
host
) {
$
this
->
markTestSkipped
(
'
DB_HOST_POSTGRES env var not set.
'
);
}
$
this
->
adminDb
=
new
PDO
(
"
pgsql:host=
$
host
;port=5432;dbname=diff1
"
,
'
dbdiff
'
,
'
rootpass
'
,
[
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
]
);
$
this
->
dropScratchDb
();
$
this
->
adminDb
->
exec
(
"
CREATE DATABASE
{
$
this
->
db
}"
);
$
capsule
=
new
Capsule
;
$
dispatcher
=
new
Dispatcher
();
$
dispatcher
->
listen
(StatementPrepared::class,
function
(
$
event
) {
$
event
->
statement
->
setFetchMode
(
PDO
::
FETCH_ASSOC
);
});
$
capsule
->
setEventDispatcher
(
$
dispatcher
);
$
capsule
->
addConnection
([
'
driver
'
=>
'
pgsql
'
,
'
host
'
=>
$
host
,
'
port
'
=>
5432
,
'
database
'
=>
$
this
->
db
,
'
username
'
=>
'
dbdiff
'
,
'
password
'
=>
'
rootpass
'
,
'
charset
'
=>
'
utf8
'
,
'
schema
'
=>
'
public
'
,
],
'
ovl
'
);
$
this
->
capsule
=
$
capsule
;
$
this
->
connection
=
$
capsule
->
getConnection
(
'
ovl
'
);
$
this
->
adapter
=
new
PostgresAdapter
();
$
this
->
connection
->
unprepared
(<<<'SQL'
CREATE FUNCTION cosine_distance(a int, b int) RETURNS int LANGUAGE sql AS $$ SELECT 1 $$;
CREATE FUNCTION cosine_distance(a text, b text) RETURNS text LANGUAGE sql AS $$ SELECT 'x' $$;
CREATE FUNCTION cosine_distance(a bigint, b bigint) RETURNS bigint LANGUAGE sql AS $$ SELECT 2::bigint $$;
CREATE FUNCTION solo() RETURNS int LANGUAGE sql AS $$ SELECT 7 $$;
CREATE TABLE t1 (id int);
CREATE TABLE t2 (id int);
CREATE FUNCTION trig_fn() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RETURN NEW; END $$;
CREATE TRIGGER shared_trig BEFORE INSERT ON t1 FOR EACH ROW EXECUTE FUNCTION trig_fn();
CREATE TRIGGER shared_trig BEFORE INSERT ON t2 FOR EACH ROW EXECUTE FUNCTION trig_fn();
SQL);
}
protected
function
tearDown
():
void
{
if
(
$
this
->
adminDb
===
null
) {
return
;
}
if
(
$
this
->
connection
!==
null
) {
$
this
->
connection
->
disconnect
();
$
this
->
connection
=
null
;
}
$
this
->
capsule
=
null
;
$
this
->
dropScratchDb
();
$
this
->
adminDb
=
null
;
}
private
function
dropScratchDb
():
void
{
try
{
$
this
->
adminDb
->
exec
(
"
DROP DATABASE IF EXISTS
{
$
this
->
db
}
WITH (FORCE)
"
);
}
catch
(
PDOException
$
e
) {
$
this
->
adminDb
->
exec
(
"
DROP DATABASE IF EXISTS
{
$
this
->
db
}"
);
}
}
public
function
testEveryOverloadIsRetained
():
void
{
// Keyed on proname, three overloads collapsed to one entry.
$
routines
=
$
this
->
adapter
->
getRoutines
(
$
this
->
connection
);
$
overloads
=
array_filter
(
array_keys
(
$
routines
),
fn
(
$
k
) =>
str_starts_with
(
$
k
,
'
cosine_distance
'
)
);
$
this
->
assertCount
(
3
,
$
overloads
);
}
public
function
testKeysAreSignaturesNotBareNames
():
void
{
$
routines
=
$
this
->
adapter
->
getRoutines
(
$
this
->
connection
);
$
this
->
assertArrayHasKey
(
'
cosine_distance(integer,integer)
'
,
$
routines
);
$
this
->
assertArrayHasKey
(
'
cosine_distance(text,text)
'
,
$
routines
);
$
this
->
assertArrayHasKey
(
'
cosine_distance(bigint,bigint)
'
,
$
routines
);
$
this
->
assertArrayNotHasKey
(
'
cosine_distance
'
,
$
routines
);
}
public
function
testEachOverloadKeepsItsOwnDefinition
():
void
{
$
routines
=
$
this
->
adapter
->
getRoutines
(
$
this
->
connection
);
$
this
->
assertStringContainsString
(
'
bigint
'
,
$
routines
[
'
cosine_distance(bigint,bigint)
'
]);
$
this
->
assertStringContainsString
(
'
text
'
,
$
routines
[
'
cosine_distance(text,text)
'
]);
}
public
function
testNonOverloadedRoutineStillAppears
():
void
{
$
routines
=
$
this
->
adapter
->
getRoutines
(
$
this
->
connection
);
$
this
->
assertArrayHasKey
(
'
solo()
'
,
$
routines
);
}
public
function
testRoutineOrderIsDeterministic
():
void
{
// ORDER BY proname left overload ties unordered, which is what made the
// surviving definition differ between databases.
$
first
=
array_keys
(
$
this
->
adapter
->
getRoutines
(
$
this
->
connection
));
$
second
=
array_keys
(
$
this
->
adapter
->
getRoutines
(
$
this
->
connection
));
$
this
->
assertSame
(
$
first
,
$
second
);
$
sorted
=
$
first
;
sort
(
$
sorted
);
$
this
->
assertSame
(
$
sorted
,
$
first
);
}
public
function
testSameNamedTriggersOnDifferentTablesAreBothKept
():
void
{
// tgname is unique per table, not per schema — keyed on the name alone,
// one of these was silently lost.
$
triggers
=
$
this
->
adapter
->
getTriggers
(
$
this
->
connection
);
$
this
->
assertArrayHasKey
(
'
t1.shared_trig
'
,
$
triggers
);
$
this
->
assertArrayHasKey
(
'
t2.shared_trig
'
,
$
triggers
);
$
this
->
assertSame
(
'
shared_trig
'
,
$
triggers
[
'
t1.shared_trig
'
][
'
name
'
]);
$
this
->
assertSame
(
'
t2
'
,
$
triggers
[
'
t2.shared_trig
'
][
'
table
'
]);
}
}
You can’t perform that action at this time.