Skip to content

Allow for Adding Database Connection Options #4160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dstarner opened this issue Feb 13, 2020 · 2 comments
Closed

Allow for Adding Database Connection Options #4160

dstarner opened this issue Feb 13, 2020 · 2 comments
Labels
status: accepted This issue has been accepted for implementation type: documentation A change or addition to the documentation

Comments

@dstarner
Copy link

Environment

  • Python version: 3.7
  • NetBox version: 2.7.2

Proposed Functionality

Django supports the OPTIONS keyword for a database configuration. This could be used to pass custom options & context when connecting to the database.

# In configuration.py

DATABASE = {
    # ... other currently existing values ...
    'CONN_MAX_AGE': 300,      # Max database connection age
    'OPTIONS': {
        # connect only to the netbox schema since thats all our db user has access to
        'options': '-c search_path=%s' % os.getenv('POSTGRES_SCHEMA', 'netbox')
    }
}

By default, OPTIONS can be an empty dictionary {}

DATABASE = {
    # ...other currently existing values ...
    'CONN_MAX_AGE': 300,      # Max database connection age
    'OPTIONS': {}
}

Use Case

For instance, in certain circumstances, such as with shared databases, NetBox may not have full admin privilege over the database and may need to be limited to a specific schema. Not only may this be preferred, but in some environments, it might be necessary due to the availability of developer environments.

Database Changes

None

External Dependencies

None

@jeremystretch
Copy link
Member

NetBox does support passing OPTIONS currently; it's just not documented as a supported parameter. I suppose we can add a link to the relevant Django docs in the config documentation.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: documentation A change or addition to the documentation labels Feb 13, 2020
@dstarner
Copy link
Author

Ah, I didnt realize it was pass-through, that makes sense then

@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: documentation A change or addition to the documentation
Projects
None yet
Development

No branches or pull requests

2 participants