Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

schema evolution test cases

git-svn-id: http://code.djangoproject.com/svn/django/branches/schema-evolution@3647 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 450889c9a6f7da3c2fce77a0ccf4c4cea9e29710 1 parent ffac835
@keredson keredson authored
Showing with 324 additions and 0 deletions.
  1. 0  tests/evolvedbtests/__init__.py
  2. 0  tests/evolvedbtests/case01_add_field/__init__.py
  3. +1 −0  tests/evolvedbtests/case01_add_field/models.py
  4. +23 −0 tests/evolvedbtests/case01_add_field/models.py.post
  5. +16 −0 tests/evolvedbtests/case01_add_field/models.py.pre
  6. +1 −0  tests/evolvedbtests/case01_add_field/views.py
  7. 0  tests/evolvedbtests/case02_rename_field/__init__.py
  8. +1 −0  tests/evolvedbtests/case02_rename_field/models.py
  9. +17 −0 tests/evolvedbtests/case02_rename_field/models.py.post
  10. +17 −0 tests/evolvedbtests/case02_rename_field/models.py.pre
  11. +1 −0  tests/evolvedbtests/case02_rename_field/views.py
  12. 0  tests/evolvedbtests/case03_rename_model/__init__.py
  13. +1 −0  tests/evolvedbtests/case03_rename_model/models.py
  14. +18 −0 tests/evolvedbtests/case03_rename_model/models.py.post
  15. +18 −0 tests/evolvedbtests/case03_rename_model/models.py.pre
  16. +1 −0  tests/evolvedbtests/case03_rename_model/views.py
  17. 0  tests/evolvedbtests/case04_change_flag/__init__.py
  18. +1 −0  tests/evolvedbtests/case04_change_flag/models.py
  19. +26 −0 tests/evolvedbtests/case04_change_flag/models.py.post
  20. +25 −0 tests/evolvedbtests/case04_change_flag/models.py.pre
  21. +1 −0  tests/evolvedbtests/case04_change_flag/views.py
  22. 0  tests/evolvedbtests/case05_remove_field/__init__.py
  23. +1 −0  tests/evolvedbtests/case05_remove_field/models.py
  24. +16 −0 tests/evolvedbtests/case05_remove_field/models.py.post
  25. +15 −0 tests/evolvedbtests/case05_remove_field/models.py.pre
  26. +1 −0  tests/evolvedbtests/case05_remove_field/views.py
  27. +11 −0 tests/evolvedbtests/manage.py
  28. +6 −0 tests/evolvedbtests/reset_all_to_post
  29. +6 −0 tests/evolvedbtests/reset_all_to_pre
  30. +91 −0 tests/evolvedbtests/settings.py
  31. +9 −0 tests/evolvedbtests/urls.py
