Skip to content

Commit

Permalink
Merge pull request #44 from carrotquest/run-migrations-hints
Browse files Browse the repository at this point in the history
Added ability to add hints to RunPython and RunSQL migration operations
  • Loading branch information
M1ha-Shvn authored Oct 19, 2022
2 parents 01cec7c + 9fb9306 commit b2cb098
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* `--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
- 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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='django-clickhouse',
version='1.1.2',
version='1.2.0',
packages=['django_clickhouse', 'django_clickhouse.management.commands'],
package_dir={'': 'src'},
url='https://github.com/carrotquest/django-clickhouse',
Expand Down
13 changes: 13 additions & 0 deletions src/django_clickhouse/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# In order to support all operations import here
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.fields import StringField, DateField
Expand Down Expand Up @@ -176,3 +177,15 @@ def get_applied_migrations(cls, db_alias: str, migrations_package: str) -> Set[s
@classmethod
def table_name(cls):
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 {}

0 comments on commit b2cb098

Please sign in to comment.