Skip to content

Commit b2b0c1c

Browse files
authored
Revert "[10.x] Get user-defined types on PostgreSQL (#49303)"
This reverts commit 57ae89a.
1 parent 9fe14c8 commit b2b0c1c

File tree

7 files changed

+8
-156
lines changed

7 files changed

+8
-156
lines changed

src/Illuminate/Database/Query/Processors/PostgresProcessor.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,6 @@ public function processColumnListing($results)
4545
}, $results);
4646
}
4747

48-
/**
49-
* Process the results of a types query.
50-
*
51-
* @param array $results
52-
* @return array
53-
*/
54-
public function processTypes($results)
55-
{
56-
return array_map(function ($result) {
57-
$result = (object) $result;
58-
59-
return [
60-
'name' => $result->name,
61-
'schema' => $result->schema,
62-
'implicit' => (bool) $result->implicit,
63-
'type' => match (strtolower($result->type)) {
64-
'b' => 'base',
65-
'c' => 'composite',
66-
'd' => 'domain',
67-
'e' => 'enum',
68-
'p' => 'pseudo',
69-
'r' => 'range',
70-
'm' => 'multirange',
71-
default => null,
72-
},
73-
'category' => match (strtolower($result->category)) {
74-
'a' => 'array',
75-
'b' => 'boolean',
76-
'c' => 'composite',
77-
'd' => 'date_time',
78-
'e' => 'enum',
79-
'g' => 'geometric',
80-
'i' => 'network_address',
81-
'n' => 'numeric',
82-
'p' => 'pseudo',
83-
'r' => 'range',
84-
's' => 'string',
85-
't' => 'timespan',
86-
'u' => 'user_defined',
87-
'v' => 'bit_string',
88-
'x' => 'unknown',
89-
'z' => 'internal_use',
90-
default => null,
91-
},
92-
];
93-
}, $results);
94-
}
95-
9648
/**
9749
* Process the results of a columns query.
9850
*

src/Illuminate/Database/Query/Processors/Processor.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ public function processViews($results)
7777
}, $results);
7878
}
7979

80-
/**
81-
* Process the results of a types query.
82-
*
83-
* @param array $results
84-
* @return array
85-
*/
86-
public function processTypes($results)
87-
{
88-
return $results;
89-
}
90-
9180
/**
9281
* Process the results of a columns query.
9382
*

src/Illuminate/Database/Schema/Builder.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,6 @@ public function getViews()
211211
);
212212
}
213213

214-
/**
215-
* Get the user-defined types that belong to the database.
216-
*
217-
* @return array
218-
*/
219-
public function getTypes()
220-
{
221-
throw new LogicException('This database driver does not support user-defined types.');
222-
}
223-
224214
/**
225215
* Get all of the table names for the database.
226216
*

src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,6 @@ public function compileViews()
101101
return "select viewname as name, schemaname as schema, definition from pg_views where schemaname not in ('pg_catalog', 'information_schema') order by viewname";
102102
}
103103

104-
/**
105-
* Compile the query to determine the user-defined types.
106-
*
107-
* @return string
108-
*/
109-
public function compileTypes()
110-
{
111-
return 'select t.typname as name, n.nspname as schema, t.typtype as type, t.typcategory as category, '
112-
."((t.typinput = 'array_in'::regproc and t.typoutput = 'array_out'::regproc) or t.typtype = 'm') as implicit "
113-
.'from pg_type t join pg_namespace n on n.oid = t.typnamespace '
114-
.'left join pg_class c on c.oid = t.typrelid '
115-
.'left join pg_type el on el.oid = t.typelem '
116-
.'left join pg_class ce on ce.oid = el.typrelid '
117-
."where ((t.typrelid = 0 and (ce.relkind = 'c' or ce.relkind is null)) or c.relkind = 'c') "
118-
."and n.nspname not in ('pg_catalog', 'information_schema')";
119-
}
120-
121104
/**
122105
* Compile the SQL needed to retrieve all table names.
123106
*
@@ -520,22 +503,9 @@ public function compileDropAllTypes($types)
520503
return 'drop type '.implode(',', $this->escapeNames($types)).' cascade';
521504
}
522505

523-
/**
524-
* Compile the SQL needed to drop all domains.
525-
*
526-
* @param array $domains
527-
* @return string
528-
*/
529-
public function compileDropAllDomains($domains)
530-
{
531-
return 'drop domain '.implode(',', $this->escapeNames($domains)).' cascade';
532-
}
533-
534506
/**
535507
* Compile the SQL needed to retrieve all type names.
536508
*
537-
* @deprecated Will be removed in a future Laravel version.
538-
*
539509
* @return string
540510
*/
541511
public function compileGetAllTypes()

