pass a dbhelper to sqldropschema2sql to handle db specificities (closes #77664)

authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
changeset6b9b6c81b9c5
branchdefault
phasepublic
hiddenno
parent revision#0e27cf112c97 enhance error message
child revision#35284d39b5fd backport stable
files modified by this revision
__pkginfo__.py
debian/changelog
debian/control
schema2sql.py
# HG changeset patch
# User Alexandre Fayolle <alexandre.fayolle@logilab.fr>
# Date 1317372052 -7200
# Fri Sep 30 10:40:52 2011 +0200
# Node ID 6b9b6c81b9c54c7d137896f107cd77c57b8413fe
# Parent 0e27cf112c97d0b76517a5dca4ae90a5db6049f2
pass a dbhelper to sqldropschema2sql to handle db specificities (closes #77664)

diff --git a/__pkginfo__.py b/__pkginfo__.py
@@ -22,11 +22,11 @@
1 
2  # package name
3  modname = 'yams'
4 
5  # release version
6 -numversion = (0, 33, 0)
7 +numversion = (0, 34, 0)
8  version = '.'.join(str(num) for num in numversion)
9 
10  # license and copyright
11  license = 'LGPL'
12 
diff --git a/debian/changelog b/debian/changelog
@@ -1,5 +1,11 @@
13 +yams (0.34.0-1) unstable; urgency=low
14 +
15 +  * new upstream release
16 +
17 + --
18 +
19  yams (0.33.0-1) unstable; urgency=low
20 
21    * new upstream release
22 
23   -- Sylvain Thénault <sylvain.thenault@logilab.fr>  Thu, 09 Jun 2011 15:32:26 +0200
diff --git a/debian/control b/debian/control
@@ -11,10 +11,11 @@
24  XS-Python-Version: >= 2.5, << 2.7
25 
26  Package: python-yams
27  Architecture: all
28  Depends: ${python:Depends}, python-logilab-common (> 0.55.2), python-logilab-database (>= 1.5.0)
29 +Breaks: cubicweb-server (<< 3.14.0)
30  Conflicts: python-yams (<= 0.5.2)
31  XB-Python-Version: ${python:Versions}
32  Description: entity / relation schema
33   Yet Another Magic Schema !
34   A simple/generic but powerful entities / relations schema, suitable
diff --git a/schema2sql.py b/schema2sql.py
@@ -43,21 +43,23 @@
35              continue
36          w(rschema2sql(rschema))
37      return '\n'.join(output)
38 
39 
40 -def dropschema2sql(schema, skip_entities=(), skip_relations=(), prefix=''):
41 +def dropschema2sql(dbhelper, schema, skip_entities=(), skip_relations=(), prefix=''):
42      """write to the output stream a SQL schema to store the objects
43      corresponding to the given schema
44      """
45      output = []
46      w = output.append
47      for etype in sorted(schema.entities()):
48          eschema = schema.eschema(etype)
49          if eschema.final or eschema.type in skip_entities:
50              continue
51 -        w(dropeschema2sql(eschema, skip_relations, prefix=prefix))
52 +        stmts = dropeschema2sql(dbhelper, eschema, skip_relations, prefix=prefix)
53 +        for stmt in stmts:
54 +            w(stmt)
55      for rtype in sorted(schema.relations()):
56          rschema = schema.rschema(rtype)
57          if rschema.final or rschema.inlined:
58              continue
59          w(droprschema2sql(rschema))
@@ -71,15 +73,24 @@
60                for rschema in eschema.subject_relations()
61                if not rschema.final and rschema.inlined]
62      return attrs
63 
64 
65 -def dropeschema2sql(eschema, skip_relations=(), prefix=''):
66 +def dropeschema2sql(dbhelper, eschema, skip_relations=(), prefix=''):
67      """return sql to drop an entity type's table"""
68 -    # not necessary to drop indexes, that's implictly done when dropping
69 -    # the table
70 -    return 'DROP TABLE %s;' % (prefix + eschema.type)
71 +    # not necessary to drop indexes, that's implictly done when
72 +    # dropping the table, but we need to drop SQLServer views used to
73 +    # create multicol unique indices
74 +    statements = []
75 +    tablename = prefix + eschema.type
76 +    if eschema._unique_together is not None:
77 +        for unique_together in eschema._unique_together:
78 +            cols  = ['%s%s' % (prefix, col) for col in unique_together]
79 +            sqls = dbhelper.sqls_drop_multicol_unique_index(tablename, cols)
80 +            statements += sqls
81 +    statements += ['DROP TABLE %s;' % (tablename)]
82 +    return statements
83 
84 
85  def eschema2sql(dbhelper, eschema, skip_relations=(), prefix=''):
86      """write an entity schema as SQL statements to stdout"""
87      output = []