Can't drop db with redbot-setup delete #3699

Closed
opened 2020-03-27 13:45:53 +01:00 by Jackenmen · 2 comments
Jackenmen commented 2020-03-27 13:45:53 +01:00 (Migrated from github.com)

Other bugs

There are two problems here:
a) options 1 and 2 are doing the opposite of what they're supposed to (easy fix so I'm just including it in same issue):

Please choose from one of the following options:
 1. Drop the entire PostgreSQL database for this instance, or
 2. Delete all of Red's data within this database, without dropping the database itself.

b) There's a PostgresSyntaxError in drop database query (SQL function arguments can only be used as data values, not as identifiers):

Traceback (most recent call last):
  File "C:\Python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\red\redbot\setup.py", line 700, in <module>
    run_cli()
  File "C:\red\redbot\setup.py", line 692, in run_cli
    cli()  # pylint: disable=no-value-for-parameter  # click
  File "C:\red\.venv\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "C:\red\.venv\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "C:\red\.venv\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\red\.venv\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\red\.venv\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\red\redbot\setup.py", line 632, in delete
    asyncio.run(
  File "C:\Python38\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\Python38\lib\asyncio\base_events.py", line 612, in run_until_complete
    return future.result()
  File "C:\red\redbot\setup.py", line 267, in remove_instance
    await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
  File "C:\red\redbot\core\drivers\postgres\postgres.py", line 243, in delete_all_data
    await cls._pool.execute(f"DROP DATABASE $1", storage_details["database"])
  File "C:\red\.venv\lib\site-packages\asyncpg\pool.py", line 518, in execute
    return await con.execute(query, *args, timeout=timeout)
  File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 274, in execute
    _, status, _ = await self._execute(query, args, 0, timeout, True)
  File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 1402, in _execute
    result, _ = await self.__execute(
  File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 1411, in __execute
    return await self._do_execute(query, executor, timeout)
  File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 1423, in _do_execute
    stmt = await self._get_statement(query, None)
  File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 328, in _get_statement
    statement = await self._protocol.prepare(stmt_name, query, timeout)
  File "asyncpg\protocol\protocol.pyx", line 163, in prepare
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "$1"
# Other bugs There are two problems here: a) options 1 and 2 are doing the opposite of what they're supposed to (easy fix so I'm just including it in same issue): ``` Please choose from one of the following options: 1. Drop the entire PostgreSQL database for this instance, or 2. Delete all of Red's data within this database, without dropping the database itself. ``` b) There's a PostgresSyntaxError in drop database query (SQL function arguments can only be used as data values, not as identifiers): ``` Traceback (most recent call last): File "C:\Python38\lib\runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Python38\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\red\redbot\setup.py", line 700, in <module> run_cli() File "C:\red\redbot\setup.py", line 692, in run_cli cli() # pylint: disable=no-value-for-parameter # click File "C:\red\.venv\lib\site-packages\click\core.py", line 764, in __call__ return self.main(*args, **kwargs) File "C:\red\.venv\lib\site-packages\click\core.py", line 717, in main rv = self.invoke(ctx) File "C:\red\.venv\lib\site-packages\click\core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\red\.venv\lib\site-packages\click\core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\red\.venv\lib\site-packages\click\core.py", line 555, in invoke return callback(*args, **kwargs) File "C:\red\redbot\setup.py", line 632, in delete asyncio.run( File "C:\Python38\lib\asyncio\runners.py", line 43, in run return loop.run_until_complete(main) File "C:\Python38\lib\asyncio\base_events.py", line 612, in run_until_complete return future.result() File "C:\red\redbot\setup.py", line 267, in remove_instance await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db) File "C:\red\redbot\core\drivers\postgres\postgres.py", line 243, in delete_all_data await cls._pool.execute(f"DROP DATABASE $1", storage_details["database"]) File "C:\red\.venv\lib\site-packages\asyncpg\pool.py", line 518, in execute return await con.execute(query, *args, timeout=timeout) File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 274, in execute _, status, _ = await self._execute(query, args, 0, timeout, True) File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 1402, in _execute result, _ = await self.__execute( File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 1411, in __execute return await self._do_execute(query, executor, timeout) File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 1423, in _do_execute stmt = await self._get_statement(query, None) File "C:\red\.venv\lib\site-packages\asyncpg\connection.py", line 328, in _get_statement statement = await self._protocol.prepare(stmt_name, query, timeout) File "asyncpg\protocol\protocol.pyx", line 163, in prepare asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "$1" ```
Jackenmen commented 2020-03-31 19:47:16 +02:00 (Migrated from github.com)

PostgreSQL needs to be connected to a database to drop another database (the database to drop can't have any active connections) and we can't know for sure what's the maintenance db for given PostgreSQL server. We can either remove option to drop whole database or try names that were most likely used for maintenance database (postgres or template1) and only clear schemas if we can't find the maintenance database.

PostgreSQL needs to be connected to a database to drop another database (the database to drop can't have any active connections) and we can't know for sure what's the maintenance db for given PostgreSQL server. We can either remove option to drop whole database or try names that were most likely used for maintenance database (`postgres` or `template1`) and only clear schemas if we can't find the maintenance database.
Tobotimus commented 2020-05-07 13:01:11 +02:00 (Migrated from github.com)

I think just remove the option to drop the database - I put the option in there without reading the fine-print!

I think just remove the option to drop the database - I put the option in there without reading the fine-print!
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#3699
No description provided.