File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
src/Illuminate/Database/Schema Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -16,12 +16,25 @@ class PostgresBuilder extends Builder
16
16
public function dropAllTables ()
17
17
{
18
18
$ tables = [];
19
+ $ hypertables = [];
19
20
20
21
$ excludedTables = $ this ->connection ->getConfig ('dont_drop ' ) ?? ['spatial_ref_sys ' ];
22
+ $ hasTimescaleDB = !empty ($ this ->connection ->select ("SELECT 1 FROM pg_extension WHERE extname = 'timescaledb' " ));
23
+
24
+ if ($ hasTimescaleDB ) {
25
+ $ hypertables = $ this ->connection ->select (
26
+ "SELECT hypertable_schema || '.' || hypertable_name as name FROM timescaledb_information.hypertables "
27
+ );
28
+ $ hypertables = array_column ($ hypertables , 'name ' );
29
+ }
21
30
22
31
foreach ($ this ->getTables ($ this ->getCurrentSchemaListing ()) as $ table ) {
23
- if (empty (array_intersect ([$ table ['name ' ], $ table ['schema_qualified_name ' ]], $ excludedTables ))) {
24
- $ tables [] = $ table ['schema_qualified_name ' ];
32
+ if (!in_array ($ table ['name ' ], $ excludedTables ) && !in_array ($ table ['schema_qualified_name ' ], $ excludedTables )) {
33
+ if (in_array ($ table ['schema_qualified_name ' ], $ hypertables )) {
34
+ $ this ->connection ->statement ("DROP TABLE IF EXISTS {$ table ['schema_qualified_name ' ]} CASCADE " );
35
+ } else {
36
+ $ tables [] = $ table ['schema_qualified_name ' ];
37
+ }
25
38
}
26
39
}
27
40
You can’t perform that action at this time.
0 commit comments