django-psycopg2-extension


Namedjango-psycopg2-extension JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/druids/django-psycopg2-extension
SummaryLibrary contains django commands which helps to prepare and manage PostgreSQL database.
upload_time2024-01-26 14:32:23
maintainer
docs_urlNone
authorLubos Matl
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django-psycopg2-extension

Library contains django commands which helps to prepare and manage PostgreSQL database.

## Quickstart

Install djjango-psycopg2-extension

```bash
pip install django-psycopg2-extension
```

Add psycopg2_extension to your `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    # Django apps...
    'psycopg2_extension',
]
```

## Commands

### psqlinit

Django command psqlinit create a database defined in django settings. 

You can define specific database settings with standard django ``DATABASE`` settings:

```python
DATABASES = {
    'default': {
        ...
        'EXTENSIONS': ['postgis', 'unaccent'],  # extensions to be installed with psqlinit command
        'SNAPSHOT_FILE': Path('data', 'sql', 'local', 'init_default.sql'), # SQL which will be loaded after database initialization
    },
}
```

Snapshot and extensions are automatically loaded when database is preparing for tests too.

### psqlclean

PostgreSQL database requires often call `VACUUM` and `REINDEX`. The command `psqlclean` performs these operations. 

You can define specific database settings for psqlclean command with standard django ``DATABASE`` settings:

```python
DATABASES = {
    'default': {
        ...
        'VACUUM': {
            'EXCLUDE': ['users_user'],  # list of excluded tables
            'TABLES': ['users_permission'],  # list of tables to vacuum, all tables are selected if the setting is not set
            'TABLES_FULL': ['users_permission'],  # list of tables to vacuum full
            'TABLES_REINDEX': ['users_permission'],  # list of tables to reindex
        }
    },
}
```

### psqlsnapshot

Command which creates SQL dump with ``pg_dump`` script and store it to the database ``'SNAPSHOT_FILE'`` setting.

### psqlviews

Command which creates views defined in ``'VIEWS'`` setting.

```python
DATABASES = {
    'default': {
        ...
        'VIEWS': {
            'MODELS': {
                'auth.users': ['id', 'email', 'first_name', 'last_name'], # Model name and list of fields
            },
            'SCHEMA': 'public', # Schema name
        }
    }
}
```

Now you can call `psqlviews` command to create or remove views.

```bash
./manage.py psqlviews --create
./manage.py psqlviews --delete
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/druids/django-psycopg2-extension",
    "name": "django-psycopg2-extension",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Lubos Matl",
    "author_email": "matllubos@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/30/46/a3d86d1a3fa738065ee13ff4a70e6d797b7ad3b439768c80a6458e1f3813/django-psycopg2-extension-0.2.1.tar.gz",
    "platform": null,
    "description": "# Django-psycopg2-extension\n\nLibrary contains django commands which helps to prepare and manage PostgreSQL database.\n\n## Quickstart\n\nInstall djjango-psycopg2-extension\n\n```bash\npip install django-psycopg2-extension\n```\n\nAdd psycopg2_extension to your `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n    # Django apps...\n    'psycopg2_extension',\n]\n```\n\n## Commands\n\n### psqlinit\n\nDjango command psqlinit create a database defined in django settings. \n\nYou can define specific database settings with standard django ``DATABASE`` settings:\n\n```python\nDATABASES = {\n    'default': {\n        ...\n        'EXTENSIONS': ['postgis', 'unaccent'],  # extensions to be installed with psqlinit command\n        'SNAPSHOT_FILE': Path('data', 'sql', 'local', 'init_default.sql'), # SQL which will be loaded after database initialization\n    },\n}\n```\n\nSnapshot and extensions are automatically loaded when database is preparing for tests too.\n\n### psqlclean\n\nPostgreSQL database requires often call `VACUUM` and `REINDEX`. The command `psqlclean` performs these operations. \n\nYou can define specific database settings for psqlclean command with standard django ``DATABASE`` settings:\n\n```python\nDATABASES = {\n    'default': {\n        ...\n        'VACUUM': {\n            'EXCLUDE': ['users_user'],  # list of excluded tables\n            'TABLES': ['users_permission'],  # list of tables to vacuum, all tables are selected if the setting is not set\n            'TABLES_FULL': ['users_permission'],  # list of tables to vacuum full\n            'TABLES_REINDEX': ['users_permission'],  # list of tables to reindex\n        }\n    },\n}\n```\n\n### psqlsnapshot\n\nCommand which creates SQL dump with ``pg_dump`` script and store it to the database ``'SNAPSHOT_FILE'`` setting.\n\n### psqlviews\n\nCommand which creates views defined in ``'VIEWS'`` setting.\n\n```python\nDATABASES = {\n    'default': {\n        ...\n        'VIEWS': {\n            'MODELS': {\n                'auth.users': ['id', 'email', 'first_name', 'last_name'], # Model name and list of fields\n            },\n            'SCHEMA': 'public', # Schema name\n        }\n    }\n}\n```\n\nNow you can call `psqlviews` command to create or remove views.\n\n```bash\n./manage.py psqlviews --create\n./manage.py psqlviews --delete\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Library contains django commands which helps to prepare and manage PostgreSQL database.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/druids/django-psycopg2-extension"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3046a3d86d1a3fa738065ee13ff4a70e6d797b7ad3b439768c80a6458e1f3813",
                "md5": "a2929ecbd1389127ff05e1649956bf03",
                "sha256": "3a17bf1743f537c458233777899da740770b7e5d337681459795d4bd2959c643"
            },
            "downloads": -1,
            "filename": "django-psycopg2-extension-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a2929ecbd1389127ff05e1649956bf03",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7155,
            "upload_time": "2024-01-26T14:32:23",
            "upload_time_iso_8601": "2024-01-26T14:32:23.103933Z",
            "url": "https://files.pythonhosted.org/packages/30/46/a3d86d1a3fa738065ee13ff4a70e6d797b7ad3b439768c80a6458e1f3813/django-psycopg2-extension-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-26 14:32:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "druids",
    "github_project": "django-psycopg2-extension",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-psycopg2-extension"
}
        
Elapsed time: 0.25703s