sql_filename => sql_dir
This commit is contained in:
parent
5103b7bd28
commit
892e052969
|
@ -1,6 +1,7 @@
|
||||||
import asyncpg
|
import asyncpg
|
||||||
import asyncio
|
import asyncio
|
||||||
from os.path import isfile
|
from os import listdir
|
||||||
|
from os.path import isdir, join
|
||||||
from sys import exit
|
from sys import exit
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,16 +9,20 @@ from risotto.config import get_config
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
sql_filename = get_config()['global']['sql_filename']
|
sql_dir = get_config()['global']['sql_dir']
|
||||||
if not isfile(sql_filename):
|
if not isdir(sql_dir):
|
||||||
print('no sql file to import')
|
print('no sql file to import')
|
||||||
exit()
|
exit()
|
||||||
db_conf = get_config()['database']['dsn']
|
db_conf = get_config()['database']['dsn']
|
||||||
pool = await asyncpg.create_pool(db_conf)
|
pool = await asyncpg.create_pool(db_conf)
|
||||||
async with pool.acquire() as connection:
|
async with pool.acquire() as connection:
|
||||||
async with connection.transaction():
|
async with connection.transaction():
|
||||||
with open(sql_filename, 'r') as sql:
|
for filename in listdir(sql_dir):
|
||||||
await connection.execute(sql.read())
|
if filename.endswith('.sql'):
|
||||||
|
sql_filename = join(sql_dir, filename)
|
||||||
|
with open(sql_filename, 'r') as sql:
|
||||||
|
await connection.execute(sql.read())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
|
@ -7,8 +7,7 @@ DEFAULT_USER = environ.get('DEFAULT_USER', 'Anonymous')
|
||||||
DEFAULT_DSN = environ.get('RISOTTO_DSN', 'postgres:///risotto?host=/var/run/postgresql/&user=risotto')
|
DEFAULT_DSN = environ.get('RISOTTO_DSN', 'postgres:///risotto?host=/var/run/postgresql/&user=risotto')
|
||||||
DEFAULT_TIRAMISU_DSN = environ.get('DEFAULT_TIRAMISU_DSN', 'postgres:///tiramisu?host=/var/run/postgresql/&user=tiramisu')
|
DEFAULT_TIRAMISU_DSN = environ.get('DEFAULT_TIRAMISU_DSN', 'postgres:///tiramisu?host=/var/run/postgresql/&user=tiramisu')
|
||||||
MESSAGE_PATH = environ.get('MESSAGE_PATH', '/root/risotto-message/messages')
|
MESSAGE_PATH = environ.get('MESSAGE_PATH', '/root/risotto-message/messages')
|
||||||
MODULE_NAME = environ.get('MODULE_NAME', 'test')
|
SQL_DIR = environ.get('SQL_DIR', './sql')
|
||||||
SQL_FILENAME = f'/root/risotto-{MODULE_NAME}/sql/init.sql'
|
|
||||||
|
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
|
@ -22,8 +21,7 @@ def get_config():
|
||||||
'internal_user': 'internal',
|
'internal_user': 'internal',
|
||||||
'check_role': True,
|
'check_role': True,
|
||||||
'admin_user': DEFAULT_USER,
|
'admin_user': DEFAULT_USER,
|
||||||
'module_name': MODULE_NAME,
|
'sql_dir': SQL_DIR},
|
||||||
'sql_filename': SQL_FILENAME},
|
|
||||||
'source': {'root_path': '/srv/seed'},
|
'source': {'root_path': '/srv/seed'},
|
||||||
'cache': {'root_path': '/var/cache/risotto'},
|
'cache': {'root_path': '/var/cache/risotto'},
|
||||||
'servermodel': {'internal_source': 'internal',
|
'servermodel': {'internal_source': 'internal',
|
||||||
|
|
Loading…
Reference in New Issue