Skip to content

Commit 41e1ad8

Browse files
authored
fix #51 (#54)
* fix #51 * fix ci and test * fix ci
1 parent aa7a971 commit 41e1ad8

File tree

16 files changed

+40
-171
lines changed

16 files changed

+40
-171
lines changed

.github/workflows/base-test.yml

-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ jobs:
4545
flag-name: run-${{ join(matrix.*, '-') }}
4646
parallel: true
4747

48-
release:
49-
50-
needs: test
51-
uses: ./.github/workflows/release.yml
52-
5348
coveralls-finish:
5449

5550
needs: test

.github/workflows/release.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
22

33
on:
4-
workflow_call:
4+
pull_request:
5+
types: [closed]
6+
branches: [ "main" ]
7+
push:
58

69
jobs:
710
build:
11+
if: github.event.pull_request.merged == true || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
812
name: Build distribution 📦
913
runs-on: ubuntu-latest
1014

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 1.1.3
22
- Fix #50 partition by single expression raise TypeError.
3+
- Fix #51 .
34

45
### 1.1.2
56
- Use [flake8](https://flake8.pycqa.org/) to lint code.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from clickhouse_backend.patch import patch_all
2+
3+
patch_all()

clickhouse_backend/models/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from clickhouse_backend.patch import patch_all
2-
31
from .base import ClickhouseModel
42
from .engines import * # noqa: F401,F403
53
from .engines import __all__ as engines_all
@@ -17,4 +15,3 @@
1715
*fucntions_all,
1816
*indexes_all,
1917
]
20-
patch_all()

clickhouse_backend/patch/migrations.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from django.db.migrations.recorder import MigrationRecorder
1313
from django.utils.timezone import now
1414

15-
from clickhouse_backend import models
16-
1715
__all__ = ["patch_migrations", "patch_migration_recorder", "patch_migration"]
1816

1917

@@ -30,6 +28,7 @@ def Migration(self):
3028
"""
3129
if self._migration_class is None:
3230
if self.connection.vendor == "clickhouse":
31+
from clickhouse_backend import models
3332

3433
class Migration(models.ClickhouseModel):
3534
app = models.StringField(max_length=255)
@@ -65,6 +64,19 @@ def __str__(self):
6564
self._migration_class = Migration
6665
return self._migration_class
6766

67+
def has_table(self):
68+
"""Return True if the django_migrations table exists."""
69+
with self.connection.cursor() as cursor:
70+
tables = self.connection.introspection.table_names(cursor)
71+
if self.Migration._meta.db_table in tables:
72+
if self.connection.vendor == "clickhouse":
73+
# fix https://github.com/jayvynl/django-clickhouse-backend/issues/51
74+
cursor.execute(
75+
"ALTER table django_migrations ADD COLUMN IF NOT EXISTS deleted Bool"
76+
)
77+
return True
78+
return False
79+
6880
def migration_qs(self):
6981
if self.connection.vendor == "clickhouse":
7082
return self.Migration.objects.using(self.connection.alias).filter(
@@ -104,6 +116,7 @@ def flush(self):
104116
self.migration_qs.all().delete()
105117

106118
MigrationRecorder.Migration = property(Migration)
119+
MigrationRecorder.has_table = has_table
107120
MigrationRecorder.migration_qs = property(migration_qs)
108121
MigrationRecorder.record_applied = record_applied
109122
MigrationRecorder.record_unapplied = record_unapplied

tests/auth_tests/models/__init__.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
11
from .custom_permissions import CustomPermissionsUser
22
from .custom_user import CustomUser, CustomUserWithoutIsActiveField, ExtensionUser
3-
from .invalid_models import CustomUserNonUniqueUsername
43
from .is_active import IsActiveTestUser1
5-
from .minimal import MinimalUser
6-
from .no_password import NoPasswordUser
74
from .uuid_pk import UUIDUser
85
from .with_custom_email_field import CustomEmailField
9-
from .with_foreign_key import CustomUserWithFK, Email
106
from .with_integer_username import IntegerUsernameUser
11-
from .with_last_login_attr import UserWithDisabledLastLoginField
12-
from .with_many_to_many import CustomUserWithM2M, CustomUserWithM2MThrough, Organization
13-
from .with_unique_constraint import CustomUserWithUniqueConstraint
147

158
__all__ = (
169
"CustomEmailField",
1710
"CustomPermissionsUser",
1811
"CustomUser",
19-
"CustomUserNonUniqueUsername",
20-
"CustomUserWithFK",
21-
"CustomUserWithM2M",
22-
"CustomUserWithM2MThrough",
23-
"CustomUserWithUniqueConstraint",
12+
"IsActiveTestUser1",
2413
"CustomUserWithoutIsActiveField",
25-
"Email",
2614
"ExtensionUser",
2715
"IntegerUsernameUser",
28-
"IsActiveTestUser1",
29-
"MinimalUser",
30-
"NoPasswordUser",
31-
"Organization",
3216
"UUIDUser",
33-
"UserWithDisabledLastLoginField",
3417
)

tests/auth_tests/models/invalid_models.py

-21
This file was deleted.

tests/auth_tests/models/minimal.py

-6
This file was deleted.

tests/auth_tests/models/no_password.py

-21
This file was deleted.

tests/auth_tests/models/with_foreign_key.py

-27
This file was deleted.

tests/auth_tests/models/with_last_login_attr.py

-5
This file was deleted.

tests/auth_tests/models/with_many_to_many.py

-40
This file was deleted.

tests/auth_tests/models/with_unique_constraint.py

-22
This file was deleted.

tests/migrations_without_clickhousemodel/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.core.management import call_command
2+
from django.db import connection
3+
from django.test import TestCase
4+
5+
6+
class TestMigrationTable(TestCase):
7+
# Regression test for https://github.com/jayvynl/django-clickhouse-backend/issues/51
8+
def test_update_from_110(self):
9+
with connection.cursor() as cursor:
10+
cursor.execute("ALTER table django_migrations DROP COLUMN deleted")
11+
call_command("migrate", fake=True)
12+
fields = connection.introspection.get_table_description(
13+
cursor, "django_migrations"
14+
)
15+
self.assertIn("deleted", {field.name for field in fields})

0 commit comments

Comments
 (0)