#28451: Change in Oracle sequence name truncation causes regression when
updating
existing database
-------------------------------------+-------------------------------------
Reporter: Kevin Grinberg | Owner: Kevin
| Grinberg
Type: Bug | Status: assigned
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):
We'll put the upgrade script here:
{{{#!python
from django.db import connection
from django.db.backends.utils import strip_quotes, truncate_name
for seq in connection.introspection.sequence_list():
name_length = 27
table, column = seq['table'], seq['column']
if len(table) >= name_length:
with connection.cursor() as cursor:
# 1.11.[1-4] format
old_sq_name = truncate_name('%s_SQ' % strip_quotes(table),
name_length).upper()
# pre-1.11, 1.11.5+
new_sq_name = '%s_SQ' % truncate_name(strip_quotes(table),
name_length).upper()
cursor.execute('SELECT sequence_name FROM user_sequences WHERE
sequence_name=%s', [old_sq_name])
row = cursor.fetchone()
if row:
cursor.execute('RENAME %s TO %s' % (old_sq_name,
new_sq_name))
args = {
'new_tr_name': '%s_TR' %
truncate_name(strip_quotes(table), name_length).upper(),
'tbl_name': table.upper(),
'sq_name': new_sq_name,
'col_name': column.upper(),
}
old_tr_name = truncate_name('%s_TR' % strip_quotes(table),
name_length).upper()
cursor.execute('DROP TRIGGER %s' % old_tr_name)
trigger_sql = """
CREATE OR REPLACE TRIGGER "%(new_tr_name)s"
BEFORE INSERT ON %(tbl_name)s
FOR EACH ROW
WHEN (new.%(col_name)s IS NULL)
BEGIN
SELECT "%(sq_name)s".nextval
INTO :new.%(col_name)s FROM dual;
END;
/""" % args
cursor.execute(trigger_sql)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28451#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.741e0ea27bf3a5aaad8dfc6d67438700%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.