Give a more useful error message if attempting to drop an object that doesn't exist. Fixes #1154
parent
d3d96d5c05
commit
166d42953c
|
@ -599,6 +599,9 @@ class DatabaseView(PGChildNodeView):
|
|||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified database could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
|
|
@ -454,6 +454,17 @@ class CastView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified cast object could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop cast
|
||||
result = res['rows'][0]
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']),
|
||||
|
|
|
@ -452,6 +452,17 @@ class EventTriggerView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=name)
|
||||
|
||||
if name is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified event trigger could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']), name=name, cascade=cascade)
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
|
|
|
@ -310,6 +310,18 @@ class ExtensionView(PGChildNodeView):
|
|||
status, name = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=name)
|
||||
|
||||
if name is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified extension could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop extension
|
||||
SQL = render_template("/".join(
|
||||
[self.template_path, 'delete.sql']
|
||||
|
|
|
@ -478,6 +478,17 @@ class ForeignDataWrapperView(PGChildNodeView):
|
|||
status, name = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=name)
|
||||
|
||||
if name is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified foreign data wrapper could not be found.\n'
|
||||
)
|
||||
)
|
||||
# drop foreign data wrapper node
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']), name=name, cascade=cascade,
|
||||
conn=self.conn)
|
||||
|
|
|
@ -488,6 +488,18 @@ class ForeignServerView(PGChildNodeView):
|
|||
status, name = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=name)
|
||||
|
||||
if name is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified foreign server could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop foreign server
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']), name=name, cascade=cascade,
|
||||
conn=self.conn)
|
||||
|
|
|
@ -499,11 +499,30 @@ class UserMappingView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=name)
|
||||
|
||||
if name is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified foreign server could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
sql = render_template("/".join([self.template_path, 'properties.sql']), umid=umid, conn=self.conn)
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'The specified user mapping could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = res['rows'][0]
|
||||
|
||||
# drop user mapping
|
||||
|
|
|
@ -616,6 +616,18 @@ It may have been removed by another user.
|
|||
status, name = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=name)
|
||||
|
||||
if name is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified schema could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop schema
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'sql/delete.sql']),
|
||||
|
|
|
@ -457,6 +457,17 @@ class CollationView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=name)
|
||||
|
||||
if name is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified collation could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'delete.sql']),
|
||||
name=name, cascade=cascade,
|
||||
|
|
|
@ -567,6 +567,17 @@ AND relkind != 'c'))"""
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified domain could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
name, basensp = res['rows'][0]
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
|
|
@ -441,6 +441,17 @@ class DomainConstraintView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified domain constraint could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = res['rows'][0]
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
|
|
@ -707,6 +707,17 @@ AND relkind != 'c'))"""
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified foreign table could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
name, basensp = res['rows'][0]
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
|
|
@ -567,10 +567,16 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(_("""
|
||||
Could not find the FTS Configuration node to delete.
|
||||
"""))
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified FTS configuration could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# Drop FTS Configuration
|
||||
result = res['rows'][0]
|
||||
|
|
|
@ -553,10 +553,16 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(_("""
|
||||
Could not find the FTS Dictionary node to delete.
|
||||
"""))
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified FTS dictionary could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# Drop FTS Dictionary
|
||||
result = res['rows'][0]
|
||||
|
|
|
@ -487,8 +487,16 @@ class FtsParserView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(_("Could not find the FTS Parser node."))
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified FTS parser could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# Drop fts Parser
|
||||
result = res['rows'][0]
|
||||
|
|
|
@ -449,6 +449,17 @@ class FtsTemplateView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified FTS template could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# Drop fts template
|
||||
result = res['rows'][0]
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']),
|
||||
|
|
|
@ -788,6 +788,17 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified function could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
name, func_args, nspname = res['rows'][0]
|
||||
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
|
|
|
@ -383,6 +383,17 @@ class SequenceView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified sequence could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
SQL = render_template("/".join([self.template_path, 'delete.sql']), data=res['rows'][0], cascade=cascade)
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
|
|
|
@ -1500,6 +1500,18 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
|
|||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified table could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = res['rows'][0]
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
|
|
@ -594,6 +594,17 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified column could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = dict(res['rows'][0])
|
||||
# We will add table & schema as well
|
||||
data['schema'] = self.schema
|
||||
|
|
|
@ -508,6 +508,17 @@ class CheckConstraintView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified check constraint could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = res['rows'][0]
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
|
|
@ -621,6 +621,17 @@ class ExclusionConstraintView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified exclusion constraint could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = res['rows'][0]
|
||||
data['schema'] = self.schema
|
||||
data['table'] = self.table
|
||||
|
|
|
@ -683,6 +683,17 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified foreign key could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = res['rows'][0]
|
||||
data['schema'] = self.schema
|
||||
data['table'] = self.table
|
||||
|
|
|
@ -643,6 +643,17 @@ class IndexConstraintView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=_(
|
||||
'The specified constraint could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = res['rows'][0]
|
||||
data['schema'] = self.schema
|
||||
data['table'] = self.table
|
||||
|
|
|
@ -638,6 +638,17 @@ class IndexesView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified index could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = dict(res['rows'][0])
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
|
|
@ -377,6 +377,18 @@ class RuleView(PGChildNodeView):
|
|||
status, res_data = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res_data)
|
||||
|
||||
if not res_data['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified rule could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop rule
|
||||
rset = res_data['rows'][0]
|
||||
SQL = render_template("/".join(
|
||||
|
|
|
@ -623,6 +623,17 @@ class TriggerView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified trigger could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
data = dict(res['rows'][0])
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
|
|
@ -965,6 +965,17 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
if not res['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified type could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# Making copy of output for future use
|
||||
data = dict(res['rows'][0])
|
||||
|
||||
|
|
|
@ -575,6 +575,17 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res_data)
|
||||
|
||||
if not res_data['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified view could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop view
|
||||
SQL = render_template(
|
||||
"/".join([
|
||||
|
|
|
@ -430,6 +430,18 @@ class ResourceGroupView(NodeView):
|
|||
status, rgname = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rgname)
|
||||
|
||||
if rgname is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified resource group could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop resource group
|
||||
sql = render_template("/".join([self.template_path, 'delete.sql']), rgname=rgname, conn=self.conn)
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
|
|
|
@ -368,9 +368,15 @@ class TablespaceView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
if len(rset['rows']) != 1:
|
||||
return gone(
|
||||
errormsg=gettext("Could not find the tablespace on the server.")
|
||||
if not rset['rows']:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'Error: Object not found.'
|
||||
),
|
||||
info=gettext(
|
||||
'The specified tablespace could not be found.\n'
|
||||
)
|
||||
)
|
||||
|
||||
# drop tablespace
|
||||
|
|
Loading…
Reference in New Issue