RB 3.3 and R:nuke() on a Postgis database

27 views
Skip to first unread message

Marco Afonso

unread,
Nov 5, 2015, 5:57:45 AM11/5/15
to redbeanphp

Hi,

This is what happens when I nuke a postgis database:

SET CONSTRAINTS ALL DEFERRED
Array ( ) 
select table_name from information_schema.tables where table_schema = 'public'
Array ( ) 
resultset: 5 rows
drop table if exists "geography_columns" CASCADE 
Array ( ) 
An error occurred: SQLSTATE[42809]: Wrong object type: 7 ERROR: "geography_columns" is not a table HINT: Use DROP VIEW to remove a view.
drop view if exists "geography_columns" CASCADE 
Array ( ) 
An error occurred: SQLSTATE[2BP01]: Dependent objects still exist: 7 ERROR: cannot drop view geography_columns because extension postgis requires it HINT: You can drop extension postgis instead.

Is this the supposed behavior?

Thanks!

gabor

unread,
Nov 5, 2015, 3:34:54 PM11/5/15
to redbeanphp

Hi,

I have tested this and I got the same error. However, nuke() will remove regular views just like tables, no problem.
The issue here is that 'geography_columns' seems to be some sort of special view.

The easiest way around this issue is to wrap a try{}catch{} around the 'drop' function.

cheers
Gabor

Marco Afonso

unread,
Nov 5, 2015, 4:53:12 PM11/5/15
to redbeanphp

Thanks Gabor,

I use nuke in the scenario where I need to reinstall the application tables... Any ideas about this if nuke fails?

Thanks

gabor

unread,
Nov 5, 2015, 5:02:05 PM11/5/15
to redbeanphp


Here is a diff patch:

diff --git a/RedBeanPHP/QueryWriter/PostgreSQL.php b/RedBeanPHP/QueryWriter/PostgreSQL.php
index f364fc7
..2b72f95 100755
--- a/RedBeanPHP/QueryWriter/PostgreSQL.php
+++ b/RedBeanPHP/QueryWriter/PostgreSQL.php
@@ -372,8 +372,8 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
 
               
foreach ( $this->getTables() as $t ) {
                        $t
= $this->esc( $t );
-
-                       $this->adapter->exec( "DROP TABLE IF EXISTS $t CASCADE " );
+                       //Some plugins (PostGIS have unremovable tables/views), avoid exceptions.
+                       try { $this->adapter->exec( "DROP TABLE IF EXISTS $t CASCADE " ); }catch( \Exception $e ) {}
               
}
 
                $this
->adapter->exec( 'SET CONSTRAINTS ALL IMMEDIATE' );



It looks like Postgis will install its views upon activating the PostgreSQL plugin, so you should not have to worry about that (at least over here it works like that).

cheers
Gabor

gabor

unread,
Nov 5, 2015, 5:03:04 PM11/5/15
to redbeanphp

Note that this diff patch is for RedBeanPHP 4.3, however the 3.3 code should be similar.

Marco Afonso

unread,
Nov 6, 2015, 10:42:46 AM11/6/15
to redbeanphp
Thanks Gabor, I will try the patch asap.
Reply all
Reply to author
Forward
0 new messages