1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

schema evolution test cases

git-svn-id: http://code.djangoproject.com/svn/django/branches/schema-evolution@3647 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Derek Anderson 2006-08-22 16:46:02 +00:00
parent ffac8356dd
commit 450889c9a6
31 changed files with 324 additions and 0 deletions

View File

View File

@ -0,0 +1 @@
models.py.pre

View File

@ -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 File

@ -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 File

@ -0,0 +1 @@
# Create your views here.

View File

@ -0,0 +1 @@
models.py.pre

View File

@ -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 File

@ -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 File

@ -0,0 +1 @@
# Create your views here.

View File

@ -0,0 +1 @@
models.py.pre

View File

@ -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 File

@ -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 File

@ -0,0 +1 @@
# Create your views here.

View File

@ -0,0 +1 @@
models.py.pre

View File

@ -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 File

@ -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 File

@ -0,0 +1 @@
# Create your views here.

View File

@ -0,0 +1 @@
models.py.pre

View File

@ -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 File

@ -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 File

@ -0,0 +1 @@
# Create your views here.

11
tests/evolvedbtests/manage.py Executable file
View File

@ -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 File

@ -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 File

@ -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 File

@ -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 File

@ -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')),
)