Remove special case for MySQL index.
authorAntony Chazapis <chazapis@gmail.com>
Mon, 23 Jan 2012 15:00:37 +0000 (17:00 +0200)
committerAntony Chazapis <chazapis@gmail.com>
Mon, 23 Jan 2012 15:00:37 +0000 (17:00 +0200)
Refs #1836

pithos/backends/lib/sqlalchemy/node.py

index a47ec5f..e977057 100644 (file)
@@ -121,6 +121,7 @@ class Node(DBWorker):
         path_length = 2048
         columns.append(Column('path', String(path_length), default='', nullable=False))
         self.nodes = Table('nodes', metadata, *columns, mysql_engine='InnoDB')
+        Index('idx_nodes_path', self.nodes.c.path, unique=True)
         
         #create policy table
         columns=[]
@@ -179,16 +180,6 @@ class Node(DBWorker):
         
         metadata.create_all(self.engine)
         
-        # the following code creates an index of specific length
-        # this can be accompliced in sqlalchemy >= 0.7.3
-        # providing mysql_length option during index creation
-        insp = Inspector.from_engine(self.engine)
-        indexes = [elem['name'] for elem in insp.get_indexes('nodes')]
-        if 'idx_nodes_path' not in indexes:
-            explicit_length = '(%s)' %path_length if self.engine.name == 'mysql' else ''
-            s = text('CREATE UNIQUE INDEX idx_nodes_path ON nodes (path%s)' %explicit_length)
-            self.conn.execute(s).close()
-        
         s = self.nodes.select().where(and_(self.nodes.c.node == ROOTNODE,
                                            self.nodes.c.parent == ROOTNODE))
         rp = self.conn.execute(s)