Ticket #1259: magic_removal-singular_normalization.diff

File magic_removal-singular_normalization.diff, 12.6 KB (added by Tom Tobin <korpios@…>, 19 years ago)

Normalizes all table names to be singular

  • db/models/options.py

     
    77from bisect import bisect
    88import re
    99
    10 # Calculate the module_name using a poor-man's pluralization.
    11 get_module_name = lambda class_name: class_name.lower() + 's'
     10# Calculate the module_name by converting to lowercase
     11get_module_name = lambda class_name: class_name.lower()
    1212
    1313# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
    1414get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip()
  • core/management.py

     
    2929def _get_packages_insert(app_label):
    3030    from django.db import backend
    3131    return "INSERT INTO %s (%s, %s) VALUES ('%s', '%s');" % \
    32         (backend.quote_name('packages'), backend.quote_name('label'), backend.quote_name('name'),
     32        (backend.quote_name('django_package'), backend.quote_name('label'), backend.quote_name('name'),
    3333        app_label, app_label)
    3434
    3535def _get_permission_codename(action, opts):
     
    4646def _get_permission_insert(name, codename, opts):
    4747    from django.db import backend
    4848    return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \
    49         (backend.quote_name('auth_permissions'), backend.quote_name('name'), backend.quote_name('package'),
     49        (backend.quote_name('auth_permission'), backend.quote_name('name'), backend.quote_name('package'),
    5050        backend.quote_name('codename'), name.replace("'", "''"), opts.app_label, codename)
    5151
    5252def _get_contenttype_insert(opts):
    5353    from django.db import backend
    5454    return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \
    55         (backend.quote_name('content_types'), backend.quote_name('name'), backend.quote_name('package'),
     55        (backend.quote_name('django_content_type'), backend.quote_name('name'), backend.quote_name('package'),
    5656        backend.quote_name('python_module_name'), opts.verbose_name, opts.app_label, opts.module_name)
    5757
    5858def _is_valid_dir_name(s):
     
    249249
    250250    app_label = app_models[0]._meta.app_label
    251251
    252     # Delete from packages, auth_permissions, content_types.
     252    # Delete from django_package, auth_permission, django_content_type.
    253253    output.append("DELETE FROM %s WHERE %s = '%s';" % \
    254         (backend.quote_name('packages'), backend.quote_name('label'), app_label))
     254        (backend.quote_name('django_package'), backend.quote_name('label'), app_label))
    255255    output.append("DELETE FROM %s WHERE %s = '%s';" % \
    256         (backend.quote_name('auth_permissions'), backend.quote_name('package'), app_label))
     256        (backend.quote_name('auth_permission'), backend.quote_name('package'), app_label))
    257257    output.append("DELETE FROM %s WHERE %s = '%s';" % \
    258         (backend.quote_name('content_types'), backend.quote_name('package'), app_label))
     258        (backend.quote_name('django_content_type'), backend.quote_name('package'), app_label))
    259259
    260260    # Delete from the admin log.
    261261    if cursor is not None:
    262262        cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \
    263             (backend.quote_name('id'), backend.quote_name('content_types'),
     263            (backend.quote_name('id'), backend.quote_name('django_content_type'),
    264264            backend.quote_name('package')), [app_label])
    265265        if admin_log_exists:
    266266            for row in cursor.fetchall():
     
    373373
    374374    # Check that the package exists in the database.
    375375    cursor.execute("SELECT 1 FROM %s WHERE %s = %%s" % \
    376         (backend.quote_name('packages'), backend.quote_name('label')), [app_label])
     376        (backend.quote_name('django_package'), backend.quote_name('label')), [app_label])
    377377    if has_no_records(cursor):
    378378#         sys.stderr.write("The '%s' package isn't installed.\n" % app_label)
    379379        print _get_packages_insert(app_label)
     
    388388        contenttypes_seen[opts.module_name] = 1
    389389        for codename, name in perms:
    390390            cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \
    391                 (backend.quote_name('auth_permissions'), backend.quote_name('package'),
     391                (backend.quote_name('auth_permission'), backend.quote_name('package'),
    392392                backend.quote_name('codename')), (app_label, codename))
    393393            if has_no_records(cursor):
    394394#                 sys.stderr.write("The '%s.%s' permission doesn't exist.\n" % (app_label, codename))
    395395                print _get_permission_insert(name, codename, opts)
    396396        cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \
    397             (backend.quote_name('content_types'), backend.quote_name('package'),
     397            (backend.quote_name('django_content_type'), backend.quote_name('package'),
    398398            backend.quote_name('python_module_name')), (app_label, opts.module_name))
    399399        if has_no_records(cursor):
    400400#             sys.stderr.write("The '%s.%s' content type doesn't exist.\n" % (app_label, opts.module_name))
     
    403403    # Check that there aren't any *extra* permissions in the DB that the model
    404404    # doesn't know about.
    405405    cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \
    406         (backend.quote_name('codename'), backend.quote_name('auth_permissions'),
     406        (backend.quote_name('codename'), backend.quote_name('auth_permission'),
    407407        backend.quote_name('package')), (app_label,))
    408408    for row in cursor.fetchall():
    409409        try:
     
    411411        except KeyError:
    412412#             sys.stderr.write("A permission called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0]))
    413413            print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \
    414                 (backend.quote_name('auth_permissions'), backend.quote_name('package'),
     414                (backend.quote_name('auth_permission'), backend.quote_name('package'),
    415415                app_label, backend.quote_name('codename'), row[0])
    416416
    417417    # Check that there aren't any *extra* content types in the DB that the
    418418    # model doesn't know about.
    419419    cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \
    420         (backend.quote_name('python_module_name'), backend.quote_name('content_types'),
     420        (backend.quote_name('python_module_name'), backend.quote_name('django_content_type'),
    421421        backend.quote_name('package')), (app_label,))
    422422    for row in cursor.fetchall():
    423423        try:
     
    425425        except KeyError:
    426426#             sys.stderr.write("A content type called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0]))
    427427            print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \
    428                 (backend.quote_name('content_types'), backend.quote_name('package'),
     428                (backend.quote_name('django_content_type'), backend.quote_name('package'),
    429429                app_label, backend.quote_name('python_module_name'), row[0])
    430430database_check.help_doc = "Checks that everything is installed in the database for the given model module name(s) and prints SQL statements if needed."
    431431database_check.args = APP_ARGS
  • contrib/contenttypes/models.py

     
    77    class Meta:
    88        verbose_name = _('package')
    99        verbose_name_plural = _('packages')
    10         db_table = 'packages'
     10        db_table = 'django_package'
    1111        ordering = ('name',)
    1212
    1313    def __repr__(self):
     
    2020    class Meta:
    2121        verbose_name = _('content type')
    2222        verbose_name_plural = _('content types')
    23         db_table = 'content_types'
     23        db_table = 'django_content_type'
    2424        ordering = ('package', 'name')
    2525        unique_together = (('package', 'python_module_name'),)
    2626
  • contrib/auth/models.py

     
    132132            # The SQL below works out to the following, after DB quoting:
    133133            # cursor.execute("""
    134134            #     SELECT p.package, p.codename
    135             #     FROM auth_permissions p, auth_groups_permissions gp, auth_users_groups ug
     135            #     FROM auth_permission p, auth_group_permissions gp, auth_user_groups ug
    136136            #     WHERE p.id = gp.permission_id
    137137            #         AND gp.group_id = ug.group_id
    138138            #         AND ug.user_id = %s""", [self.id])
     
    143143                    AND gp.%s = ug.%s
    144144                    AND ug.%s = %%s""" % (
    145145                backend.quote_name('package'), backend.quote_name('codename'),
    146                 backend.quote_name('auth_permissions'), backend.quote_name('auth_groups_permissions'),
     146                backend.quote_name('auth_permission'), backend.quote_name('auth_group_permissions'),
    147147                backend.quote_name('auth_users_groups'), backend.quote_name('id'),
    148148                backend.quote_name('permission_id'), backend.quote_name('group_id'),
    149149                backend.quote_name('group_id'), backend.quote_name('user_id'))
  • contrib/redirects/models.py

     
    1111    class Meta:
    1212        verbose_name = _('redirect')
    1313        verbose_name_plural = _('redirects')
    14         db_table = 'django_redirects'
     14        db_table = 'django_redirect'
    1515        unique_together=(('site', 'old_path'),)
    1616        ordering = ('old_path',)
    1717    class Admin:
  • contrib/comments/models.py

     
    8686    site = models.ForeignKey(Site)
    8787    objects = CommentManager()
    8888    class Meta:
    89         db_table = 'comments'
    9089        verbose_name = _('Comment')
    9190        verbose_name_plural = _('Comments')
    9291        ordering = ('-submit_date',)
     
    173172    approved = models.BooleanField(_('approved by staff'))
    174173    site = models.ForeignKey(Site)
    175174    class Meta:
    176         db_table = 'comments_free'
    177175        verbose_name = _('Free comment')
    178176        verbose_name_plural = _('Free comments')
    179177        ordering = ('-submit_date',)
     
    266264    flag_date = models.DateTimeField(_('flag date'), auto_now_add=True)
    267265    objects = UserFlagManager()
    268266    class Meta:
    269         db_table = 'comments_user_flags'
    270267        verbose_name = _('User flag')
    271268        verbose_name_plural = _('User flags')
    272269        unique_together = (('user', 'comment'),)
     
    279276    comment = models.ForeignKey(Comment)
    280277    deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True)
    281278    class Meta:
    282         db_table = 'comments_moderator_deletions'
    283279        verbose_name = _('Moderator deletion')
    284280        verbose_name_plural = _('Moderator deletions')
    285281        unique_together = (('user', 'comment'),)
  • contrib/flatpages/models.py

     
    1414    registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
    1515    sites = models.ManyToManyField(Site)
    1616    class Meta:
    17         db_table = 'django_flatpages'
     17        db_table = 'django_flatpage'
    1818        verbose_name = _('flat page')
    1919        verbose_name_plural = _('flat pages')
    2020        ordering = ('url',)
  • contrib/sessions/models.py

     
    3737    expire_date = models.DateTimeField(_('expire date'))
    3838    objects = SessionManager()
    3939    class Meta:
    40         db_table = 'django_sessions'
     40        db_table = 'django_session'
    4141        verbose_name = _('session')
    4242        verbose_name_plural = _('sessions')
    4343        module_constants = {
  • contrib/sites/models.py

     
    1111    name = models.CharField(_('display name'), maxlength=50)
    1212    objects = SiteManager()
    1313    class Meta:
    14         db_table = 'sites'
     14        db_table = 'django_site'
    1515        verbose_name = _('site')
    1616        verbose_name_plural = _('sites')
    1717        ordering = ('domain',)
Back to Top