1. Luke Plant
  2. django

Commits

dand...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 1346f55

schema evolution test cases

  • Participants
  • Parent commits b93b4b6
  • Branches schema-evolution

Comments (0)

Files changed (31)

File tests/evolvedbtests/__init__.py

Empty file added.

File tests/evolvedbtests/case01_add_field/__init__.py

Empty file added.

File tests/evolvedbtests/case01_add_field/models.py

View file
+models.py.pre

File tests/evolvedbtests/case01_add_field/models.py.post

View file
+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()

File tests/evolvedbtests/case01_add_field/models.py.pre

View file
+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
+    

File tests/evolvedbtests/case01_add_field/views.py

View file
+# Create your views here.

File tests/evolvedbtests/case02_rename_field/__init__.py

Empty file added.

File tests/evolvedbtests/case02_rename_field/models.py

View file
+models.py.pre

File tests/evolvedbtests/case02_rename_field/models.py.post

View file
+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

File tests/evolvedbtests/case02_rename_field/models.py.pre

View file
+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

File tests/evolvedbtests/case02_rename_field/views.py

View file
+# Create your views here.

File tests/evolvedbtests/case03_rename_model/__init__.py

Empty file added.

File tests/evolvedbtests/case03_rename_model/models.py

View file
+models.py.pre

File tests/evolvedbtests/case03_rename_model/models.py.post

View file
+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')

File tests/evolvedbtests/case03_rename_model/models.py.pre

View file
+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')

File tests/evolvedbtests/case03_rename_model/views.py

View file
+# Create your views here.

File tests/evolvedbtests/case04_change_flag/__init__.py

Empty file added.

File tests/evolvedbtests/case04_change_flag/models.py

View file
+models.py.pre

File tests/evolvedbtests/case04_change_flag/models.py.post

View file
+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)
+        

File tests/evolvedbtests/case04_change_flag/models.py.pre

View file
+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)
+

File tests/evolvedbtests/case04_change_flag/views.py

View file
+# Create your views here.

File tests/evolvedbtests/case05_remove_field/__init__.py

Empty file added.

File tests/evolvedbtests/case05_remove_field/models.py

View file
+models.py.pre

File tests/evolvedbtests/case05_remove_field/models.py.post

View file
+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

File tests/evolvedbtests/case05_remove_field/models.py.pre

View file
+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

File tests/evolvedbtests/case05_remove_field/views.py

View file
+# Create your views here.

File tests/evolvedbtests/manage.py

View file
+#!/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)

File tests/evolvedbtests/reset_all_to_post

View file
+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 ..
+

File tests/evolvedbtests/reset_all_to_pre

View file
+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 ..
+

File tests/evolvedbtests/settings.py

View file
+# 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',
+)

File tests/evolvedbtests/urls.py

View file
+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')),
+)