Merge pull request #14 from 3YOURMIND/only-consider-added-migrations

Only consider added migrations
This commit is contained in:
David Wobrock authored and GitHub committed 2018-01-20 15:57:42 +01:00
commit cbbcdc2e2c
66 files changed
+325 -7

No files matched your search

+8 -6
View File
@@ -125,16 +125,16 @@ class MigrationLinter(object):
Even if calling a shell is slow and ugly, for now,
it allows to seperate the instances correctly.
"""
git_diff_command = (
sqlmigrate_command = (
'cd {0} && '
'{1} manage.py sqlmigrate {2} {3} '
'--database {4}').format(
self.django_path,
self.python_exe, app_name, migration_name,
self.database)
log.info('Executing {0}'.format(git_diff_command))
log.info('Executing {0}'.format(sqlmigrate_command))
sqlmigrate_process = Popen(
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
sqlmigrate_command, shell=True, stdout=PIPE, stderr=PIPE)
sql_statements = []
for line in map(
@@ -152,14 +152,16 @@ class MigrationLinter(object):
def _gather_migrations_git(self, git_commit_id):
migrations = []
# Get changes since specified commit
git_diff_command = 'cd {0} && git diff --name-only {1}'.format(
self.django_path, git_commit_id)
git_diff_command = (
'cd {0} && '
'git diff --name-only --diff-filter=A {1}').format(
self.django_path, git_commit_id)
log.info('Executing {0}'.format(git_diff_command))
diff_process = Popen(
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
for line in map(
utils.clean_bytes_to_str, diff_process.stdout.readlines()):
# Only gather lines that include migrations
# Only gather lines that include added migrations
if re.search(
'\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME),
line) and \
+4 -1
View File
@@ -38,6 +38,8 @@ MULTI_COMMIT_PROJECT = os.path.join(
_FIXTURES_FOLDER, 'test_project_multi_commit/')
CORRECT_PROJECT = os.path.join(
_FIXTURES_FOLDER, 'test_correct_project/')
DELETED_MIGRATION_PROJECT = os.path.join(
_FIXTURES_FOLDER, 'test_deleted_migration_project/')
NOT_DJANGO_GIT_PROJECT = os.path.join(
_FIXTURES_FOLDER, 'test_git_project/')
@@ -46,7 +48,8 @@ NOT_GIT_DJANGO_PROJECT = os.path.join(
ALL_GIT_PROJECTS = (
NOT_DJANGO_GIT_PROJECT,
MULTI_COMMIT_PROJECT
MULTI_COMMIT_PROJECT,
DELETED_MIGRATION_PROJECT
)
+15
View File
@@ -129,3 +129,18 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertEqual(len(lines), 3)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].startswith('*** Summary'))
def test_call_linter_with_deleted_migrations(self):
cmd = '{0} {1} 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba'.format(
self.linter_exec,
fixtures.DELETED_MIGRATION_PROJECT)
fixtures.prepare_git_project(fixtures.DELETED_MIGRATION_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
process.wait()
self.assertEqual(process.returncode, 0)
lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines()))
self.assertEqual(len(lines), 3)
self.assertTrue(lines[0].endswith('OK'))
self.assertTrue(lines[1].startswith('*** Summary'))
@@ -0,0 +1,3 @@
*.pyc
__pycache__/
*sqlite3
@@ -0,0 +1,16 @@
Delete file and insert new
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Thu Jan 18 23:27:37 2018 +0100
#
# On branch master
# Changes to be committed:
# deleted: test_app/migrations/0002_new_not_null_field.py
# new file: test_app/migrations/0003_new_nullable_field.py
# modified: test_app/models.py
#
# Untracked files:
# git/
#
@@ -0,0 +1 @@
ref: refs/heads/master
@@ -0,0 +1 @@
154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba
@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
@@ -0,0 +1,4 @@
0000000000000000000000000000000000000000 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e David-Wobrock <david.wobrock@gmail.com> 1516314144 +0100 commit (initial): Project init
0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock <david.wobrock@gmail.com> 1516314322 +0100 commit: Add backward incompatible migration
154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock <david.wobrock@gmail.com> 1516314457 +0100 commit: Delete file and insert new
be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock <david.wobrock@gmail.com> 1516459290 +0100 commit (amend): Delete file and insert new
@@ -0,0 +1,4 @@
0000000000000000000000000000000000000000 0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e David-Wobrock <david.wobrock@gmail.com> 1516314144 +0100 commit (initial): Project init
0395cbee60f2ea1b97f42ebdd43991c8f5d8d76e 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba David-Wobrock <david.wobrock@gmail.com> 1516314322 +0100 commit: Add backward incompatible migration
154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba be2fae887ee7ecd2d1e6371af1a865c17414bde9 David-Wobrock <david.wobrock@gmail.com> 1516314457 +0100 commit: Delete file and insert new
be2fae887ee7ecd2d1e6371af1a865c17414bde9 4bdc4ba9e7695893423be1b54f3101d6ccbd11c7 David-Wobrock <david.wobrock@gmail.com> 1516459290 +0100 commit (amend): Delete file and insert new
@@ -0,0 +1,2 @@
x¥�;
1@­sŠéÅ%gC"ÀÎ:ŸY�kQ¯ïŠG°|¯x/I­¥z\õÆ �s²dR´}ÐVóHqrÙzãÜ™ÉkRáÙ¯Òà^%oΛ¤vù‹Ãû‡‡K␍å>$©{Àí ‰`­QkµØeÜù�„:5¹qêP¥«J>ñ
@@ -0,0 +1,3 @@
x]PËjÃ0ìÙ_±�ƒ�;Ôm øRrÈ­·„m­�ZY2zÒ¯¯dåY„˜™�™UÃee™?Ì }L¡•”‰~Öté«G¢¼£@U¤ÐaóU‹^B‘Eö RÀ2/^Ò"O—%O«¼Œ:% ¤³Æ*$Ø0JeÀ
æÌ‘pfœ×QÒÉ/£ÍY7°Þ…1)ô7à•QËk­a¦’«(»€óU�;L0Ãj|(‹£8¢ (Z†ÚŸ“ð89úí|à…ñ67o
Ýú{_&™&=ï�¨¬âu¼¸C;†œê*„a¸“˜Ñø¼U¶¶Fn½4©Ý‹´S­|錊␍µ:’o<ž�ÊmÅ~±Úºßs’T�ÔHB‰Ý&žÏï{øÐ$–s2UºFï„ÁUH÷‚)ãÿüájwr>Dqá£&
@@ -0,0 +1 @@
x¥ŽKJD1Eg5›ü^> ¢àWª*mèÎK¢½}Ÿ¸g÷ÜÁáÐè½-°Á>¬)Õn”8PŽ"¹ZD'…LJ^2»èÅbv5IT7œ²/Ð.oTD‚®VД«·R˜½ËÙPª'ŽA~­Ï1á¿?}Œ2]à™ñtÿÃ×sÇv=Ñè/`6œñÎZxÔFku¼Gè’(Ô3¤Ë'CÛå␍W+W�ÞÎó˜cW?hþVd
@@ -0,0 +1,2 @@
x]OÁj„0ì9_ñ \QÙ‚,xXºlÙÃÞz+"Ѽ•´1‘D ö뛘ݵÛwafÞ̼F¨¶ÅËÓ3¼¡DMGdÐÌpø¤²S�'i’�’�§Y±I³MV@žïò-!­z`‹,a␍ð~Pz„žwÖƒ+ibèCa!­ ÆÀùF…«(¹ƒÑްÃ%9P»žÐc ” eËÑXâcVžSƒ+íùñªÑ^uveÂeÓñn$í± öAü€^8
fJâ…þ␍΂ÛUÉ~ÕÑICju»„°Ò•Žaм§z®¿p¾"µ½Šÿ`y¤ÂXÉ7êF¬}‰Ó!ˆ¢Ç.4 ä$D½TZ£OrĵOw‚%ãÿ~µÚ]�+ò ␍¢�m
@@ -0,0 +1,2 @@
x�ޱ
Â0E]íW¼± RAÈ …‚ƒ›{Hš×´ò’H’¢ŸocÄÉñ^Îá^E^A]ïW}ðôU:ã™V0Ú› ¬×H±(:’1±\2;çº:k7‰~DÒÀß0;¹„C›Û2ü&¬fïÂù$þ“ZIñcuƒ /M*B‘0¦ßÑf&–E+‚Й4ðÝv_ž<4Si
@@ -0,0 +1 @@
xU�Ak„0…{öW ìA·¨¨]l<JK½õVJˆf””8‘)ý÷Mâ®íæÞ¼yßK:¥;8ÕÅÍ²Û z-$�␍¬vȼà ␍·( û�§/N£†2/˼MPå}VYU»kswŠ£'`lXíj�1�Ó¬�…•¤ G¦¤uij‰6£y¹è.¾IŽ&5-)LnÁ;£^ñe�·Ë(ù3å»xl¢Ü8# ¤^â-|Ñ’ØâbŸç8…¸(ŠŠq!á7#m­J±A¢ñ1␍KŸ[ žýó}£«¸…xö‹ÉÎò¼ÐžŸ°�y¼EzÝŸM␍h‡å�Â3úÚê´Û7ä¯dqD³‘|ÛöݬxîêC÷Ú¿ºÁ‹U
@@ -0,0 +1,3 @@
x]�ÍjÃ0„{ÖS,ô !«LÀ‡BHé¡·ÞJ1R´1
òÊX
¥oßHnÝŸ=ÎÎ~3k|0p×Ê›[xDÂY'´`>`Ö4PBŠ�’M»•ͶiA©�ºgì4‡l± kÀ�S˜Œn¸2\ XÃ,úÈ;z#<¯ª“XÅÍŽ1¸ŽÅ É"FèൈyQñ„1õzšx␍\JÙôŽ\rÚóM]\o !Lù�\áÏý¯Ðk½­Vx(u{Ò#v\ó™õ<‹JøÞÓÅ{m<ö§Løg+Z·ü-ž(á€ó’”Ϻ—ù‚_]3t­ý ¡¢o�
@@ -0,0 +1 @@
x+)JMU04±`040031Qˆ�ÏÌË,‰�×+¨dx6÷ÑìM¯9{wk®+�ºqèIOðD¨²âÔ’’̼ôb�²)ûw—Ê<hý¶~ÇÑ3ËŠ*§Ÿõm†*+-Ê+)Ž}z»ûè÷š›O×�KÚúüÄm¶wP%åÅé™ S0°È.Ø~§å´ø¾ ‹¦ƒ)ÒE[^‚D_
@@ -0,0 +1,3 @@
x]�ЭjУ0�{жS,є !ЋPLР�BHщЁЗоJ1RД1
ђЪX
ЅoпHnн�=ЮЮ~3k|0pзЪ�[xDТY'Д`>`ж4PB���MЛ�ЭЖiAЉ�Кgь4�lБ kР�S��nИ2\ XУ,њШ;z#<ЏЊ�XХЭ�1И�Х Щ"FшрЕ�yQё�1ѕz�x␍\Jйє�\rкѓM]\o !Lљ�\сЯ§ЏаkН­Vx(u{в#v\ѓ�ѕ<�JјогХ{m<іЇLјg+ZЗќ-�(с�ѓ��ЯК�љ�_]3t­§ Ђ№o�
@@ -0,0 +1 @@
x¥ŽAn1 EYçÞ£¢1N2Œ„*Ü¡kÇvÚˆ™ JÓrýâ]¾÷¥§/uYJ‡c ]of@¢j^#“ž‚¤ƒ÷qœÐ&’ñdÂB¦ÁݹÙÚa[MrDœèD(a¦ØÛ8L)'�Èž}bÇ?ý«6¸òoÑ·�šZ•œõ‰‡Ç /Ÿ —ù uyߺ ½#ì·Ùíh·$ÜÕfë¹Ì¼*”õÛZ‡Õî7zRY
@@ -0,0 +1,2 @@
xm�AkĂ0 …wöŻ>µĐĹt �íJÇÖÚ±câÄJęb[ÁVŰíß/I[ča'!žôľ'•ŽJx|xş“RŠďÍb …Ú6PSgcĚçm¤=V —š ±dŔź–&ŕÂyY;§K‡ hđdďŃÁQG;HA{4Pşmť­4[
EŃů˝uDOÁ†î(tć6AmN !Šs›ž•2TĄĚěuhčš©"Ż0¨i6ťŞť�”ÁÖŃŻÇŔꔫD¦°ľĄČ@I�:’‡łKVuđ¬�Ë@�ś÷}~UJ†ŁŤ˛„l°ÖÇ#9{]-ÖůfľÝ.W‹Mţąž}}Ěĺäđ?�Mîm‡Ó®íM؆&ɱ7 x�˙řٱř°č™ž
@@ -0,0 +1 @@
4bdc4ba9e7695893423be1b54f3101d6ccbd11c7
@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_deleted_migration_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,5 @@
from django.apps import AppConfig
class TestAppConfig(AppConfig):
name = 'test_app'
@@ -0,0 +1,21 @@
# Generated by Django 2.0.1 on 2018-01-18 22:24
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='A',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('null_field', models.IntegerField(null=True)),
],
),
]
@@ -0,0 +1,15 @@
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [('test_app', '0001_initial'),]
operations = [
migrations.AddField(
model_name='a',
name='new_char_nullable_test_field',
field=models.CharField(max_length=30, null=True),
),
]
@@ -0,0 +1,6 @@
from django.db import models
class A(models.Model):
null_field = models.IntegerField(null=True)
new_not_null_field = models.IntegerField(null=False)
new_char_nullable_test_field = models.CharField(max_length=30, null=True)
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
@@ -0,0 +1,120 @@
"""
Django settings for test_deleted_migration_project project.
Generated by 'django-admin startproject' using Django 1.11.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'gtb+mohs%gf0+#fr89vw7e&#edmv=q8!iv+n&j_soawk$tkj3^'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'test_app'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'test_deleted_migration_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'test_deleted_migration_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django_fake_database_backends.backends.mysql',
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
@@ -0,0 +1,21 @@
"""linter_test_project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
@@ -0,0 +1,16 @@
"""
WSGI config for linter_test_project project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_deleted_migration_project.settings")
application = get_wsgi_application()