Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add primary keys to some tables for BDR. #1689

Closed
wants to merge 1 commit into from

Conversation

bowlofeggs
Copy link
Contributor

fixes #1318

Signed-off-by: Patrick Uiterwijk puiterwijk@redhat.com

This patch was written by Patrick as noted above. I didn't have time to get it fully ready to merge (the migration needs a hash still), but I wanted to go ahead and post the PR since he sent it to me today. I'll clean it up soon and get it ready for review.

@bowlofeggs bowlofeggs added High priority These issues are higher priority than normal Migration Issues or pull requests that involve a database migration Refactor Issues that are a refactor to improve maintainability for Bodhi labels Jul 17, 2017
@bowlofeggs
Copy link
Contributor Author

Once the Greenwave patch is merged I'll rebase this one on top and give it a revision.

Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
@bowlofeggs
Copy link
Contributor Author

I've rebased this PR on the Greenwave patch, but the migration fails to apply on the first step due to duplicates:

INFO  [alembic.runtime.migration] Running upgrade 95ce24bed77a -> 31786efadb0a, Add primary keys for BDR.
Traceback (most recent call last):
  File "/usr/bin/alembic", line 9, in <module>
    load_entry_point('alembic==0.8.6', 'console_scripts', 'alembic')()
  File "/usr/lib/python2.7/site-packages/alembic/config.py", line 479, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/usr/lib/python2.7/site-packages/alembic/config.py", line 473, in main
    self.run_cmd(cfg, options)
  File "/usr/lib/python2.7/site-packages/alembic/config.py", line 456, in run_cmd
    **dict((k, getattr(options, k)) for k in kwarg)
  File "/usr/lib/python2.7/site-packages/alembic/command.py", line 174, in upgrade
    script.run_env()
  File "/usr/lib/python2.7/site-packages/alembic/script/base.py", line 397, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/usr/lib/python2.7/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/lib/python2.7/site-packages/alembic/util/compat.py", line 79, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "alembic/env.py", line 93, in <module>
    run_migrations_online()
  File "alembic/env.py", line 85, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/lib/python2.7/site-packages/alembic/runtime/environment.py", line 797, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/lib/python2.7/site-packages/alembic/runtime/migration.py", line 312, in run_migrations
    step.migration_fn(**kw)
  File "/home/vagrant/bodhi/alembic/versions/31786efadb0a_.py", line 17, in upgrade
    op.create_primary_key('pk_update_bug_table', 'update_bug_table', ['update_id', 'bug_id'])
  File "<string>", line 8, in create_primary_key
  File "<string>", line 3, in create_primary_key
  File "/usr/lib/python2.7/site-packages/alembic/operations/ops.py", line 265, in create_primary_key
    return operations.invoke(op)
  File "/usr/lib/python2.7/site-packages/alembic/operations/base.py", line 318, in invoke
    return fn(self, operation)
  File "/usr/lib/python2.7/site-packages/alembic/operations/toimpl.py", line 135, in create_constraint
    operation.to_constraint(operations.migration_context)
  File "/usr/lib/python2.7/site-packages/alembic/ddl/impl.py", line 180, in add_constraint
    self._exec(schema.AddConstraint(const))
  File "/usr/lib/python2.7/site-packages/alembic/ddl/impl.py", line 118, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 968, in _execute_ddl
    compiled
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) could not create unique index "pk_update_bug_table"
DETAIL:  Key (update_id, bug_id)=(38176, 17557) is duplicated.
 [SQL: 'ALTER TABLE update_bug_table ADD CONSTRAINT pk_update_bug_table PRIMARY KEY (update_id, bug_id)']

Thus, we are going to need to remove duplicates on these tables. After a quick glance at these uniqueness constraints, I think they do make logical sense to be unique since I think each relationship only makes sense to exist once in these through tables.

Not all through table relationships make sense to be unique in general though. I.e., nothing says it's inherently "wrong" to put a relationship between two objects twice in a through table. I wonder how things like that should be modeled under BDR…

@bowlofeggs
Copy link
Contributor Author

Unfortunately I don't have time to finish this right now since it's more complex than it seemed it would be (due to the duplicate entries). I'm going to close the PR, but it's still linked in the issue so the patch isn't lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High priority These issues are higher priority than normal Migration Issues or pull requests that involve a database migration Refactor Issues that are a refactor to improve maintainability for Bodhi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updates cannot be edited in staging due to BDR
2 participants