Database Upgrade 1.2.3 -> 1.3.4 fails

Issue #430 resolved
randy2009 created an issue

Hi, if i upgrade the database with: paster upgrade-db production.ini

i get

sqlalchemy.exc.IntegrityError: (IntegrityError) could not create unique index "users_group_to_perm_users_group_id_permission_id_key" DETAIL: Key (users_group_id, permission_id)=(15, 7) is duplicated.

We use postgresql.

Complete stacktrace:

{{{ #!python

Cannot retrieve rhodecode's revision. Original error was: No scm found at given path /var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/../.. You are about to perform database upgrade, make sure You backed up your database before. Continue ? [y/n]y Found current database under version control with version 3 performing upgrade step 0 attempting to do database upgrade to version 5 2012-04-25 10:53:59,101 INFO sqlalchemy.engine.base.Engine select version() 2012-04-25 10:53:59,101 INFO sqlalchemy.engine.base.Engine {} 2012-04-25 10:53:59,102 INFO sqlalchemy.engine.base.Engine select current_schema() 2012-04-25 10:53:59,102 INFO sqlalchemy.engine.base.Engine {} 2012-04-25 10:53:59,106 INFO sqlalchemy.engine.base.Engine CREATE TABLE users_group_repo_group_to_perm ( users_group_repo_group_to_perm_id SERIAL NOT NULL, users_group_id INTEGER NOT NULL, group_id INTEGER NOT NULL, permission_id INTEGER NOT NULL, PRIMARY KEY (users_group_repo_group_to_perm_id), UNIQUE (users_group_id, group_id), UNIQUE (users_group_repo_group_to_perm_id), FOREIGN KEY(users_group_id) REFERENCES users_groups (users_group_id), FOREIGN KEY(group_id) REFERENCES groups (group_id), FOREIGN KEY(permission_id) REFERENCES permissions (permission_id) )

2012-04-25 10:53:59,106 INFO sqlalchemy.engine.base.Engine {} 2012-04-25 10:53:59,117 INFO sqlalchemy.engine.base.Engine COMMIT 2012-04-25 10:53:59,119 INFO sqlalchemy.engine.base.Engine CREATE TABLE changeset_comments ( comment_id SERIAL NOT NULL, repo_id INTEGER NOT NULL, revision VARCHAR(40) NOT NULL, line_no VARCHAR(10), f_path VARCHAR(1000), user_id INTEGER NOT NULL, text VARCHAR(25000) NOT NULL, modified_at TIMESTAMP WITHOUT TIME ZONE NOT NULL, PRIMARY KEY (comment_id), FOREIGN KEY(repo_id) REFERENCES repositories (repo_id), FOREIGN KEY(user_id) REFERENCES users (user_id) )

2012-04-25 10:53:59,119 INFO sqlalchemy.engine.base.Engine {} 2012-04-25 10:53:59,126 INFO sqlalchemy.engine.base.Engine COMMIT 2012-04-25 10:53:59,128 INFO sqlalchemy.engine.base.Engine CREATE TABLE notifications ( notification_id SERIAL NOT NULL, subject VARCHAR(512), body VARCHAR(50000), created_by INTEGER, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, type VARCHAR(256), PRIMARY KEY (notification_id), FOREIGN KEY(created_by) REFERENCES users (user_id) )

2012-04-25 10:53:59,128 INFO sqlalchemy.engine.base.Engine {} 2012-04-25 10:53:59,135 INFO sqlalchemy.engine.base.Engine COMMIT 2012-04-25 10:53:59,136 INFO sqlalchemy.engine.base.Engine CREATE TABLE user_to_notification ( user_id INTEGER NOT NULL, notification_id INTEGER NOT NULL, read BOOLEAN, sent_on TIMESTAMP WITHOUT TIME ZONE, PRIMARY KEY (user_id, notification_id), UNIQUE (user_id, notification_id), FOREIGN KEY(user_id) REFERENCES users (user_id), FOREIGN KEY(notification_id) REFERENCES notifications (notification_id) )

2012-04-25 10:53:59,136 INFO sqlalchemy.engine.base.Engine {} 2012-04-25 10:53:59,141 INFO sqlalchemy.engine.base.Engine COMMIT 2012-04-25 10:53:59,142 INFO sqlalchemy.engine.base.Engine ALTER TABLE users_group_to_perm ADD CONSTRAINT users_group_to_perm_users_group_id_permission_id_key UNIQUE (users_group_id, permission_id) 2012-04-25 10:53:59,142 INFO sqlalchemy.engine.base.Engine {} 2012-04-25 10:53:59,144 INFO sqlalchemy.engine.base.Engine ROLLBACK Traceback (most recent call last): File "/var/www/rhodecode-venv/bin/paster", line 9, in <module> load_entry_point('PasteScript==1.7.5', 'console_scripts', 'paster')() File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/paste/script/command.py", line 104, in run invoke(command, command_name, options, args[1:]) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/paste/script/command.py", line 143, in invoke exit_code = runner.run(args) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/utils.py", line 647, in run return super(BasePasterCommand, self).run(args[1:]) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/paste/script/command.py", line 238, in run result = self.command() File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/init.py", line 59, in command dbmanage.upgrade() File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/db_manage.py", line 186, in upgrade getattr(UpgradeSteps(self), 'step_%s' % step)() File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/db_manage.py", line 151, in step_0 api.upgrade(db_uri, repository_path, dbversion) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/versioning/api.py", line 186, in upgrade return _migrate(url, repository, version, upgrade=True, err=err, opts) File "<string>", line 2, in _migrate File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/versioning/util/__init__.py", line 159, in with_engine return f(*a, kw) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/versioning/api.py", line 366, in _migrate schema.runchange(ver, change, changeset.step) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/versioning/schema.py", line 91, in runchange change.run(self.engine, step) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/versioning/script/py.py", line 145, in run script_func(engine) File "/var/www/rhodecode-venv/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/versions/004_version_1_3_0.py", line 51, in upgrade cons.create() File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/changeset/constraint.py", line 45, in create self.do_imports('constraintgenerator', a, *kw) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/changeset/constraint.py", line 33, in do_imports run_single_visitor(engine, visitorcallable, self, a, kw) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/changeset/databases/visitor.py", line 75, in run_single_visitor fn(element, kwargs) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/changeset/ansisql.py", line 272, in visit_migrate_unique_constraint self._visit_constraint(p, **k) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/changeset/ansisql.py", line 278, in _visit_constraint self.execute() File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/rhodecode/lib/dbmigrate/migrate/changeset/ansisql.py", line 42, in execute return self.connection.execute(self.buffer.getvalue()) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1450, in execute params) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1627, in _execute_text statement, parameters File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1697, in _execute_context context) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1690, in _execute_context context) File "/var/www/rhodecode-venv/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 335, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.IntegrityError: (IntegrityError) could not create unique index "users_group_to_perm_users_group_id_permission_id_key" DETAIL: Key (users_group_id, permission_id)=(15, 7) is duplicated. 'ALTER TABLE users_group_to_perm ADD CONSTRAINT users_group_to_perm_users_group_id_permission_id_key UNIQUE (users_group_id, permission_id)' {} }}}

Comments (4)

  1. Log in to comment