File tree Expand file tree Collapse file tree 8 files changed +48
-7
lines changed
Expand file tree Collapse file tree 8 files changed +48
-7
lines changed Original file line number Diff line number Diff line change 1919 - TOXENV=py36-django20-sqlite
2020 - TOXENV=py36-django20-mysql
2121 - TOXENV=py36-django20-postgresql
22- - TOXENV=checkqa
22+ - TOXENV=qa
2323install :
2424- pip install -U pip
2525- pip install tox codecov
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ def pk_sequence_get(model):
99 continue
1010 if not isinstance (field , models .AutoField ):
1111 continue
12- return field .db_column or field .column
12+ return (field .db_column or field .column , field .model ._meta .db_table )
13+ return (None , None )
1314
1415
1516def sequence_reset (model ):
@@ -21,7 +22,7 @@ def sequence_reset(model):
2122 supporting pre-existing models which could have been created by a
2223 migration.
2324 """
24- pk_field = pk_sequence_get (model )
25+ pk_field , table = pk_sequence_get (model )
2526 if not pk_field :
2627 return
2728
@@ -45,12 +46,12 @@ def sequence_reset(model):
4546 cursor = connection .cursor ()
4647 cursor .execute (
4748 'SELECT MAX({column}) + 1 FROM {table}' .format (
48- column = pk_field , table = model . _meta . db_table
49+ column = pk_field , table = table
4950 )
5051 )
5152 result = cursor .fetchone ()[0 ] or 0
5253 reset = 'ALTER TABLE {table} AUTO_INCREMENT = %s' % result
5354
5455 connection .cursor ().execute (
55- reset .format (column = pk_field , table = model . _meta . db_table )
56+ reset .format (column = pk_field , table = table )
5657 )
Original file line number Diff line number Diff line change 1+ """Test app for model inheritance."""
Original file line number Diff line number Diff line change 1+ from django .db import models
2+
3+
4+ class Parent (models .Model ):
5+ pass
6+
7+
8+ class Child (Parent ):
9+ name = models .CharField (max_length = 50 )
Original file line number Diff line number Diff line change 4141
4242 'dbdiff.tests.decimal_test' ,
4343 'dbdiff.tests.nonintpk' ,
44+ 'dbdiff.tests.inheritance' ,
4445)
4546
4647MIDDLEWARE_CLASSES = (
Original file line number Diff line number Diff line change 6363 "model" : " contenttypes.contenttype" ,
6464 "pk" : 8
6565},
66+ {
67+ "fields" : {
68+ "app_label" : " inheritance" ,
69+ "model" : " parent"
70+ },
71+ "model" : " contenttypes.contenttype" ,
72+ "pk" : 9
73+ },
74+ {
75+ "fields" : {
76+ "app_label" : " inheritance" ,
77+ "model" : " child"
78+ },
79+ "model" : " contenttypes.contenttype" ,
80+ "pk" : 10
81+ },
6682{
6783 "fields" : {
6884 "app_label" : " " ,
6985 "model" : " "
7086 },
7187 "model" : " contenttypes.contenttype" ,
72- "pk" : 9
88+ "pk" : 11
7389}
7490]
Original file line number Diff line number Diff line change 11from dbdiff .tests .decimal_test .models import TestModel as DecimalModel
2+ from dbdiff .tests .inheritance .models import Child , Parent
23from dbdiff .tests .nonintpk .models import Nonintpk
34
45import pytest
@@ -19,3 +20,15 @@ def test_still_first_pk():
1920@pytest .mark .dbdiff (models = [DecimalModel , Nonintpk ])
2021def test_doesnt_reset_nonintpk_which_would_fail ():
2122 assert DecimalModel .objects .count () == 0
23+
24+
25+ @pytest .mark .dbdiff (models = [Child ])
26+ def test_inheritance_sequence_reset ():
27+ assert Child .objects .count () == 0
28+ assert Child .objects .create (name = '1' ).pk == 1
29+
30+
31+ @pytest .mark .dbdiff (models = [Child ])
32+ def test_inheritance_sequence_reset_again ():
33+ assert Parent .objects .count () == 0
34+ assert Child .objects .create (name = '1' ).pk == 1
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ setenv =
3030 mysql: DJANGO_SETTINGS_MODULE =dbdiff.tests.project.settings_mysql
3131passenv = TEST_* DBDIFF_*
3232
33- [testenv:checkqa ]
33+ [testenv:qa ]
3434basepython = python2.7
3535commands =
3636 flake8 --show-source --exclude tests --max-complexity =7 --ignore =D203 dbdiff
You can’t perform that action at this time.
0 commit comments