diff --git a/INSTALL.md b/INSTALL.md index ff3d0bb..880d3bf 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -89,7 +89,7 @@ user@host:szuru/server$ source python_modules/bin/activate # enters the sandbox - API URL, - data directory, - data URL, - - the `database` section, + - database, - the `smtp` section. 2. Compile the frontend: diff --git a/config.yaml.dist b/config.yaml.dist index bcf9846..8048a9a 100644 --- a/config.yaml.dist +++ b/config.yaml.dist @@ -11,29 +11,20 @@ base_url: # used to form links to frontend, example: http://example.com/ data_url: # used to form links to posts and avatars, example: http://example.com/data/ data_dir: # absolute path for posts and avatars storage, example: /srv/www/booru/client/public/data/ + +# usage: schema://user:password@host:port/database_name +# example: postgres://szuru:dog@localhost:5432/szuru_test +# example (useful for tests): sqlite:///:memory: +database: +test_database: 'sqlite:///:memory:' # required for runing the test suite + + thumbnails: avatar_width: 300 avatar_height: 300 post_width: 300 post_height: 300 -database: - schema: postgres - host: # example: localhost - port: # example: 5432 - user: # example: szuru - pass: # example: dog - name: # example: szuru - -# required for runing the test suite -test_database: - schema: postgres - host: # example: localhost - port: # example: 5432 - user: # example: szuru - pass: # example: dog - name: # example: szuru_test - # used to send password reminders smtp: host: # example: localhost diff --git a/server/szurubooru/db/session.py b/server/szurubooru/db/session.py index b9dea7c..eb8f621 100644 --- a/server/szurubooru/db/session.py +++ b/server/szurubooru/db/session.py @@ -19,14 +19,7 @@ class QueryCounter(object): def create_session(): - _engine = sqlalchemy.create_engine( - '{schema}://{user}:{password}@{host}:{port}/{name}'.format( - schema=config.config['database']['schema'], - user=config.config['database']['user'], - password=config.config['database']['pass'], - host=config.config['database']['host'], - port=config.config['database']['port'], - name=config.config['database']['name'])) + _engine = sqlalchemy.create_engine(config.config['database']) sqlalchemy.event.listen( _engine, 'after_execute', lambda *args: QueryCounter.bump()) _session_maker = sqlalchemy.orm.sessionmaker(bind=_engine) diff --git a/server/szurubooru/facade.py b/server/szurubooru/facade.py index 69bc6b9..60e58d5 100644 --- a/server/szurubooru/facade.py +++ b/server/szurubooru/facade.py @@ -68,10 +68,8 @@ def validate_config(): raise errors.ConfigError( 'data_dir must be an absolute path') - for key in ['schema', 'host', 'port', 'user', 'pass', 'name']: - if not config.config['database'][key]: - raise errors.ConfigError( - 'Database is not configured: %r is missing' % key) + if not config.config['database']: + raise errors.ConfigError('Database is not configured') def create_app(): diff --git a/server/szurubooru/migrations/env.py b/server/szurubooru/migrations/env.py index f116150..2f7c112 100644 --- a/server/szurubooru/migrations/env.py +++ b/server/szurubooru/migrations/env.py @@ -16,15 +16,7 @@ alembic_config = alembic.context.config logging.config.fileConfig(alembic_config.config_file_name) szuru_config = szurubooru.config.config -alembic_config.set_main_option( - 'sqlalchemy.url', - '{schema}://{user}:{password}@{host}:{port}/{name}'.format( - schema=szuru_config['database']['schema'], - user=szuru_config['database']['user'], - password=szuru_config['database']['pass'], - host=szuru_config['database']['host'], - port=szuru_config['database']['port'], - name=szuru_config['database']['name'])) +alembic_config.set_main_option('sqlalchemy.url', szuru_config['database']) target_metadata = szurubooru.db.Base.metadata diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index aca4682..3db1960 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -31,18 +31,11 @@ class QueryCounter(object): return self._statements -if not config.config['test_database']['host']: +if not config.config['test_database']: raise RuntimeError('Test database not configured.') _query_counter = QueryCounter() -_engine = sqlalchemy.create_engine( - '{schema}://{user}:{password}@{host}:{port}/{name}'.format( - schema=config.config['test_database']['schema'], - user=config.config['test_database']['user'], - password=config.config['test_database']['pass'], - host=config.config['test_database']['host'], - port=config.config['test_database']['port'], - name=config.config['test_database']['name'])) +_engine = sqlalchemy.create_engine(config.config['test_database']) db.Base.metadata.drop_all(bind=_engine) db.Base.metadata.create_all(bind=_engine) sqlalchemy.event.listen(