#NEWLINE# def clear( self ) : #NEWLINE# #INDENT# 'Drop tables and other objects' #NEWLINE# STD_DROP = 'DROP %s IF EXISTS "%s" CASCADE' #NEWLINE# curs = pgexecute ( self . conn , "SELECT nspname FROM pg_namespace\n               WHERE nspname NOT IN ('public', 'information_schema')\n                     AND substring(nspname for 3) != 'pg_'\n               ORDER BY nspname" ) #NEWLINE# objs = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for obj in objs : #NEWLINE# #INDENT# self . execute ( ( STD_DROP % ( 'SCHEMA' , obj [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# if ( self . version >= 90100 ) : #NEWLINE# #INDENT# curs = pgexecute ( self . conn , "SELECT extname FROM pg_extension\n                          JOIN pg_namespace n ON (extnamespace = n.oid)\n                   WHERE nspname NOT IN ('information_schema')\n                     AND extname != 'plpgsql'" ) #NEWLINE# exts = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for ext in exts : #NEWLINE# #INDENT# self . execute ( ( STD_DROP % ( 'EXTENSION' , ext [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# #UNINDENT# curs = pgexecute ( self . conn , "SELECT relname, relkind FROM pg_class\n                      JOIN pg_namespace ON (relnamespace = pg_namespace.oid)\n               WHERE relkind in ('r', 'S', 'v', 'f', 'm')\n                     AND nspname NOT IN ('pg_catalog', 'information_schema')\n               ORDER BY relkind DESC" ) #NEWLINE# objs = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for obj in objs : #NEWLINE# #INDENT# if ( obj [ 'relkind' ] == 'r' ) : #NEWLINE# #INDENT# objtype = 'TABLE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( obj [ 'relkind' ] == 'S' ) : #NEWLINE# #INDENT# objtype = 'SEQUENCE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( obj [ 'relkind' ] == 'v' ) : #NEWLINE# #INDENT# objtype = 'VIEW' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( obj [ 'relkind' ] == 'f' ) : #NEWLINE# #INDENT# objtype = 'FOREIGN TABLE' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( obj [ 'relkind' ] == 'm' ) : #NEWLINE# #INDENT# objtype = 'MATERIALIZED VIEW' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . execute ( ( STD_DROP % ( objtype , obj [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# curs = pgexecute ( self . conn , "SELECT typname, typtype FROM pg_type t\n                      JOIN pg_namespace n ON (typnamespace = n.oid)\n               WHERE typtype IN ('b', 'c', 'd', 'e')\n                 AND NOT (typtype = 'b' AND typarray = 0)\n                 AND nspname NOT IN ('pg_catalog', 'pg_toast',\n                     'information_schema')" ) #NEWLINE# types = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for typ in types : #NEWLINE# #INDENT# self . execute ( ( STD_DROP % ( ( 'DOMAIN' if ( typ [ 'typtype' ] == 'd' ) else 'TYPE' ) , typ [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# curs = pgexecute ( self . conn , "SELECT proisagg, p.oid::regprocedure AS proc\n               FROM pg_proc p JOIN pg_namespace n ON (pronamespace = n.oid)\n               WHERE nspname NOT IN ('pg_catalog', 'information_schema')\n               ORDER BY 1, 2" ) #NEWLINE# funcs = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for func in funcs : #NEWLINE# #INDENT# self . execute ( ( 'DROP %s IF EXISTS %s CASCADE' % ( ( 'AGGREGATE' if func [ 'proisagg' ] else 'FUNCTION' ) , func [ 'proc' ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# if ( self . version < 90000 ) : #NEWLINE# #INDENT# if self . is_plpgsql_installed ( ) : #NEWLINE# #INDENT# self . execute_commit ( 'DROP LANGUAGE plpgsql' ) #NEWLINE# #UNINDENT# #UNINDENT# curs = pgexecute ( self . conn , "SELECT o.oid::regoperator\n               FROM pg_operator o JOIN pg_namespace n ON (oprnamespace = n.oid)\n               WHERE nspname NOT IN ('pg_catalog', 'information_schema')" ) #NEWLINE# opers = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for oper in opers : #NEWLINE# #INDENT# self . execute ( ( 'DROP OPERATOR IF EXISTS %s CASCADE' % oper [ 0 ] ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# curs = pgexecute ( self . conn , "SELECT opfname, amname\n               FROM pg_opfamily o JOIN pg_am a ON (opfmethod = a.oid)\n                    JOIN pg_namespace n ON (opfnamespace = n.oid)\n               WHERE nspname NOT IN ('pg_catalog', 'information_schema')" ) #NEWLINE# opfams = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for opfam in opfams : #NEWLINE# #INDENT# self . execute ( ( 'DROP OPERATOR FAMILY IF EXISTS "%s" USING "%s" CASCADE' % ( opfam [ 0 ] , opfam [ 1 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# curs = pgexecute ( self . conn , "SELECT opcname, amname\n               FROM pg_opclass o JOIN pg_am a ON (opcmethod = a.oid)\n                    JOIN pg_namespace n ON (opcnamespace = n.oid)\n               WHERE nspname NOT IN ('pg_catalog', 'information_schema')" ) #NEWLINE# opcls = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for opcl in opcls : #NEWLINE# #INDENT# self . execute ( ( 'DROP OPERATOR CLASS IF EXISTS "%s" USING "%s" CASCADE' % ( opcl [ 0 ] , opcl [ 1 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# curs = pgexecute ( self . conn , "SELECT conname FROM pg_conversion c\n                      JOIN pg_namespace n ON (connamespace = n.oid)\n               WHERE nspname NOT IN ('pg_catalog', 'information_schema')" ) #NEWLINE# convs = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for cnv in convs : #NEWLINE# #INDENT# self . execute ( ( STD_DROP % ( 'CONVERSION' , opers [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# if ( self . version >= 90100 ) : #NEWLINE# #INDENT# curs = pgexecute ( self . conn , "SELECT collname FROM pg_collation c\n                          JOIN pg_namespace n ON (collnamespace = n.oid)\n                   WHERE nspname NOT IN (\n                         'pg_catalog', 'information_schema')" ) #NEWLINE# colls = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for coll in colls : #NEWLINE# #INDENT# self . execute ( ( STD_DROP % ( 'COLLATION' , coll [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# #UNINDENT# curs = pgexecute ( self . conn , "SELECT CASE umuser WHEN 0 THEN 'PUBLIC' ELSE\n                  pg_get_userbyid(umuser) END AS username, s.srvname\n               FROM pg_user_mappings u\n                  JOIN pg_foreign_server s ON (srvid = s.oid)" ) #NEWLINE# umaps = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for ump in umaps : #NEWLINE# #INDENT# self . execute ( ( 'DROP USER MAPPING IF EXISTS FOR "%s" SERVER "%s"' % ( ump [ 0 ] , ump [ 1 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# curs = pgexecute ( self . conn , 'SELECT srvname FROM pg_foreign_server' ) #NEWLINE# servs = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for srv in servs : #NEWLINE# #INDENT# self . execute ( ( STD_DROP % ( 'SERVER' , srv [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( ) #NEWLINE# curs = pgexecute ( self . conn , 'SELECT fdwname FROM pg_foreign_data_wrapper' ) #NEWLINE# fdws = curs . fetchall ( ) #NEWLINE# curs . close ( ) #NEWLINE# self . conn . rollback ( ) #NEWLINE# for fdw in fdws : #NEWLINE# #INDENT# self . execute ( ( STD_DROP % ( 'FOREIGN DATA WRAPPER' , fdw [ 0 ] ) ) ) #NEWLINE# #UNINDENT# self . conn . commit ( )