sprin / pg-discuss

A comment system backend in Python with PostgreSQL
http://pg-discuss.sprin.io/
9 stars 1 forks source link

Postgres socket #29

Open cryptofuture opened 8 years ago

cryptofuture commented 8 years ago

Can I use it with postgres socket? Didn't found anything beside servername:port in configuration.

cryptofuture commented 8 years ago

Is not wise how to use DATABASE_URL var now. I tried:

DATABASE_URL=postgresql:///pg-discuss:password@localhost:5432/pg-discuss
DATABASE_URL=postgresql://pg-discuss:password@localhost:5432/pg-discuss
DATABASE_URL=postgresql:///pg-discuss
DATABASE_URL=postgresql://pg-discuss@:5432/pg-discuss
DATABASE_URL=postgresql://pg-discuss@127.0.0.1:5432/pg-discuss
DATABASE_URL=postgresql://pg-discuss:password@127.0.0.1:5432/pg-discuss
sprin commented 8 years ago

The rules are specified by the libpq connection string format. To specify a unix socket, you need to omit the hostname. Example:

postgresql://pg-discuss:password@/pg-discuss
cryptofuture commented 8 years ago

It gives me SyntaxError: invalid syntax

Traceback (most recent call last):
  File "/opt/pg-discuss/bin/pgd-admin", line 7, in <module>
    from pg_discuss.management import execute_from_command_line
  File "/opt/pg-discuss/lib/python3.5/site-packages/pg_discuss/management.py", line 3, in <module>
    app = app_factory()
  File "/opt/pg-discuss/lib/python3.5/site-packages/pg_discuss/app.py", line 46, in app_factory
    app.config.from_pyfile(custom_settings)
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask/config.py", line 130, in from_pyfile
    exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
  File "/opt/pg-discuss/local_settings.py", line 1
    DATABASE_URL=postgresql://pg-discuss:myrolepassword@/pg-discuss
                                   ^
SyntaxError: invalid syntax

with DATABASE_URL='postgresql://pg-discuss:password@/pg-discuss'

 File "/opt/pg-discuss/bin/pgd-admin", line 11, in <module>
    sys.exit(execute_from_command_line())
  File "/opt/pg-discuss/lib/python3.5/site-packages/pg_discuss/management.py", line 7, in execute_from_command_line
    app.script_manager.run()
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_script/__init__.py", line 412, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_script/__init__.py", line 383, in handle
    res = handle(*args, **config)
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_migrate/__init__.py", line 239, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/command.py", line 174, in upgrade
    script.run_env()
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/script/base.py", line 407, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/util/compat.py", line 68, in load_module_py
    module_id, path).load_module(module_id)
  File "<frozen importlib._bootstrap_external>", line 388, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 809, in load_module
  File "<frozen importlib._bootstrap_external>", line 668, in load_module
  File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "migrations/env.py", line 19, in <module>
    config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI'))
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/config.py", line 218, in set_main_option
    self.set_section_option(self.config_ini_section, name, value)
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/config.py", line 245, in set_section_option
    self.file_config.set(section, name, value)
  File "/usr/lib/python3.5/configparser.py", line 1189, in set
    self._validate_value_types(option=option, value=value)
  File "/usr/lib/python3.5/configparser.py", line 1174, in _validate_value_types
    raise TypeError("option values must be strings")
TypeError: <flask_script.commands.Command object at 0x7f6687771828>: option values must be strings

local_settings.py(located in /opt/pg-discuss) file contents:

DATABASE_URL=postgresql://pg-discuss:myrolepassword@/pg-discuss
SECRET_KEY=mygeneratedsecretkeyhere
SERVER_NAME=localhost:8080
sprin commented 8 years ago

Since this is a Python file, you'll need to quote the strings to avoid the syntax error.

DATABASE_URL="postgresql://pg-discuss:myrolepassword@/pg-discuss"
SECRET_KEY="mygeneratedsecretkeyhere"
SERVER_NAME="localhost:8080"

Apologies I didn't realize that earlier. I was thinking your were using bash syntax to set an environment variable. I'll see if I can clarify this in the docs.

cryptofuture commented 8 years ago

It gives same output as with ' used for quotes

(pg-discuss) user@hostname:/opt/pg-discuss# pgd-admin db upgrade
Traceback (most recent call last):
  File "/opt/pg-discuss/bin/pgd-admin", line 11, in <module>
    sys.exit(execute_from_command_line())
  File "/opt/pg-discuss/lib/python3.5/site-packages/pg_discuss/management.py", line 7, in execute_from_command_line
    app.script_manager.run()
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_script/__init__.py", line 412, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_script/__init__.py", line 383, in handle
    res = handle(*args, **config)
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/opt/pg-discuss/lib/python3.5/site-packages/flask_migrate/__init__.py", line 239, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/command.py", line 174, in upgrade
    script.run_env()
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/script/base.py", line 407, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/util/compat.py", line 68, in load_module_py
    module_id, path).load_module(module_id)
  File "<frozen importlib._bootstrap_external>", line 388, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 809, in load_module
  File "<frozen importlib._bootstrap_external>", line 668, in load_module
  File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "migrations/env.py", line 19, in <module>
    config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI'))
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/config.py", line 218, in set_main_option
    self.set_section_option(self.config_ini_section, name, value)
  File "/opt/pg-discuss/lib/python3.5/site-packages/alembic/config.py", line 245, in set_section_option
    self.file_config.set(section, name, value)
  File "/usr/lib/python3.5/configparser.py", line 1189, in set
    self._validate_value_types(option=option, value=value)
  File "/usr/lib/python3.5/configparser.py", line 1174, in _validate_value_types
    raise TypeError("option values must be strings")
TypeError: <flask_script.commands.Command object at 0x7f9370865828>: option values must be strings
(pg-discuss) user@hostname:/opt/pg-discuss# cat local_settings.py 
DATABASE_URL="postgresql://pg-discuss:myrolepassword@/pg-discuss"
SECRET_KEY="mygeneratedsecretkeyhere"
SERVER_NAME="localhost:8080"(pg-discuss) user@hostname:/opt/pg-discuss# 

Maybe its something in configparser.