1. Olemis Lang
  2. bloodhound-mq

Commits

Olemis Lang  committed e377e26

BH Multiproduct #333: Include auto incremented columns in model-generated schema. Generate multi-product schema from models

  • Participants
  • Parent commits 3459851
  • Branches t333_mp_gen_schema

Comments (0)

Files changed (3)

File series

View file
  • Ignore whitespace
+t333/t333_r1427886_schema_autoinc.diff
+t333/t333_r1427886_mp_gen_schema.diff

File t333/t333_r1427886_mp_gen_schema.diff

View file
  • Ignore whitespace
+# HG changeset patch
+# Parent 3f53561a2a08f85cf3f0faefca00e18aa899fa13
+BH Multiproduct #333 : Generate multi-product DB schema from model meta-data
+
+diff -r 3f53561a2a08 bloodhound_multiproduct/multiproduct/api.py
+--- a/bloodhound_multiproduct/multiproduct/api.py	Thu Jan 03 00:36:35 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Thu Jan 03 00:38:12 2013 -0500
+@@ -31,7 +31,7 @@
+ from trac.util.translation import _, N_
+ from trac.web.chrome import ITemplateProvider
+ 
+-from multiproduct.model import Product
++from multiproduct.model import Product, ProductResourceMap
+ 
+ DB_VERSION = 2
+ DB_SYSTEM_KEY = 'bloodhound_multi_product_version'
+@@ -43,20 +43,9 @@
+     implements(IEnvironmentSetupParticipant, ITemplateProvider,
+             IPermissionRequestor, ITicketFieldProvider, IResourceManager)
+     
+-    SCHEMA = [
+-        Table('bloodhound_product', key = ['prefix', 'name']) [
+-            Column('prefix'),
+-            Column('name'),
+-            Column('description'),
+-            Column('owner'),
+-            ],
+-        Table('bloodhound_productresourcemap', key = 'id') [
+-            Column('id', auto_increment=True),
+-            Column('product_id'),
+-            Column('resource_type'),
+-            Column('resource_id'),
+-            ]
+-        ]
++    SCHEMA = [modelcls._get_schema() \
++                for modelcls in (Product, ProductResourceMap)]
++    del modelcls
+     
+     def get_version(self):
+         """Finds the current version of the bloodhound database schema"""
+diff -r 3f53561a2a08 bloodhound_multiproduct/multiproduct/model.py
+--- a/bloodhound_multiproduct/multiproduct/model.py	Thu Jan 03 00:36:35 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/model.py	Thu Jan 03 00:38:12 2013 -0500
+@@ -86,6 +86,7 @@
+             'non_key_fields':['product_id','resource_type','resource_id',],
+             'no_change_fields':['id',],
+             'unique_fields':[],
++            'auto_inc':['id'],
+             }
+     
+     def reparent_resource(self, product=None):

File t333/t333_r1427886_schema_autoinc.diff

View file
  • Ignore whitespace
+# HG changeset patch
+# Parent d143652322b7ec13c6bd1f0b7aaf7fa01297ba6a
+BH Dashboard #333 : Consider auto_increment when generating schema from model metadata
+
+diff -r d143652322b7 bloodhound_dashboard/bhdashboard/model.py
+--- a/bloodhound_dashboard/bhdashboard/model.py	Wed Jan 02 18:06:37 2013 +0000
++++ b/bloodhound_dashboard/bhdashboard/model.py	Thu Jan 03 00:51:31 2013 -0500
+@@ -232,7 +232,9 @@
+     
+     @classmethod
+     def _get_schema(cls):
+-        fields =  [Column(field) for field in cls._get_fields()]
++        fields =  [Column(field, \
++                        auto_increment=field in cls._meta.get('auto_inc', [])) \
++                for field in cls._get_fields()]
+         return Table(cls._meta['table_name'], key=set(cls._meta['key_fields'] +
+                             cls._meta['unique_fields'])) [fields]
+ 
+diff -r d143652322b7 bloodhound_multiproduct/tests/model.py
+--- a/bloodhound_multiproduct/tests/model.py	Wed Jan 02 18:06:37 2013 +0000
++++ b/bloodhound_multiproduct/tests/model.py	Thu Jan 03 00:51:31 2013 -0500
+@@ -159,6 +159,6 @@
+         product.description = new_description
+         self.assertEqual(new_description, product.description)
+ 
+-if __name__ == '__main_':
++if __name__ == '__main__':
+     unittest.main()
+