Add support for mysql database as messkit backend
This commit is contained in:
parent
20430fb241
commit
c43daf0940
|
@ -81,19 +81,20 @@ class Install(commands.Subcommand):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# get db info
|
# get db info
|
||||||
dbhost = self.basic_prompt('postgres host', 'localhost')
|
dbtype = self.basic_prompt('db type', 'postgresql')
|
||||||
dbport = self.basic_prompt('postgres port', '5432')
|
dbhost = self.basic_prompt('db host', 'localhost')
|
||||||
dbname = self.basic_prompt('postgres db', 'messkit')
|
dbport = self.basic_prompt('db port', '3306' if dbtype == 'mysql' else '5432')
|
||||||
dbuser = self.basic_prompt('postgres user', 'rattail')
|
dbname = self.basic_prompt('db name', 'messkit')
|
||||||
|
dbuser = self.basic_prompt('db user', 'rattail')
|
||||||
|
|
||||||
# get db password
|
# get db password
|
||||||
dbpass = None
|
dbpass = None
|
||||||
while not dbpass:
|
while not dbpass:
|
||||||
dbpass = self.basic_prompt('postgres pass', is_password=True)
|
dbpass = self.basic_prompt('db pass', is_password=True)
|
||||||
|
|
||||||
# test db connection
|
# test db connection
|
||||||
rprint("\n\ttesting db connection... ", end='')
|
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)
|
error = self.test_db_connection(dburl)
|
||||||
if error:
|
if error:
|
||||||
rprint("[bold red]cannot connect![/bold red] ..error was:")
|
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):
|
if self.basic_prompt("make poser dir?", True, is_bool=True):
|
||||||
rprint()
|
rprint()
|
||||||
|
|
||||||
|
# make poser dir
|
||||||
poser_handler = self.app.get_poser_handler()
|
poser_handler = self.app.get_poser_handler()
|
||||||
poserdir = poser_handler.make_poser_dir()
|
poserdir = poser_handler.make_poser_dir()
|
||||||
|
|
||||||
|
@ -247,7 +249,7 @@ class Install(commands.Subcommand):
|
||||||
|
|
||||||
return text or default
|
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:
|
try:
|
||||||
# newer style
|
# newer style
|
||||||
from sqlalchemy.engine import URL
|
from sqlalchemy.engine import URL
|
||||||
|
@ -257,7 +259,12 @@ class Install(commands.Subcommand):
|
||||||
from sqlalchemy.engine.url import URL
|
from sqlalchemy.engine.url import URL
|
||||||
factory = URL
|
factory = URL
|
||||||
|
|
||||||
return factory(drivername='postgresql+psycopg2',
|
if dbtype == 'mysql':
|
||||||
|
drivername = 'mysql+mysqlconnector'
|
||||||
|
else:
|
||||||
|
drivername = 'postgresql+psycopg2'
|
||||||
|
|
||||||
|
return factory(drivername=drivername,
|
||||||
username=dbuser,
|
username=dbuser,
|
||||||
password=dbpass,
|
password=dbpass,
|
||||||
host=dbhost,
|
host=dbhost,
|
||||||
|
|
Loading…
Reference in a new issue