let setup command configure the database

This commit is contained in:
Izalia Mae 2022-12-20 07:59:58 -05:00
parent ed25fcab35
commit 261dce50ab
2 changed files with 60 additions and 3 deletions

View file

@ -32,6 +32,7 @@ DEFAULTS = {
CATEGORY_NAMES = [
'general',
'database',
'sqlite',
'postgres',
'mysql'
]
@ -85,6 +86,9 @@ class Config(AppBase, dict):
def __setitem__(self, key, value):
if key in {'database', 'hostname', 'port', 'username', 'password'}:
key = f'{self.dbtype}_{key}'
if (self.is_docker and key in {'general_host', 'general_port'}) or value == '__DEFAULT__':
value = DEFAULTS[key]

View file

@ -45,6 +45,8 @@ def cli(ctx, config):
@cli.command('convert')
@click.option('--old-config', '-o', help='path to the old relay config')
def cli_convert(old_config):
'Convert an old relay.yaml and relay.jsonld to the the new formats'
with open(old_config or 'relay.yaml') as fd:
config = yaml.load(fd.read(), Loader=yaml.SafeLoader)
ap = config.get('ap', {})
@ -106,7 +108,10 @@ def cli_setup():
'Generate a new config'
while True:
app.config['general_host'] = click.prompt('What domain will the relay be hosted on?', default=app.config.host)
app.config['general_host'] = click.prompt(
'What domain will the relay be hosted on?',
default = app.config.host
)
if not app.config.host.endswith('example.com'):
break
@ -114,12 +119,60 @@ def cli_setup():
click.echo('The domain must not be example.com')
if not app.config.is_docker:
app.config['general_listen'] = click.prompt('Which address should the relay listen on?', default=app.config.listen)
app.config['general_listen'] = click.prompt(
'Which address should the relay listen on?',
default = app.config.listen
)
while True:
app.config['general_port'] = click.prompt('What TCP port should the relay listen on?', default=app.config.port, type=int)
app.config['general_port'] = click.prompt(
'What TCP port should the relay listen on?',
default = app.config.port,
type = int
)
break
app.config['database_type'] = click.prompt(
'What database backend would you like to use for the relay?',
default = app.config.dbtype,
type = click.Choice(['sqlite', 'postgresql', 'mysql']),
show_choices = True
)
if app.config.dbtype == 'sqlite':
app.config['sqlite_database'] = click.prompt(
'Where would you like to store your database file? Relative paths are relative to the config file location.',
default = app.config['sqlite_database']
)
else:
dbconfig = app.config.dbconfig
app.config.hostname = click.prompt(
'What address is your database listening on?',
default = dbconfig.hostname
) or None
app.config.port = click.prompt(
'What port is your database listening on?',
default = dbconfig.port
) or None
app.config.database = click.prompt(
'What would you like the name of the database be?',
default = dbconfig.database
) or None
app.config.username = click.prompt(
'Which user will be connecting to the database?',
default = dbconfig.username
) or None
app.config.password = click.prompt(
'What is the database user\'s password?',
default = dbconfig.password
) or None
app.config.save()
with app.database.session as s: