From 140b72a72ba3748044edab1ec3abec6e0d5efc97 Mon Sep 17 00:00:00 2001 From: nolash Date: Wed, 10 Nov 2021 09:07:23 +0100 Subject: [PATCH] Use database prefix instead of name --- .../cic-cache/cic_cache/data/config/database.ini | 3 ++- apps/cic-cache/cic_cache/db/__init__.py | 9 ++++++--- apps/cic-cache/cic_cache/version.py | 2 +- apps/cic-cache/requirements.txt | 16 ++++++++-------- apps/cic-cache/scripts/migrate.py | 9 ++++----- apps/cic-cache/setup.cfg | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/apps/cic-cache/cic_cache/data/config/database.ini b/apps/cic-cache/cic_cache/data/config/database.ini index e32e62f3..3c20e4ec 100644 --- a/apps/cic-cache/cic_cache/data/config/database.ini +++ b/apps/cic-cache/cic_cache/data/config/database.ini @@ -3,7 +3,8 @@ engine = driver = host = port = -name = cic-cache +#name = cic-cache +prefix = user = password = debug = 0 diff --git a/apps/cic-cache/cic_cache/db/__init__.py b/apps/cic-cache/cic_cache/db/__init__.py index b2bb01b9..edc9e04b 100644 --- a/apps/cic-cache/cic_cache/db/__init__.py +++ b/apps/cic-cache/cic_cache/db/__init__.py @@ -14,16 +14,19 @@ from .list import ( logg = logging.getLogger() -def dsn_from_config(config): +def dsn_from_config(config, name): scheme = config.get('DATABASE_ENGINE') if config.get('DATABASE_DRIVER') != None: scheme += '+{}'.format(config.get('DATABASE_DRIVER')) + database_name = name + if config.get('DATABASE_PREFIX'): + database_name = '{}_{}'.format(config.get('DATABASE_PREFIX'), database_name) dsn = '' if config.get('DATABASE_ENGINE') == 'sqlite': dsn = '{}:///{}'.format( scheme, - config.get('DATABASE_NAME'), + database_name, ) else: @@ -33,7 +36,7 @@ def dsn_from_config(config): config.get('DATABASE_PASSWORD'), config.get('DATABASE_HOST'), config.get('DATABASE_PORT'), - config.get('DATABASE_NAME'), + database_name, ) logg.debug('parsed dsn from config: {}'.format(dsn)) return dsn diff --git a/apps/cic-cache/cic_cache/version.py b/apps/cic-cache/cic_cache/version.py index 814fc8e0..25a3de36 100644 --- a/apps/cic-cache/cic_cache/version.py +++ b/apps/cic-cache/cic_cache/version.py @@ -5,7 +5,7 @@ version = ( 0, 2, 1, - 'alpha.2', + 'alpha.3', ) version_object = semver.VersionInfo( diff --git a/apps/cic-cache/requirements.txt b/apps/cic-cache/requirements.txt index 4cabe432..ae488062 100644 --- a/apps/cic-cache/requirements.txt +++ b/apps/cic-cache/requirements.txt @@ -1,15 +1,15 @@ alembic==1.4.2 -confini>=0.3.6rc4,<0.5.0 +confini~=0.5.2 uwsgi==2.0.19.1 -moolb~=0.1.1b2 -cic-eth-registry~=0.6.1a5 +moolb~=0.2.0 +cic-eth-registry~=0.6.1 SQLAlchemy==1.3.20 semver==2.13.0 psycopg2==2.8.6 celery==4.4.7 redis==3.5.3 -chainsyncer[sql]>=0.0.6a3,<0.1.0 -erc20-faucet>=0.3.2a2, <0.4.0 -chainlib-eth>=0.0.9a14,<0.1.0 -eth-address-index>=0.2.3a4,<0.3.0 -okota>=0.2.4a6,<0.3.0 +chainsyncer[sql]~=0.0.7 +erc20-faucet~=0.3.2 +chainlib-eth~=0.0.11 +eth-address-index>=0.2.4 +okota~=0.2.4 diff --git a/apps/cic-cache/scripts/migrate.py b/apps/cic-cache/scripts/migrate.py index 581fd432..5adc3968 100644 --- a/apps/cic-cache/scripts/migrate.py +++ b/apps/cic-cache/scripts/migrate.py @@ -21,7 +21,7 @@ logg = logging.getLogger() # BUG: the dbdir doesn't work after script install rootdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) dbdir = os.path.join(rootdir, 'cic_cache', 'db') -migrationsdir = os.path.join(dbdir, 'migrations') +default_migrations_dir = os.path.join(dbdir, 'migrations') configdir = os.path.join(rootdir, 'cic_cache', 'data', 'config') #config_dir = os.path.join('/usr/local/etc/cic-cache') @@ -32,7 +32,7 @@ argparser = cic_cache.cli.ArgumentParser(arg_flags) argparser.process_local_flags(local_arg_flags) argparser.add_argument('--reset', action='store_true', help='downgrade before upgrading') argparser.add_argument('-f', '--force', action='store_true', help='force action') -argparser.add_argument('--migrations-dir', dest='migrations_dir', type=str, help='migrations directory') +argparser.add_argument('--migrations-dir', dest='migrations_dir', default=default_migrations_dir, type=str, help='migrations directory') args = argparser.parse_args() extra_args = { @@ -40,17 +40,16 @@ extra_args = { 'force': None, 'migrations_dir': None, } - # process config config = cic_cache.cli.Config.from_args(args, arg_flags, local_arg_flags, extra_args=extra_args) -migrations_dir = os.path.join(config.get('_MIGRATIONS_DIR'), config.get('DATABASE_ENGINE')) +migrations_dir = os.path.join(config.get('_MIGRATIONS_DIR'), config.get('DATABASE_ENGINE', 'default')) if not os.path.isdir(migrations_dir): logg.debug('migrations dir for engine {} not found, reverting to default'.format(config.get('DATABASE_ENGINE'))) migrations_dir = os.path.join(args.migrations_dir, 'default') # connect to database -dsn = dsn_from_config(config) +dsn = dsn_from_config(config, 'cic_cache') logg.info('using migrations dir {}'.format(migrations_dir)) diff --git a/apps/cic-cache/setup.cfg b/apps/cic-cache/setup.cfg index 3ffda56c..531de168 100644 --- a/apps/cic-cache/setup.cfg +++ b/apps/cic-cache/setup.cfg @@ -1,7 +1,7 @@ [metadata] name = cic-cache description = CIC Cache API and server -version = 0.2.1a2 +version = 0.2.1a10 author = Louis Holbrook author_email = dev@holbrook.no url = https://gitlab.com/grassrootseconomics/cic-eth