From df7befa43dd999a1f5c3a743aadb056152747a75 Mon Sep 17 00:00:00 2001 From: Serj Zavadsky Date: Mon, 16 Jul 2018 12:31:55 +0200 Subject: [PATCH 1/4] logging config fixed (now logging is made not by `root` logger, but by 'django_migration_linter.sql_analyzer') --- django_migration_linter/migration_linter.py | 4 +++- django_migration_linter/sql_analyser.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 00a44eb..ac4169f 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -13,7 +13,7 @@ # limitations under the License. from __future__ import print_function -import logging as log +import logging import os import re from subprocess import Popen, PIPE @@ -21,6 +21,8 @@ import sys from . import utils from .sql_analyser import analyse_sql_statements +log = logging.getLogger(__name__) + class MigrationLinter(object): MIGRATION_FOLDER_NAME = 'migrations' diff --git a/django_migration_linter/sql_analyser.py b/django_migration_linter/sql_analyser.py index 636be21..f1d074f 100644 --- a/django_migration_linter/sql_analyser.py +++ b/django_migration_linter/sql_analyser.py @@ -13,7 +13,9 @@ # limitations under the License. import re -import logging as log +import logging + +log = logging.getLogger(__name__) def has_default(sql, **kwargs): From a37cef0560894ccd26ca8b374ca81aa3bde88cb1 Mon Sep 17 00:00:00 2001 From: Serj Zavadsky Date: Mon, 16 Jul 2018 12:50:41 +0200 Subject: [PATCH 2/4] logging config fixed --- django_migration_linter/migration_linter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index ac4169f..f37a5bf 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -267,9 +267,9 @@ def _main(): args = parser.parse_args() if args.verbose: - log.basicConfig(format='%(message)s', level=log.DEBUG) + logging.basicConfig(format='%(message)s', level=logging.DEBUG) else: - log.basicConfig(format='%(message)s') + logging.basicConfig(format='%(message)s') folder_name = args.django_folder[0] # Create and use linter From 0ce615ff197d547b1e72c5f9c1d67a6a0cd1b980 Mon Sep 17 00:00:00 2001 From: Serj Zavadsky Date: Tue, 29 Jan 2019 16:52:08 +0100 Subject: [PATCH 3/4] IgnoreMigration operation fix (postgres compatibility fix) --- django_migration_linter/operations.py | 72 +++++++++++++-------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/django_migration_linter/operations.py b/django_migration_linter/operations.py index 0262061..344bc73 100644 --- a/django_migration_linter/operations.py +++ b/django_migration_linter/operations.py @@ -1,36 +1,36 @@ -# Copyright 2019 3YOURMIND GmbH - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from django.db.migrations.operations.base import Operation - -IGNORE_MIGRATION_SQL = "-- dml ignores this migration" - - -class IgnoreMigration(Operation): - - reversible = True - # Must be true to be generated through the sqlmigrate command - reduces_to_sql = True - - def state_forwards(self, app_label, state): - pass - - def database_forwards(self, app_label, schema_editor, from_state, to_state): - schema_editor.execute(IGNORE_MIGRATION_SQL) - - def database_backwards(self, app_label, schema_editor, from_state, to_state): - schema_editor.execute(IGNORE_MIGRATION_SQL + "(reversed)") - - def describe(self): - return "The Django migration linter will ignore this migration" +# Copyright 2019 3YOURMIND GmbH + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.db.migrations.operations.base import Operation + +IGNORE_MIGRATION_SQL = "select 1;" + + +class IgnoreMigration(Operation): + + reversible = True + # Must be true to be generated through the sqlmigrate command + reduces_to_sql = True + + def state_forwards(self, app_label, state): + pass + + def database_forwards(self, app_label, schema_editor, from_state, to_state): + schema_editor.execute(IGNORE_MIGRATION_SQL) + + def database_backwards(self, app_label, schema_editor, from_state, to_state): + schema_editor.execute(IGNORE_MIGRATION_SQL) + + def describe(self): + return "The Django migration linter will ignore this migration" From 0c66b1cdfa14eba922b79c780a9ed3957b0d443b Mon Sep 17 00:00:00 2001 From: Serj Zavadsky Date: Tue, 29 Jan 2019 17:08:42 +0100 Subject: [PATCH 4/4] IgnoreMigration operation fix (postgres compatibility fix) --- django_migration_linter/operations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_migration_linter/operations.py b/django_migration_linter/operations.py index 344bc73..883355d 100644 --- a/django_migration_linter/operations.py +++ b/django_migration_linter/operations.py @@ -14,7 +14,7 @@ from django.db.migrations.operations.base import Operation -IGNORE_MIGRATION_SQL = "select 1;" +IGNORE_MIGRATION_SQL = "select 1; -- dml ignores this migration" class IgnoreMigration(Operation): @@ -30,7 +30,7 @@ class IgnoreMigration(Operation): schema_editor.execute(IGNORE_MIGRATION_SQL) def database_backwards(self, app_label, schema_editor, from_state, to_state): - schema_editor.execute(IGNORE_MIGRATION_SQL) + schema_editor.execute(IGNORE_MIGRATION_SQL + "(reversed)") def describe(self): return "The Django migration linter will ignore this migration"