From 969228b6943c984d5bc2645949c2aefb2d83f38a Mon Sep 17 00:00:00 2001 From: John Carter Date: Sat, 9 Mar 2019 15:41:12 +1300 Subject: [PATCH] Remove makemigrations.py, use Django instead --- CONTRIBUTING.rst | 2 +- makemigrations.py | 96 ----------------------------------------------- tox.ini | 10 ++--- 3 files changed, 5 insertions(+), 103 deletions(-) delete mode 100644 makemigrations.py diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index e06b15d26c..01ed7cd762 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -91,7 +91,7 @@ Ready to contribute? Here's how to set up `dj-stripe` for local development. 7. If your changes altered the models you may need to generate Django migrations:: - $ python makemigrations.py + $ DJSTRIPE_TEST_DB_VENDOR=sqlite ./manage.py makemigrations 8. Commit your changes and push your branch to GitHub:: diff --git a/makemigrations.py b/makemigrations.py deleted file mode 100644 index be3b18413b..0000000000 --- a/makemigrations.py +++ /dev/null @@ -1,96 +0,0 @@ -""" -Migrations creation/check tool - -Based on: https://github.com/pinax/pinax-stripe/blob/master/makemigrations.py -""" - -import os -import sys - -import django -from django.apps import apps -from django.conf import settings -from django.db import connections -from django.db.utils import OperationalError - -DEFAULT_SETTINGS = dict( - DATABASES={"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}, - DEBUG=True, - INSTALLED_APPS=[ - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.sites", - "jsonfield", - "djstripe", - ], - MIDDLEWARE_CLASSES=[ - "django.contrib.sessions.middleware.SessionMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware", - ], - ROOT_URLCONF="djstripe.urls", - SITE_ID=1, - TIME_ZONE="UTC", - USE_TZ=True, -) - - -def check_migrations(): - from django.db.migrations.autodetector import MigrationAutodetector - from django.db.migrations.executor import MigrationExecutor - from django.db.migrations.state import ProjectState - - changed = set() - - print("Checking dj-stripe migrations...") - for db in settings.DATABASES.keys(): - try: - executor = MigrationExecutor(connections[db]) - except OperationalError as ex: - sys.exit("Unable to check migrations due to database: {}".format(ex)) - - autodetector = MigrationAutodetector( - executor.loader.project_state(), ProjectState.from_apps(apps) - ) - - changed.update(autodetector.changes(graph=executor.loader.graph).keys()) - - if changed and "djstripe" in changed: - sys.exit( - "A migration file is missing. Please run " - "'python makemigrations.py' to generate it." - ) - else: - print("All migration files present.") - - -def run(*args): - """ - Check and/or create dj-stripe Django migrations. - - If --check is present in the arguments then migrations are checked only. - """ - if not settings.configured: - settings.configure(**DEFAULT_SETTINGS) - - django.setup() - - parent = os.path.dirname(os.path.abspath(__file__)) - sys.path.insert(0, parent) - - try: - args = list(args) - args.pop(args.index("--check")) - is_check = True - except ValueError: - is_check = False - - if is_check: - check_migrations() - else: - django.core.management.call_command("makemigrations", "djstripe", *args) - - -if __name__ == "__main__": - run(*sys.argv[1:]) diff --git a/tox.ini b/tox.ini index 0eac0986d2..22519f8d56 100644 --- a/tox.ini +++ b/tox.ini @@ -32,14 +32,12 @@ commands = isort {toxinidir} -c [testenv:checkmigrations] -commands = python makemigrations.py --check -deps = - Django>=2.1,<2.2 +setenv = DJSTRIPE_TEST_DB_VENDOR=sqlite +commands = ./manage.py makemigrations --check --dry-run [testenv:makemigrations] -commands = python makemigrations.py -deps = - Django>=2.1,<2.2 +setenv = DJSTRIPE_TEST_DB_VENDOR=sqlite +commands = ./manage.py makemigrations [testenv:makemessages] whitelist_externals = mkdir