django-mysql-replication


Namedjango-mysql-replication JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/waqqas/django-mysql-replication
SummaryMySQL DB change events by reading replication logs
upload_time2024-05-12 14:53:08
maintainerNone
docs_urlNone
authorWaqqas Jabbar
requires_python>=3.9
licenseMIT
keywords django schedule
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ### django-myql-migration
MySQL DB change events by reading replication logs. These are useful when the data is directly inserted into the MySQL database.

### Installation

Install via `pip`

`pip install django-myql-migration`

Add `"django_myql_migration"` to your `INSTALLED_APPS` settings like this:

```
INSTALLED_APPS = (
    "django_myql_migration",
    ...
)
```

Edit `my.cnf` to setup replication, as follows:
```
[mysqld]
log-bin=mysql-bin
server-id=1
binlog-format=row
gtid_mode=ON
log-slave_updates=true
enforce_gtid_consistency
binlog-row-metadata=FULL
binlog-row-image=FULL
```

Set these environment variables `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_DATABASE`, `MYSQL_SLAVE_USER`, `MYSQL_SLAVE_PASSWORD`

Add replication user using the following command

`mysql -u root -p -h ${MYSQL_HOST} -P ${MYSQL_PORT} ${MYSQL_DATABASE} -e "CREATE USER '${MYSQL_SLAVE_USER}'@'%' IDENTIFIED BY '${MYSQL_SLAVE_PASSWORD}'; GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO '${MYSQL_SLAVE_USER}'@'%';FLUSH PRIVILEGES;"`


### Usage

There are 3 signals generated by the package: `row_inserted`, `row_deleted` and `row_updated`. You can use the standard Django signal handling mechanism to handle signals. e.g. To know when the user is added to the system, you can create a `signals.py` file with the following content

```
from django_mysql_replication.signals import row_inserted
from django.contrib.auth import get_user_model

User = get_user_model()

@receiver(row_inserted, sender=User)
def user_added(sender, instance, *args, **kwargs):
    pass

```

Run the following command to listen to DB changes

`python manage.py listen`


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/waqqas/django-mysql-replication",
    "name": "django-mysql-replication",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "django, schedule",
    "author": "Waqqas Jabbar",
    "author_email": "waqqas.jabbar@egmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c8/23/01f2a63b23ed9d64318e07c187a58972a65895b7c0db353be493e554e792/django-mysql-replication-0.1.3.tar.gz",
    "platform": null,
    "description": "### django-myql-migration\nMySQL DB change events by reading replication logs. These are useful when the data is directly inserted into the MySQL database.\n\n### Installation\n\nInstall via `pip`\n\n`pip install django-myql-migration`\n\nAdd `\"django_myql_migration\"` to your `INSTALLED_APPS` settings like this:\n\n```\nINSTALLED_APPS = (\n    \"django_myql_migration\",\n    ...\n)\n```\n\nEdit `my.cnf` to setup replication, as follows:\n```\n[mysqld]\nlog-bin=mysql-bin\nserver-id=1\nbinlog-format=row\ngtid_mode=ON\nlog-slave_updates=true\nenforce_gtid_consistency\nbinlog-row-metadata=FULL\nbinlog-row-image=FULL\n```\n\nSet these environment variables `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_DATABASE`, `MYSQL_SLAVE_USER`, `MYSQL_SLAVE_PASSWORD`\n\nAdd replication user using the following command\n\n`mysql -u root -p -h ${MYSQL_HOST} -P ${MYSQL_PORT} ${MYSQL_DATABASE} -e \"CREATE USER '${MYSQL_SLAVE_USER}'@'%' IDENTIFIED BY '${MYSQL_SLAVE_PASSWORD}'; GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO '${MYSQL_SLAVE_USER}'@'%';FLUSH PRIVILEGES;\"`\n\n\n### Usage\n\nThere are 3 signals generated by the package: `row_inserted`, `row_deleted` and `row_updated`. You can use the standard Django signal handling mechanism to handle signals. e.g. To know when the user is added to the system, you can create a `signals.py` file with the following content\n\n```\nfrom django_mysql_replication.signals import row_inserted\nfrom django.contrib.auth import get_user_model\n\nUser = get_user_model()\n\n@receiver(row_inserted, sender=User)\ndef user_added(sender, instance, *args, **kwargs):\n    pass\n\n```\n\nRun the following command to listen to DB changes\n\n`python manage.py listen`\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "MySQL DB change events by reading replication logs",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/waqqas/django-mysql-replication"
    },
    "split_keywords": [
        "django",
        " schedule"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "60f1dd490d55281407908ef3933470343c1b37ac94daec5f39727a834343c7d9",
                "md5": "aa11cb0b7c6bd8d9ae8cf9665442d958",
                "sha256": "9da32b926705c1b85ccaac49812a3b10ddb63334336b7342de187bcd2e8228ed"
            },
            "downloads": -1,
            "filename": "django_mysql_replication-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aa11cb0b7c6bd8d9ae8cf9665442d958",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6891,
            "upload_time": "2024-05-12T14:53:07",
            "upload_time_iso_8601": "2024-05-12T14:53:07.093568Z",
            "url": "https://files.pythonhosted.org/packages/60/f1/dd490d55281407908ef3933470343c1b37ac94daec5f39727a834343c7d9/django_mysql_replication-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c82301f2a63b23ed9d64318e07c187a58972a65895b7c0db353be493e554e792",
                "md5": "2cfc0764944d0a6e1490e430c62aac50",
                "sha256": "fc8ffb2f8366ff98f3a7dff2c92de86e499b1087a7f6cdd63d9833f5b2e1d892"
            },
            "downloads": -1,
            "filename": "django-mysql-replication-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2cfc0764944d0a6e1490e430c62aac50",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 5795,
            "upload_time": "2024-05-12T14:53:08",
            "upload_time_iso_8601": "2024-05-12T14:53:08.648399Z",
            "url": "https://files.pythonhosted.org/packages/c8/23/01f2a63b23ed9d64318e07c187a58972a65895b7c0db353be493e554e792/django-mysql-replication-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-12 14:53:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "waqqas",
    "github_project": "django-mysql-replication",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-mysql-replication"
}
        
Elapsed time: 0.22343s