diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-07-29 23:50:57 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-07-29 23:50:57 +0000 |
| commit | 53ab0d34bb4df109c8e53bb058c26e4c95aa74c3 (patch) | |
| tree | ebd1b10e99f5661f32727dd9b1d252e5d6651c41 /openstack | |
| parent | 5e89fd2c185c586d95080b4469b2fe397fa92ed1 (diff) | |
| parent | c76be5bbfe1064e5bb351876e9915ec4cc282236 (diff) | |
| download | oslo-53ab0d34bb4df109c8e53bb058c26e4c95aa74c3.tar.gz oslo-53ab0d34bb4df109c8e53bb058c26e4c95aa74c3.tar.xz oslo-53ab0d34bb4df109c8e53bb058c26e4c95aa74c3.zip | |
Merge "Add function drop_unique_constraint()"
Diffstat (limited to 'openstack')
| -rw-r--r-- | openstack/common/db/sqlalchemy/utils.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/openstack/common/db/sqlalchemy/utils.py b/openstack/common/db/sqlalchemy/utils.py index 3ff7bdb..caf5569 100644 --- a/openstack/common/db/sqlalchemy/utils.py +++ b/openstack/common/db/sqlalchemy/utils.py @@ -18,6 +18,7 @@ # License for the specific language governing permissions and limitations # under the License. +from migrate.changeset import UniqueConstraint import sqlalchemy from sqlalchemy import Boolean from sqlalchemy import CheckConstraint @@ -191,6 +192,43 @@ def _get_not_supported_column(col_name_col_instance, column_name): return column +def drop_unique_constraint(migrate_engine, table_name, uc_name, *columns, + **col_name_col_instance): + """Drop unique constraint from table. + + This method drops UC from table and works for mysql, postgresql and sqlite. + In mysql and postgresql we are able to use "alter table" construction. + Sqlalchemy doesn't support some sqlite column types and replaces their + type with NullType in metadata. We process these columns and replace + NullType with the correct column type. + + :param migrate_engine: sqlalchemy engine + :param table_name: name of table that contains uniq constraint. + :param uc_name: name of uniq constraint that will be dropped. + :param columns: columns that are in uniq constraint. + :param col_name_col_instance: contains pair column_name=column_instance. + column_instance is instance of Column. These params + are required only for columns that have unsupported + types by sqlite. For example BigInteger. + """ + + meta = MetaData() + meta.bind = migrate_engine + t = Table(table_name, meta, autoload=True) + + if migrate_engine.name == "sqlite": + override_cols = [ + _get_not_supported_column(col_name_col_instance, col.name) + for col in t.columns + if isinstance(col.type, NullType) + ] + for col in override_cols: + t.columns.replace(col) + + uc = UniqueConstraint(*columns, table=t, name=uc_name) + uc.drop() + + def drop_old_duplicate_entries_from_table(migrate_engine, table_name, use_soft_delete, *uc_column_names): """Drop all old rows having the same values for columns in uc_columns. |