View
0  tests/evolvedbtests/__init__.py
No changes.
View
0  tests/evolvedbtests/case01_add_field/__init__.py
No changes.
View
1  tests/evolvedbtests/case01_add_field/models.py
View
23 tests/evolvedbtests/case01_add_field/models.py.post
@@ -0,0 +1,23 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published')
+ author = models.CharField(maxlength=200)
+ def __str__(self):
+ return self.question
+
+ # new fields
+ pub_date2 = models.DateTimeField('date published')
+
+class Choice(models.Model):
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+ votes = models.IntegerField()
+ def __str__(self):
+ return self.choice
+
+ # new fields
+ votes2 = models.IntegerField()
+ hasSomething = models.BooleanField()
+ creatorIp = models.IPAddressField()
View
16 tests/evolvedbtests/case01_add_field/models.py.pre
@@ -0,0 +1,16 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published')
+ author = models.CharField(maxlength=200)
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+ votes = models.IntegerField()
+ def __str__(self):
+ return self.choice
+
View
1  tests/evolvedbtests/case01_add_field/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0  tests/evolvedbtests/case02_rename_field/__init__.py
No changes.
View
1  tests/evolvedbtests/case02_rename_field/models.py
View
17 tests/evolvedbtests/case02_rename_field/models.py.post
@@ -0,0 +1,17 @@
+from django.db import models
+
+class Poll(models.Model):
+ """this model originally had fields named pub_date and the_author. you can use either a str
+ or a tuple for the aka value. (tuples are used if you have changed its name more than once)"""
+ question = models.CharField(maxlength=200)
+ published_date = models.DateTimeField('date published', aka=('pub_date', 'publish_date'))
+ author = models.CharField(maxlength=200, aka='the_author')
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+ number_of_votes = models.IntegerField(aka='votes')
+ def __str__(self):
+ return self.choice
View
17 tests/evolvedbtests/case02_rename_field/models.py.pre
@@ -0,0 +1,17 @@
+from django.db import models
+
+class Poll(models.Model):
+ """this model originally had fields named pub_date and the_author. you can use either a str
+ or a tuple for the aka value. (tuples are used if you have changed its name more than once)"""
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published', aka=('pub_date', 'publish_date'))
+ the_author = models.CharField(maxlength=200, aka='the_author')
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+ votes = models.IntegerField(aka='votes')
+ def __str__(self):
+ return self.choice
View
1  tests/evolvedbtests/case02_rename_field/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0  tests/evolvedbtests/case03_rename_model/__init__.py
No changes.
View
1  tests/evolvedbtests/case03_rename_model/models.py
View
18 tests/evolvedbtests/case03_rename_model/models.py.post
@@ -0,0 +1,18 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published')
+ author = models.CharField(maxlength=200)
+ def __str__(self):
+ return self.question
+
+class Option(models.Model):
+ "the original name for this model was 'Choice'"
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+ votes = models.IntegerField(aka='number_of_votes') # show that field name changes work too
+ def __str__(self):
+ return self.choice
+ class Meta:
+ aka = ('Choice', 'BadName')
View
18 tests/evolvedbtests/case03_rename_model/models.py.pre
@@ -0,0 +1,18 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published')
+ author = models.CharField(maxlength=200)
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ "the original name for this model was 'Choice'"
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+ number_of_votes = models.IntegerField(aka='number_of_votes') # show that field name changes work too
+ def __str__(self):
+ return self.choice
+ class Meta:
+ aka = ('Choice', 'OtherBadName')
View
1  tests/evolvedbtests/case03_rename_model/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0  tests/evolvedbtests/case04_change_flag/__init__.py
No changes.
View
1  tests/evolvedbtests/case04_change_flag/models.py
View
26 tests/evolvedbtests/case04_change_flag/models.py.post
@@ -0,0 +1,26 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=100)
+ pub_date = models.DateTimeField('date published')
+ author = models.CharField(maxlength=200)
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ "the original name for this model was 'Choice'"
+ poll = models.ForeignKey(Poll)
+ option = models.CharField(maxlength=400, aka='choice') # make sure aka still works
+ votes = models.IntegerField()
+ votes2 = models.IntegerField() # make sure column adds still work
+ def __str__(self):
+ return self.choice
+
+class Foo(models.Model):
+ GENDER_CHOICES = (
+ ('M', 'Male'),
+ ('F', 'Female'),
+ )
+ gender = models.CharField(maxlength=1, choices=GENDER_CHOICES, db_index=True)
+ gender2 = models.CharField(maxlength=1, null=True, unique=True)
+
View
25 tests/evolvedbtests/case04_change_flag/models.py.pre
@@ -0,0 +1,25 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published')
+ author = models.CharField(maxlength=200)
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ "the original name for this model was 'Choice'"
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200, aka='choice') # make sure aka still works
+ votes = models.IntegerField()
+ def __str__(self):
+ return self.choice
+
+class Foo(models.Model):
+ GENDER_CHOICES = (
+ ('M', 'Male'),
+ ('F', 'Female'),
+ )
+ gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
+# gender2 = models.CharField(maxlength=1)
+
View
1  tests/evolvedbtests/case04_change_flag/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0  tests/evolvedbtests/case05_remove_field/__init__.py
No changes.
View
1  tests/evolvedbtests/case05_remove_field/models.py
View
16 tests/evolvedbtests/case05_remove_field/models.py.post
@@ -0,0 +1,16 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published')
+ # author = models.CharField(maxlength=200) # we no longer care
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ poll = models.ForeignKey(Poll)
+ # make sure rename fields are not picked up in any field deletes
+ option = models.CharField(maxlength=200, aka='choice')
+ number_of_votes = models.IntegerField( aka=('votes','num_votes') )
+ def __str__(self):
+ return self.choice
View
15 tests/evolvedbtests/case05_remove_field/models.py.pre
@@ -0,0 +1,15 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+ pub_date = models.DateTimeField('date published')
+ author = models.CharField(maxlength=200)
+ def __str__(self):
+ return self.question
+
+class Choice(models.Model):
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+ votes = models.IntegerField()
+ def __str__(self):
+ return self.choice
View
1  tests/evolvedbtests/case05_remove_field/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
11 tests/evolvedbtests/manage.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+ import settings # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
View
6 tests/evolvedbtests/reset_all_to_post
@@ -0,0 +1,6 @@
+cd case01_add_field/; ln -sf models.py.post models.py; cd ..
+cd case02_rename_field/; ln -sf models.py.post models.py; cd ..
+cd case03_rename_model/; ln -sf models.py.post models.py; cd ..
+cd case04_change_flag/; ln -sf models.py.post models.py; cd ..
+cd case05_remove_field/; ln -sf models.py.post models.py; cd ..
+
View
6 tests/evolvedbtests/reset_all_to_pre
@@ -0,0 +1,6 @@
+cd case01_add_field/; ln -sf models.py.pre models.py; cd ..
+cd case02_rename_field/; ln -sf models.py.pre models.py; cd ..
+cd case03_rename_model/; ln -sf models.py.pre models.py; cd ..
+cd case04_change_flag/; ln -sf models.py.pre models.py; cd ..
+cd case05_remove_field/; ln -sf models.py.pre models.py; cd ..
+
View
91 tests/evolvedbtests/settings.py
@@ -0,0 +1,91 @@
+# Django settings for evolvedb project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+#DATABASE_ENGINE = 'sqlite3' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
+#DATABASE_NAME = '<your_path_here>/default.db' # Or path to database file if using sqlite3.
+#DATABASE_USER = '' # Not used with sqlite3.
+#DATABASE_PASSWORD = '' # Not used with sqlite3.
+#DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
+#DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
+
+DATABASE_ENGINE = 'mysql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
+DATABASE_NAME = 'evolvedb' # Or path to database file if using sqlite3.
+DATABASE_USER = '' # Not used with sqlite3.
+DATABASE_PASSWORD = '' # Not used with sqlite3.
+DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
+
+#DATABASE_ENGINE = 'postgresql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
+#DATABASE_NAME = 'evolvedb' # Or path to database file if using sqlite3.
+#DATABASE_USER = '' # Not used with sqlite3.
+#DATABASE_PASSWORD = '' # Not used with sqlite3.
+#DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
+#DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
+
+# Local time zone for this installation. All choices can be found here:
+# http://www.postgresql.org/docs/current/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
+# http://blogs.law.harvard.edu/tech/stories/storyReader$15
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT.
+# Example: "http://media.lawrence.com"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'ooh(rzy9tz@%ep!p5w7wzfu@nuxet-$m6pt(v50^wkvpxhksq0'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.load_template_source',
+ 'django.template.loaders.app_directories.load_template_source',
+# 'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.middleware.doc.XViewMiddleware',
+)
+
+ROOT_URLCONF = 'evolvedb.urls'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates".
+ # Always use forward slashes, even on Windows.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'evolvedb.case01_add_field',
+ 'evolvedb.case02_rename_field',
+ 'evolvedb.case03_rename_model',
+ 'evolvedb.case04_change_flag',
+ 'evolvedb.case05_remove_field',
+)
View
9 tests/evolvedbtests/urls.py
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+ # Example:
+ # (r'^evolvedb/', include('evolvedb.apps.foo.urls.foo')),
+
+ # Uncomment this for admin:
+# (r'^admin/', include('django.contrib.admin.urls')),
+)
Please sign in to comment.
Something went wrong with that request. Please try again.