#16448: Single sequence for every table
-------------------------+----------------------------------------------
 Reporter:  wiesiek@…    |          Owner:  nobody
     Type:  New feature  |         Status:  new
Milestone:               |      Component:  Database layer (models, ORM)
  Version:  1.3          |       Severity:  Normal
 Keywords:               |   Triage Stage:  Unreviewed
Has patch:  0            |  Easy pickings:  0
    UI/UX:  0            |
-------------------------+----------------------------------------------
 Hi,
 I am a newbie in Django,
 but IMHO in database layer design Django does not follow DRY principle.
 I do not understand, why Django uses different sequence for every table.
 Having single sequence for all tables is much better than having
 sequences for different tables regarding
 maintenance, sharding, security et.c. I give you and example package,
 that can greatly simplify many mentioned tasks.
 Just use django_seq as id generator on any django table

 CREATE OR REPLACE PACKAGE django_seq IS

   FUNCTION NEXTVAL RETURN NUMBER;
   FUNCTION CURRVAL RETURN NUMBER;
 END django_seq;
 /
 CREATE OR REPLACE PACKAGE BODY django_seq IS

   last_val NUMBER;
   shard_no NUMBER;

   FUNCTION NEXTVAL RETURN NUMBER IS
   BEGIN
     SELECT to_number(to_char(mr_inne_seq.nextval) || lpad(shard_no, 4,
 '0')) ||
            ltrim(to_char(MOD(abs(hsecs), 1000000), '000000'))
       INTO last_val
       FROM sys.v_$timer;
     RETURN last_val;
   END;

   FUNCTION CURRVAL RETURN NUMBER IS
     no_current_value EXCEPTION;
     PRAGMA EXCEPTION_INIT(no_current_value, -8002);
   BEGIN
     IF (last_val IS NULL) THEN
       RAISE no_current_value;
     END IF;
     RETURN last_val;
   END CURRVAL;

 BEGIN
   --- the code below can use database table lookup
   shard_no := 5;

 END django_seq;
 /

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16448>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to