mirror of
https://github.com/django/django.git
synced 2025-08-19 02:01:29 +00:00
[1.7.x] Making SQL management commands migration aware.
This commit is contained in:
parent
c5afdc3d73
commit
b6a960cd1d
7 changed files with 107 additions and 0 deletions
0
tests/commands_sql_migrations/__init__.py
Normal file
0
tests/commands_sql_migrations/__init__.py
Normal file
33
tests/commands_sql_migrations/migrations/0001_initial.py
Normal file
33
tests/commands_sql_migrations/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Comment',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Book',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
('title', models.CharField(db_index=True, max_length=100)),
|
||||
('comments', models.ManyToManyField(to='commands_sql_migrations.Comment')),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
0
tests/commands_sql_migrations/migrations/__init__.py
Normal file
0
tests/commands_sql_migrations/migrations/__init__.py
Normal file
10
tests/commands_sql_migrations/models.py
Normal file
10
tests/commands_sql_migrations/models.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Comment(models.Model):
|
||||
pass
|
||||
|
||||
|
||||
class Book(models.Model):
|
||||
title = models.CharField(max_length=100, db_index=True)
|
||||
comments = models.ManyToManyField(Comment)
|
39
tests/commands_sql_migrations/tests.py
Normal file
39
tests/commands_sql_migrations/tests.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import apps
|
||||
from django.core.management import CommandError
|
||||
from django.core.management.color import no_style
|
||||
from django.core.management.sql import (sql_create, sql_delete, sql_indexes,
|
||||
sql_destroy_indexes, sql_all)
|
||||
from django.db import connections, DEFAULT_DB_ALIAS, router
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SQLCommandsMigrationsTestCase(TestCase):
|
||||
"""Tests that apps with migrations can not use sql commands."""
|
||||
|
||||
def test_sql_create(self):
|
||||
app_config = apps.get_app_config('commands_sql_migrations')
|
||||
with self.assertRaises(CommandError):
|
||||
sql_create(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
|
||||
def test_sql_delete(self):
|
||||
app_config = apps.get_app_config('commands_sql_migrations')
|
||||
with self.assertRaises(CommandError):
|
||||
sql_delete(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
|
||||
def test_sql_indexes(self):
|
||||
app_config = apps.get_app_config('commands_sql_migrations')
|
||||
with self.assertRaises(CommandError):
|
||||
sql_indexes(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
|
||||
def test_sql_destroy_indexes(self):
|
||||
app_config = apps.get_app_config('commands_sql_migrations')
|
||||
with self.assertRaises(CommandError):
|
||||
sql_destroy_indexes(app_config, no_style(),
|
||||
connections[DEFAULT_DB_ALIAS])
|
||||
|
||||
def test_sql_all(self):
|
||||
app_config = apps.get_app_config('commands_sql_migrations')
|
||||
with self.assertRaises(CommandError):
|
||||
sql_all(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
|
Loading…
Add table
Add a link
Reference in a new issue