[schema2sql] Drop most of the DB DROP related code
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 30 Jun 2016 11:18:01 +0200
changeset 11412 ac166217bd8c
parent 11411 9a5a6ec5fc09
child 11413 c172fa18565e
[schema2sql] Drop most of the DB DROP related code This code is dead for a while, it has been superseded by `sql_drop_all_user_tables`. Related to #14050899
cubicweb/server/schema2sql.py
cubicweb/server/sources/native.py
cubicweb/server/sqlutils.py
--- a/cubicweb/server/schema2sql.py	Thu Jun 30 11:00:08 2016 +0200
+++ b/cubicweb/server/schema2sql.py	Thu Jun 30 11:18:01 2016 +0200
@@ -84,26 +84,6 @@
     return '\n'.join(output)
 
 
-def dropschema2sql(dbhelper, schema, skip_entities=(), skip_relations=(), prefix=''):
-    """write to the output stream a SQL schema to store the objects
-    corresponding to the given schema
-    """
-    output = []
-    w = output.append
-    for etype in sorted(schema.entities()):
-        eschema = schema.eschema(etype)
-        if eschema.final or eschema.type in skip_entities:
-            continue
-        stmts = dropeschema2sql(dbhelper, eschema, skip_relations, prefix=prefix)
-        for stmt in stmts:
-            w(stmt)
-    for rtype in sorted(schema.relations()):
-        rschema = schema.rschema(rtype)
-        if rschema_has_table(rschema, skip_relations):
-            w(droprschema2sql(rschema))
-    return '\n'.join(output)
-
-
 def unique_index_name(eschema, attrs):
     """Return a predictable-but-size-constrained name for a multi-columns unique index on
     given attributes of the entity schema (actually, the later may be a schema or a string).
@@ -122,22 +102,6 @@
         yield attrs, unique_index_name(eschema, attrs)
 
 
-def dropeschema2sql(dbhelper, eschema, skip_relations=(), prefix=''):
-    """return sql to drop an entity type's table"""
-    # not necessary to drop indexes, that's implictly done when
-    # dropping the table, but we need to drop SQLServer views used to
-    # create multicol unique indices
-    statements = []
-    tablename = prefix + eschema.type
-    if eschema._unique_together is not None:
-        for attrs, index_name in iter_unique_index_names(eschema):
-            cols = ['%s%s' % (prefix, attr) for attr in attrs]
-            for sql in dbhelper.sqls_drop_multicol_unique_index(tablename, cols, index_name):
-                yield sql
-    statements += ['DROP TABLE %s;' % (tablename)]
-    return statements
-
-
 def eschema2sql(dbhelper, eschema, skip_relations=(), prefix=''):
     """write an entity schema as SQL statements to stdout"""
     output = []
@@ -306,13 +270,6 @@
                           'to_idx': build_index_name(table, ['eid_to'], 'idx_')}
 
 
-def droprschema2sql(rschema):
-    """return sql to drop a relation type's table"""
-    # not necessary to drop indexes, that's implictly done when dropping
-    # the table
-    return 'DROP TABLE %s_relation;' % rschema.type
-
-
 def grant_schema(schema, user, set_owner=True, skip_entities=(), prefix=''):
     """write to the output stream a SQL schema to store the objects
     corresponding to the given schema
--- a/cubicweb/server/sources/native.py	Thu Jun 30 11:00:08 2016 +0200
+++ b/cubicweb/server/sources/native.py	Thu Jun 30 11:18:01 2016 +0200
@@ -1468,19 +1468,6 @@
     return schema
 
 
-def sql_drop_schema(driver):
-    helper = get_db_helper(driver)
-    return """
-%s;
-%s
-DROP TABLE entities;
-DROP TABLE tx_entity_actions;
-DROP TABLE tx_relation_actions;
-DROP TABLE transactions;
-""" % (';'.join(helper.sqls_drop_multicol_unique_index('entities', ['extid'])),
-       helper.sql_drop_numrange('entities_id_seq'))
-
-
 def grant_schema(user, set_owner=True):
     result = ''
     for table in ('entities', 'entities_id_seq',
--- a/cubicweb/server/sqlutils.py	Thu Jun 30 11:00:08 2016 +0200
+++ b/cubicweb/server/sqlutils.py	Thu Jun 30 11:18:01 2016 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -158,25 +158,6 @@
     return '\n'.join(output)
 
 
-def sqldropschema(schema, driver, text_index=True,
-                  skip_relations=PURE_VIRTUAL_RTYPES, skip_entities=()):
-    """return the sql to drop the schema, according to the given parameters"""
-    from cubicweb.server.schema2sql import dropschema2sql
-    from cubicweb.server.sources import native
-    output = []
-    w = output.append
-    if text_index:
-        dbhelper = db.get_db_helper(driver)
-        w(dbhelper.sql_drop_fti())
-        w('')
-    w(dropschema2sql(dbhelper, schema, prefix=SQL_PREFIX,
-                     skip_entities=skip_entities,
-                     skip_relations=skip_relations))
-    w('')
-    w(native.sql_drop_schema(driver))
-    return '\n'.join(output)
-
-
 _SQL_DROP_ALL_USER_TABLES_FILTER_FUNCTION = re.compile('^(?!(sql|pg)_)').match
 def sql_drop_all_user_tables(driver_or_helper, sqlcursor):
     """Return ths sql to drop all tables found in the database system."""