# Django Rename Table
This package provides the ability to create (and remove) an alias of a database table.
You may wish to do this when renaming database tables and want to avoid downtime.
Renaming tables on a live system can be problematic. If you run the migration to raname the table first then any
previous running versions of the code will start to error as they can no longer find the model's table.
Deploying the updated code first and then migrating would also fail for similar reasons.
A solution to this is to use this tool and a multistep process.
## Instructions
### 1) Rename the table
This renames the table and create an alias with the original name.
```python
from django.db import migrations
from django_rename_table.operations import RenameTableWithAlias
class Migration(migrations.Migration):
dependencies = [
("myapp", "0001_initial"),
]
operations = [
RenameTableWithAlias("old_table_name", "new_table_name"),
]
```
### 2) Apply the migration
```python manage.py migrate```
### 3) Update model to point at renamed table
```python
from django.db import models
class MyModel(models.Model):
name = models.CharField(max_length=1000)
class Meta:
db_table = "new_table_name"
```
### 4) Delete alias when you're happy no deployed code is using the old table
```python
from django.db import migrations
from django_rename_table.operations import RemoveAlias
class Migration(migrations.Migration):
dependencies = [
("myapp", "0002_rename_and_create_alias"),
]
operations = [
RemoveAlias("old_table_name"),
]
```
## License
This project is licensed under the MIT License. See the LICENSE file for details.
## Contributing
Contributions are welcome! Please submit a pull request or open an issue to report bugs or suggest features.
Raw data
{
"_id": null,
"home_page": "https://github.com/mathewpower/django-rename-table",
"name": "django-rename-table",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "django, migration, operations, database, postgresql",
"author": "Mathew Power",
"author_email": "mathew.power@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/de/cc/6917007f0d6a6d7c3eb0bbb4957a1206674218ddf8712bed5f3d0244c1d7/django_rename_table-0.1.1.tar.gz",
"platform": null,
"description": "# Django Rename Table\n\nThis package provides the ability to create (and remove) an alias of a database table.\n\nYou may wish to do this when renaming database tables and want to avoid downtime.\n\nRenaming tables on a live system can be problematic. If you run the migration to raname the table first then any\nprevious running versions of the code will start to error as they can no longer find the model's table.\n\nDeploying the updated code first and then migrating would also fail for similar reasons.\n\nA solution to this is to use this tool and a multistep process.\n\n## Instructions\n\n### 1) Rename the table\nThis renames the table and create an alias with the original name.\n\n```python\nfrom django.db import migrations\nfrom django_rename_table.operations import RenameTableWithAlias\n\nclass Migration(migrations.Migration):\n dependencies = [\n (\"myapp\", \"0001_initial\"),\n ]\n\n operations = [\n RenameTableWithAlias(\"old_table_name\", \"new_table_name\"),\n ]\n```\n\n### 2) Apply the migration\n```python manage.py migrate```\n\n### 3) Update model to point at renamed table\n```python\nfrom django.db import models\n\nclass MyModel(models.Model):\n name = models.CharField(max_length=1000)\n\n class Meta:\n db_table = \"new_table_name\"\n```\n\n\n### 4) Delete alias when you're happy no deployed code is using the old table\n```python\nfrom django.db import migrations\nfrom django_rename_table.operations import RemoveAlias\n\nclass Migration(migrations.Migration):\n dependencies = [\n (\"myapp\", \"0002_rename_and_create_alias\"),\n ]\n\n operations = [\n RemoveAlias(\"old_table_name\"),\n ]\n```\n\n## License\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Contributing\nContributions are welcome! Please submit a pull request or open an issue to report bugs or suggest features.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django migration operations for renaming tables with aliases and managing view aliases.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/mathewpower/django-rename-table",
"Repository": "https://github.com/mathewpower/django-rename-table",
"documentation": "https://github.com/mathewpower/django-rename-table#readme",
"issues": "https://github.com/mathewpower/django-rename-table/issues"
},
"split_keywords": [
"django",
" migration",
" operations",
" database",
" postgresql"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "43eb1da0bfe4ac6f5652ddd7635d9c23bb780cfb8ec92163bdd5f638dde4f723",
"md5": "a03fc0428d70e6bed210b6439db58529",
"sha256": "2679e89cfd4399f6cb873554ca9157b26b84ed89a844742ca43dc17f839c7af4"
},
"downloads": -1,
"filename": "django_rename_table-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a03fc0428d70e6bed210b6439db58529",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 3994,
"upload_time": "2024-12-02T00:32:48",
"upload_time_iso_8601": "2024-12-02T00:32:48.289542Z",
"url": "https://files.pythonhosted.org/packages/43/eb/1da0bfe4ac6f5652ddd7635d9c23bb780cfb8ec92163bdd5f638dde4f723/django_rename_table-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "decc6917007f0d6a6d7c3eb0bbb4957a1206674218ddf8712bed5f3d0244c1d7",
"md5": "78cfe18c57f0b619b79b7cb6de8d6493",
"sha256": "1c164ae14831e2193baa1c561b6439e8bf0e3b38878cea14543cd8bcd700701c"
},
"downloads": -1,
"filename": "django_rename_table-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "78cfe18c57f0b619b79b7cb6de8d6493",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 3397,
"upload_time": "2024-12-02T00:32:49",
"upload_time_iso_8601": "2024-12-02T00:32:49.780317Z",
"url": "https://files.pythonhosted.org/packages/de/cc/6917007f0d6a6d7c3eb0bbb4957a1206674218ddf8712bed5f3d0244c1d7/django_rename_table-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 00:32:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mathewpower",
"github_project": "django-rename-table",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-rename-table"
}