Merge pull request #44 from carrotquest/run-migrations-hints

Added ability to add hints to RunPython and RunSQL migration operations
This commit is contained in:
M1ha Shvn 2022-10-19 10:43:38 +03:00 committed by GitHub
commit b2cb098349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -75,6 +75,12 @@ Parameters
* `--verbosity: Optional[int] = 1` - Level of debug output. See [here](https://docs.djangoproject.com/en/3.2/ref/django-admin/#cmdoption-verbosity) for more details. * `--verbosity: Optional[int] = 1` - Level of debug output. See [here](https://docs.djangoproject.com/en/3.2/ref/django-admin/#cmdoption-verbosity) for more details.
* `--help` - Print help * `--help` - Print help
## Migration operations enhancements
* `RunSQL`, `RunPython`
Can accept `hints: dict = {}` parameter in order to set migration database alias (`force_migrate_on_databases: List[str]` key) or model (`model: Union[str, Type[ClickHouseModel]]` key)
## Migration algorithm ## Migration algorithm
- Get a list of databases from `CLICKHOUSE_DATABASES` setting. Migrate them one by one. - Get a list of databases from `CLICKHOUSE_DATABASES` setting. Migrate them one by one.
- Find all django apps from `INSTALLED_APPS` setting, which have no `readonly=True` attribute and have `migrate=True` attribute. Migrate them one by one. - Find all django apps from `INSTALLED_APPS` setting, which have no `readonly=True` attribute and have `migrate=True` attribute. Migrate them one by one.

View File

@ -13,7 +13,7 @@ with open('requirements.txt') as f:
setup( setup(
name='django-clickhouse', name='django-clickhouse',
version='1.1.2', version='1.2.0',
packages=['django_clickhouse', 'django_clickhouse.management.commands'], packages=['django_clickhouse', 'django_clickhouse.management.commands'],
package_dir={'': 'src'}, package_dir={'': 'src'},
url='https://github.com/carrotquest/django-clickhouse', url='https://github.com/carrotquest/django-clickhouse',

View File

@ -10,6 +10,7 @@ from django.dispatch import receiver
# In order to support all operations import here # In order to support all operations import here
from infi.clickhouse_orm.migrations import * # noqa F401, F403 from infi.clickhouse_orm.migrations import * # noqa F401, F403
from infi.clickhouse_orm.migrations import RunSQL as LibRunSQL, RunPython as LibRunPython
from infi.clickhouse_orm.database import ServerError, DatabaseException from infi.clickhouse_orm.database import ServerError, DatabaseException
from infi.clickhouse_orm.fields import StringField, DateField from infi.clickhouse_orm.fields import StringField, DateField
@ -176,3 +177,15 @@ class MigrationHistory(ClickHouseModel):
@classmethod @classmethod
def table_name(cls): def table_name(cls):
return 'django_clickhouse_migrations' return 'django_clickhouse_migrations'
class RunSQL(LibRunSQL):
def __init__(self, *args, hints: Optional[dict] = None, **kwargs):
super().__init__(*args, **kwargs)
self.hints = hints or {}
class RunPython(LibRunPython):
def __init__(self, *args, hints: Optional[dict] = None, **kwargs):
super().__init__(*args, **kwargs)
self.hints = hints or {}