mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2024-11-22 00:56:37 +03:00
Added ability to add hints to RunPython and RunSQL migration operations
This commit is contained in:
parent
01cec7c999
commit
ac8d34c261
|
@ -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.
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -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',
|
||||||
|
|
|
@ -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(LibRunSQL):
|
||||||
|
def __init__(self, *args, hints: Optional[dict] = None, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.hints = hints or {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user