Add support for mysql database as messkit backend

This commit is contained in:
Lance Edgar 2022-03-05 10:14:15 -06:00
parent 20430fb241
commit c43daf0940

View file

@ -81,19 +81,20 @@ class Install(commands.Subcommand):
sys.exit(1)
# get db info
dbhost = self.basic_prompt('postgres host', 'localhost')
dbport = self.basic_prompt('postgres port', '5432')
dbname = self.basic_prompt('postgres db', 'messkit')
dbuser = self.basic_prompt('postgres user', 'rattail')
dbtype = self.basic_prompt('db type', 'postgresql')
dbhost = self.basic_prompt('db host', 'localhost')
dbport = self.basic_prompt('db port', '3306' if dbtype == 'mysql' else '5432')
dbname = self.basic_prompt('db name', 'messkit')
dbuser = self.basic_prompt('db user', 'rattail')
# get db password
dbpass = None
while not dbpass:
dbpass = self.basic_prompt('postgres pass', is_password=True)
dbpass = self.basic_prompt('db pass', is_password=True)
# test db connection
rprint("\n\ttesting db connection... ", end='')
dburl = self.make_db_url(dbhost, dbport, dbname, dbuser, dbpass)
dburl = self.make_db_url(dbtype, dbhost, dbport, dbname, dbuser, dbpass)
error = self.test_db_connection(dburl)
if error:
rprint("[bold red]cannot connect![/bold red] ..error was:")
@ -191,6 +192,7 @@ class Install(commands.Subcommand):
if self.basic_prompt("make poser dir?", True, is_bool=True):
rprint()
# make poser dir
poser_handler = self.app.get_poser_handler()
poserdir = poser_handler.make_poser_dir()
@ -247,7 +249,7 @@ class Install(commands.Subcommand):
return text or default
def make_db_url(self, dbhost, dbport, dbname, dbuser, dbpass):
def make_db_url(self, dbtype, dbhost, dbport, dbname, dbuser, dbpass):
try:
# newer style
from sqlalchemy.engine import URL
@ -257,7 +259,12 @@ class Install(commands.Subcommand):
from sqlalchemy.engine.url import URL
factory = URL
return factory(drivername='postgresql+psycopg2',
if dbtype == 'mysql':
drivername = 'mysql+mysqlconnector'
else:
drivername = 'postgresql+psycopg2'
return factory(drivername=drivername,
username=dbuser,
password=dbpass,
host=dbhost,