Skip to content

Commit 08344f7

Browse files
Barthelemyshellfly
andauthored
Update index definition to be compatible with Django 5 (#89)
* Update index definition to be compatible with Django 5 * migration * add django 5.2 to the CI and the setup file * Clean the migration * Update Python version to 3.10 * Update 0005_rename_vote_content_type_object_id_vote_vote_content_a520b4_idx_and_more.py * django versions in the CI * Proper versions in the setup * Update ci.yml to trigger CI workflow * Squashed the migrations added the missing DEFAULT_AUTO_FIELD to the tests * Fix flake8 command syntax in CI workflow --------- Co-authored-by: shellfly <[email protected]>
1 parent 99ac395 commit 08344f7

File tree

6 files changed

+61
-13
lines changed

6 files changed

+61
-13
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ jobs:
1414
strategy:
1515
max-parallel: 4
1616
matrix:
17-
django-version: [2.2.27, 3.2.12, 4.0.2]
17+
django-version: [4.2.20, 5.1.9, 5.2.1]
1818

1919
steps:
2020
- uses: actions/checkout@v2
21-
- name: Set up Python 3.9
21+
- name: Set up Python
2222
uses: actions/setup-python@v2
2323
with:
24-
python-version: "3.9"
24+
python-version: "3.12"
2525
- name: Install dependencies
2626
run: |
2727
python -m pip install --upgrade pip
2828
pip install -q Django==${{ matrix.django-version }} flake8 coverage djangorestframework
2929
- name: Lint with flake8
3030
run: |
31-
flake8 --exclude vote/migrations/* vote
31+
flake8 --exclude "vote/migrations/*" vote
3232
- name: Test with coverage
3333
run: |
3434
coverage run runtests.py

runtests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"django.contrib.sessions.middleware.SessionMiddleware",
2929
"django.contrib.auth.middleware.AuthenticationMiddleware",
3030
],
31+
DEFAULT_AUTO_FIELD='django.db.models.BigAutoField',
3132
TEMPLATES=[
3233
{
3334
"BACKEND": "django.template.backends.django.DjangoTemplates",

setup.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@
2727
"License :: OSI Approved :: Apache Software License",
2828
"Environment :: Web Environment",
2929
"Framework :: Django",
30-
"Framework :: Django :: 1.7",
31-
"Framework :: Django :: 1.8",
32-
"Framework :: Django :: 1.9",
33-
"Framework :: Django :: 1.10",
34-
"Framework :: Django :: 2.0",
35-
"Framework :: Django :: 3.0",
36-
"Framework :: Django :: 4.0",
37-
"Programming Language :: Python :: 2.7",
30+
"Framework :: Django :: 4.2",
31+
"Framework :: Django :: 5.1",
32+
"Framework :: Django :: 5.2",
3833
"Programming Language :: Python :: 3.7",
3934
"Programming Language :: Python :: 3.8",
4035
"Programming Language :: Python :: 3.9",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Generated by Django 4.2.5 on 2025-12-01 14:57
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
replaces = [('vote', '0001_initial'), ('vote', '0002_auto_20161229_1022'), ('vote', '0003_vote_action'), ('vote', '0004_auto_20170110_1150'), ('vote', '0005_alter_vote_id')]
10+
11+
initial = True
12+
13+
dependencies = [
14+
('auth', '__first__'),
15+
('contenttypes', '__first__'),
16+
]
17+
18+
operations = [
19+
migrations.CreateModel(
20+
name='Vote',
21+
fields=[
22+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
23+
('user_id', models.BigIntegerField()),
24+
('object_id', models.PositiveIntegerField()),
25+
('create_at', models.DateTimeField(auto_now_add=True)),
26+
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
27+
('action', models.PositiveSmallIntegerField(default=0)),
28+
],
29+
options={
30+
'unique_together': {('user_id', 'content_type', 'object_id', 'action')},
31+
'index_together': {('content_type', 'object_id')},
32+
},
33+
),
34+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.5 on 2025-04-17 07:15
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('vote', '0004_auto_20170110_1150'),
10+
]
11+
12+
operations = [
13+
migrations.RenameIndex(
14+
model_name='vote',
15+
new_name='vote_vote_content_a520b4_idx',
16+
old_fields=('content_type', 'object_id'),
17+
),
18+
]

vote/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Vote(models.Model):
3838

3939
class Meta:
4040
unique_together = ('user_id', 'content_type', 'object_id', 'action')
41-
index_together = ('content_type', 'object_id')
41+
indexes = [models.Index(fields=["content_type", "object_id"])]
4242

4343
@classmethod
4444
def votes_for(cls, model, instance=None, action=UP):

0 commit comments

Comments
 (0)