src/Illuminate/Database/Schema/PostgresBuilder.php

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ public function hasTable($table)
5353
)) > 0;
5454
}
5555

56-
/**
57-
* Get the user-defined types that belong to the database.
58-
*
59-
* @return array
60-
*/
61-
public function getTypes()
62-
{
63-
return $this->connection->getPostProcessor()->processTypes(
64-
$this->connection->selectFromWriteConnection($this->grammar->compileTypes())
65-
);
66-
}
67-
6856
/**
6957
* Get all of the table names for the database.
7058
*
@@ -163,8 +151,6 @@ public function dropAllViews()
163151
/**
164152
* Get all of the type names for the database.
165153
*
166-
* @deprecated Will be removed in a future Laravel version.
167-
*
168154
* @return array
169155
*/
170156
public function getAllTypes()
@@ -182,27 +168,20 @@ public function getAllTypes()
182168
public function dropAllTypes()
183169
{
184170
$types = [];
185-
$domains = [];
186171

187-
$schemas = $this->grammar->escapeNames($this->getSchemas());
172+
foreach ($this->getAllTypes() as $row) {
173+
$row = (array) $row;
188174

189-
foreach ($this->getTypes() as $type) {
190-
if (! $type['implicit'] && in_array($this->grammar->escapeNames([$type['schema']])[0], $schemas)) {
191-
if ($type['type'] === 'domain') {
192-
$domains[] = $type['schema'].'.'.$type['name'];
193-
} else {
194-
$types[] = $type['schema'].'.'.$type['name'];
195-
}
196-
}
175+
$types[] = reset($row);
197176
}
198177

199-
if (! empty($types)) {
200-
$this->connection->statement($this->grammar->compileDropAllTypes($types));
178+
if (empty($types)) {
179+
return;
201180
}
202181

203-
if (! empty($domains)) {
204-
$this->connection->statement($this->grammar->compileDropAllDomains($domains));
205-
}
182+
$this->connection->statement(
183+
$this->grammar->compileDropAllTypes($types)
184+
);
206185
}
207186

208187
/**

src/Illuminate/Support/Facades/Schema.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* @method static bool hasView(string $view)
1515
* @method static array getTables()
1616
* @method static array getViews()
17-
* @method static array getTypes()
1817
* @method static bool hasColumn(string $table, string $column)
1918
* @method static bool hasColumns(string $table, array $columns)
2019
* @method static void whenTableHasColumn(string $table, string $column, \Closure $callback)

tests/Integration/Database/SchemaBuilderTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -182,33 +182,6 @@ public function testGetViews()
182182
$this->assertEmpty(array_diff(['foo', 'bar', 'baz'], array_column($views, 'name')));
183183
}
184184

185-
public function testGetAndDropTypes()
186-
{
187-
if ($this->driver !== 'pgsql') {
188-
$this->markTestSkipped('Test requires a PostgreSQL connection.');
189-
}
190-
191-
DB::statement('create type pseudo_foo');
192-
DB::statement('create type comp_foo as (f1 int, f2 text)');
193-
DB::statement("create type enum_foo as enum ('new', 'open', 'closed')");
194-
DB::statement('create type range_foo as range (subtype = float8)');
195-
DB::statement('create domain domain_foo as text');
196-
197-
$types = Schema::getTypes();
198-
199-
$this->assertCount(11, $types);
200-
$this->assertTrue(collect($types)->contains(fn ($type) => $type['name'] === 'pseudo_foo' && $type['type'] === 'pseudo' && ! $type['implicit']));
201-
$this->assertTrue(collect($types)->contains(fn ($type) => $type['name'] === 'comp_foo' && $type['type'] === 'composite' && ! $type['implicit']));
202-
$this->assertTrue(collect($types)->contains(fn ($type) => $type['name'] === 'enum_foo' && $type['type'] === 'enum' && ! $type['implicit']));
203-
$this->assertTrue(collect($types)->contains(fn ($type) => $type['name'] === 'range_foo' && $type['type'] === 'range' && ! $type['implicit']));
204-
$this->assertTrue(collect($types)->contains(fn ($type) => $type['name'] === 'domain_foo' && $type['type'] === 'domain' && ! $type['implicit']));
205-
206-
Schema::dropAllTypes();
207-
$types = Schema::getTypes();
208-
209-
$this->assertEmpty($types);
210-
}
211-
212185
public function testGetIndexes()
213186
{
214187
Schema::create('foo', function (Blueprint $table) {

0 commit comments

Comments
 (0)