[ADD] cli: db manager
Currently dbs can only be managed via the UI in order to take filestores in account: while it's possible to load/copy/rename/drop databases via `psql`, that will not manage the related filestores so the result of the operation is incomplete DBs and leftover filestores littering the disk. Seems like a good idea to add a CLI to perform the same tasks. Currently the CLI calls into the corresponding service, rather than both calling into (possibly better designed) unified APIs, but that seems fine for an initial version. The top-level `db` command acts as a db manager, with git-style sub-sub-commands for the various operations: - `load` to load a dump file into a database (with a specified name or not) - `dump` to dump a local db to a zip dump (pg_dump can be created via the corresponding command so not a concern) - `duplicate` and `rename` - `drop` in order to drop both the database itself and the corresponding filestore Notably, `create` is currently left out because a database can trivially be created by invoking odoo using a dbname which doesn't exist, so doesn't seem useful. `list` is also left out, because `psql -l` generally does the job. closes odoo/odoo#97365 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
+5
-10
@@ -8,16 +8,11 @@ import odoo
|
||||
from odoo.modules import get_modules, get_module_path, initialize_sys_path
|
||||
|
||||
commands = {}
|
||||
|
||||
class CommandType(type):
|
||||
def __init__(cls, name, bases, attrs):
|
||||
super(CommandType, cls).__init__(name, bases, attrs)
|
||||
name = getattr(cls, name, cls.__name__.lower())
|
||||
cls.name = name
|
||||
if name != 'command':
|
||||
commands[name] = cls
|
||||
|
||||
Command = CommandType('Command', (object,), {'run': lambda self, args: None})
|
||||
class Command:
|
||||
name = None
|
||||
def __init_subclass__(cls):
|
||||
cls.name = cls.name or cls.__name__.lower()
|
||||
commands[cls.name] = cls
|
||||
|
||||
class Help(Command):
|
||||
"""Display the list of available commands"""
|
||||
|
||||
Reference in New Issue
Block a user