Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Dec 10, 2024
1 parent 583fd97 commit f882641
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
6 changes: 3 additions & 3 deletions django_mongodb/fields/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class ArrayLenTransform(Transform):
lookup_name = "len"
output_field = IntegerField()

def as_sql(self, compiler, connection):
def as_mql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
# Distinguish NULL and empty arrays
return (
Expand Down Expand Up @@ -312,7 +312,7 @@ def __init__(self, index, base_field, *args, **kwargs):
self.index = index
self.base_field = base_field

def as_sql(self, compiler, connection):
def as_mql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
if not lhs.endswith("]"):
lhs = "(%s)" % lhs
Expand All @@ -338,7 +338,7 @@ def __init__(self, start, end, *args, **kwargs):
self.start = start
self.end = end

def as_sql(self, compiler, connection):
def as_mql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
if not lhs.endswith("]"):
lhs = "(%s)" % lhs
Expand Down
7 changes: 4 additions & 3 deletions tests/model_fields_/array_default_migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import django.contrib.postgres.fields
from django.db import migrations, models

import django_mongodb


class Migration(migrations.Migration):
dependencies = []
Expand All @@ -11,7 +12,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.AutoField(
django_mongodb.fields.ObjectIdAutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
Expand All @@ -20,7 +21,7 @@ class Migration(migrations.Migration):
),
(
"field",
django.contrib.postgres.fields.ArrayField(models.IntegerField(), size=None),
django_mongodb.fields.ArrayField(models.IntegerField(), size=None),
),
],
options={},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import django.contrib.postgres.fields
from django.db import migrations, models

import django_mongodb


class Migration(migrations.Migration):
dependencies = [
("postgres_tests", "0001_initial"),
("model_fields_", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="integerarraydefaultmodel",
name="field_2",
field=django.contrib.postgres.fields.ArrayField(
models.IntegerField(), default=[], size=None
),
field=django_mongodb.fields.ArrayField(models.IntegerField(), default=[], size=None),
preserve_default=False,
),
]
9 changes: 5 additions & 4 deletions tests/model_fields_/array_index_migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import django.contrib.postgres.fields
from django.db import migrations, models

import django_mongodb


class Migration(migrations.Migration):
dependencies = []
Expand All @@ -11,7 +12,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.AutoField(
django_mongodb.fields.ObjectIdAutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
Expand All @@ -20,14 +21,14 @@ class Migration(migrations.Migration):
),
(
"char",
django.contrib.postgres.fields.ArrayField(
django_mongodb.fields.ArrayField(
models.CharField(max_length=10), db_index=True, size=100
),
),
("char2", models.CharField(max_length=11, db_index=True)),
(
"text",
django.contrib.postgres.fields.ArrayField(models.TextField(), db_index=True),
django_mongodb.fields.ArrayField(models.TextField(), db_index=True),
),
],
options={},
Expand Down
27 changes: 6 additions & 21 deletions tests/model_fields_/test_arrayfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,34 +671,19 @@ def test_adding_field_with_default(self):
}
)
def test_adding_arrayfield_with_index(self):
"""
ArrayField shouldn't have varchar_patterns_ops or text_patterns_ops indexes.
"""
table_name = "model_fields__chartextarrayindexmodel"
call_command("migrate", "model_fields_", verbosity=0)
with connection.cursor() as cursor:
like_constraint_columns_list = [
v["columns"]
for k, v in list(
connection.introspection.get_constraints(cursor, table_name).items()
)
if k.endswith("_like")
]
# Only the CharField should have a LIKE index.
self.assertEqual(like_constraint_columns_list, [["char2"]])
# All fields should have regular indexes.
with connection.cursor() as cursor:
indexes = [
c["columns"][0]
for c in connection.introspection.get_constraints(cursor, table_name).values()
if c["index"] and len(c["columns"]) == 1
]
indexes = [
c["columns"][0]
for c in connection.introspection.get_constraints(None, table_name).values()
if c["index"] and len(c["columns"]) == 1
]
self.assertIn("char", indexes)
self.assertIn("char2", indexes)
self.assertIn("text", indexes)
call_command("migrate", "model_fields_", "zero", verbosity=0)
with connection.cursor() as cursor:
self.assertNotIn(table_name, connection.introspection.table_names(cursor))
self.assertNotIn(table_name, connection.introspection.table_names(None))


class TestSerialization(SimpleTestCase):
Expand Down

0 comments on commit f882641

Please sign in to comment.