# HG changeset patch # User Sylvain Thénault # Date 1467278281 -7200 # Node ID ac166217bd8cf118ebfb0fed92db4e80c626655c # Parent 9a5a6ec5fc093772c145df6721122c7e51f07768 [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 diff -r 9a5a6ec5fc09 -r ac166217bd8c cubicweb/server/schema2sql.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 diff -r 9a5a6ec5fc09 -r ac166217bd8c cubicweb/server/sources/native.py --- 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', diff -r 9a5a6ec5fc09 -r ac166217bd8c cubicweb/server/sqlutils.py --- 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."""