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

Error on "alembic upgrade head" #51

Closed
fredrikaverpil opened this issue Mar 13, 2017 · 14 comments
Closed

Error on "alembic upgrade head" #51

fredrikaverpil opened this issue Mar 13, 2017 · 14 comments

Comments

@fredrikaverpil
Copy link
Contributor

fredrikaverpil commented Mar 13, 2017

I ran alembic.exe upgrade head from my Python 3.5 installation on my Windows machine and I got this error:

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade f2005d1fbadc -> 92257ba439e1, Budget is now statusable
INFO  [alembic.runtime.migration] Running upgrade 92257ba439e1 -> d8421de6a206, Added Project_Users.rate
INFO  [alembic.runtime.migration] Running upgrade d8421de6a206 -> ea28a39ba3f5, Added Invoices table
INFO  [alembic.runtime.migration] Running upgrade ea28a39ba3f5 -> 255ee1f9c7b3, Added Payments table
INFO  [alembic.runtime.migration] Running upgrade 255ee1f9c7b3 -> f16651477e64, Added AuthenticationLog class
INFO  [alembic.runtime.migration] Running upgrade f16651477e64 -> a9319b19f7be, added shot.fps
INFO  [alembic.runtime.migration] Running upgrade a9319b19f7be -> 0063f547dc2e, updated version_inputs table
INFO  [alembic.runtime.migration] Running upgrade 0063f547dc2e -> c5607b4cfb0a, Added support for time zones
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: AuthenticationLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: date
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: AuthenticationLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: SimpleEntities
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: date_created
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: date_updated
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: SimpleEntities
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Tasks
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Tasks
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Vacations
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Vacations
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Projects
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Projects
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: TimeLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: TimeLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Studios
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: scheduling_started_at
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: last_scheduled_at
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Studios
INFO  [alembic.runtime.migration] Running upgrade c5607b4cfb0a -> 31b1e22b455e, Added exclude and check constraints to TimeLogs table
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Removing duplicate TimeLog entries
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Removing contained TimeLog entries (TimeLogs surrounded by other TimeLogs
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Trimming residual overlapping TimeLog.end values
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Trimming residual overlapping TimeLog.start values
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Adding CheckConstraint(end > start) to TimeLogs table
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Adding ExcludeConstraint to TimeLogs table
DEBUG [stalker.models.task] add_exclude_constraint is Running!
DEBUG [stalker.models.task] running "btree_gist" extension creation!
DEBUG [stalker.models.task] add_exclude_constraint: (psycopg2.ProgrammingError) permission denied to create extension "btree_gist"
HINT:  Must be superuser to create this extension.
 [SQL: 'CREATE EXTENSION btree_gist;']
DEBUG [stalker.models.task] creating ts_to_box function!
Traceback (most recent call last):
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\base.py", line 1182, in _execute_context
    context)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\default.py", line 469, in do_execute
    cursor.execute(statement, parameters)
psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\users\iruser\skalman\condaenvs\skalman_py35\Scripts\alembic.exe\__main__.py", line 9, in <module>
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\config.py", line 479, in main
    CommandLine(prog=prog).main(argv=argv)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\config.py", line 473, in main
    self.run_cmd(cfg, options)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\config.py", line 456, in run_cmd
    **dict((k, getattr(options, k)) for k in kwarg)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\command.py", line 174, in upgrade
    script.run_env()
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\script\base.py", line 407, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\util\pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\util\compat.py", line 68, in load_module_py
    module_id, path).load_module(module_id)
  File "<frozen importlib._bootstrap_external>", line 396, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 817, in load_module
  File "<frozen importlib._bootstrap_external>", line 676, in load_module
  File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "alembic\env.py", line 72, in <module>
    run_migrations_online()
  File "alembic\env.py", line 65, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\runtime\environment.py", line 797, in run_migrations
    self.get_context().run_migrations(**kw)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\alembic\runtime\migration.py", line 312, in run_migrations
    step.migration_fn(**kw)
  File "C:\Users\iruser\code\repos\stalker\alembic\versions\31b1e22b455e_added_exclude_and_check_constraints_to_.py", line 123, in upgrade
    add_exclude_constraint(TimeLog.__table__, conn)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\stalker\models\task.py", line 3189, in add_exclude_constraint
    ts_to_box.execute(bind=connection)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\sql\ddl.py", line 96, in execute
    return bind.execute(self.against(target))
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\base.py", line 945, in execute
    return meth(self, multiparams, params)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\sql\ddl.py", line 68, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\base.py", line 1002, in _execute_ddl
    compiled
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\base.py", line 1189, in _execute_context
    context)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\base.py", line 1393, in _handle_dbapi_exception
    exc_info
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\util\compat.py", line 202, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\util\compat.py", line 185, in reraise
    raise value.with_traceback(tb)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\base.py", line 1182, in _execute_context
    context)
  File "c:\users\iruser\skalman\condaenvs\skalman_py35\lib\site-packages\sqlalchemy\engine\default.py", line 469, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.InternalError: (psycopg2.InternalError) current transaction is aborted, commands ignored until end of transaction block
 [SQL: "CREATE FUNCTION ts_to_box(TIMESTAMPTZ, TIMESTAMPTZ)\nRETURNS BOX\nAS\n$$\n    SELECT  BOX(\n      POINT(DATE_PART('epoch', $1), 0),\n      POINT(DATE_PART('epoch', $2 - interval '1 minute'), 1)\n    )\n$$\nLANGUAGE 'sql'\nIMMUTABLE;\n"]
@fredrikaverpil
Copy link
Contributor Author

Got a different error when attempting the alembic upgrade head with Python 2.7 on Windows:

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade f2005d1fbadc -> 92257ba439e1, Budget is now statusable
INFO  [alembic.runtime.migration] Running upgrade 92257ba439e1 -> d8421de6a206, Added Project_Users.rate
INFO  [alembic.runtime.migration] Running upgrade d8421de6a206 -> ea28a39ba3f5, Added Invoices table
INFO  [alembic.runtime.migration] Running upgrade ea28a39ba3f5 -> 255ee1f9c7b3, Added Payments table
INFO  [alembic.runtime.migration] Running upgrade 255ee1f9c7b3 -> f16651477e64, Added AuthenticationLog class
INFO  [alembic.runtime.migration] Running upgrade f16651477e64 -> a9319b19f7be, added shot.fps
INFO  [alembic.runtime.migration] Running upgrade a9319b19f7be -> 0063f547dc2e, updated version_inputs table
INFO  [alembic.runtime.migration] Running upgrade 0063f547dc2e -> c5607b4cfb0a, Added support for time zones
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Studios
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: scheduling_started_at
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: last_scheduled_at
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Studios
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Tasks
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Tasks
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Projects
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Projects
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: AuthenticationLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: date
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: AuthenticationLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: SimpleEntities
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: date_created
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: date_updated
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: SimpleEntities
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: TimeLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: TimeLogs
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] upgrading table: Vacations
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: computed_end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: start
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] altering column: end
INFO  [c5607b4cfb0a_added_support_for_time_zones_py] done upgrading table: Vacations
INFO  [alembic.runtime.migration] Running upgrade c5607b4cfb0a -> 31b1e22b455e, Added exclude and check constraints to TimeLogs table
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Removing duplicate TimeLog entries
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Removing contained TimeLog entries (TimeLogs surrounded by other TimeLogs
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Trimming residual overlapping TimeLog.end values
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Trimming residual overlapping TimeLog.start values
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Adding CheckConstraint(end > start) to TimeLogs table
INFO  [31b1e22b455e_added_exclude_and_check_constraints_to__py] Adding ExcludeConstraint to TimeLogs table
Traceback (most recent call last):
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\users\iruser\skalman\condaenvs\skalman_py27\Scripts\alembic.exe\__main__.py", line 9, in <module>
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\config.py", line 479, in main
    CommandLine(prog=prog).main(argv=argv)
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\config.py", line 473, in main
    self.run_cmd(cfg, options)
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\config.py", line 456, in run_cmd
    **dict((k, getattr(options, k)) for k in kwarg)
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\command.py", line 174, in upgrade
    script.run_env()
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\script\base.py", line 407, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\util\pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\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 72, in <module>
    run_migrations_online()
  File "alembic\env.py", line 65, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\runtime\environment.py", line 797, in run_migrations
    self.get_context().run_migrations(**kw)
  File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\runtime\migration.py", line 312, in run_migrations
    step.migration_fn(**kw)
  File "C:\Users\iruser\code\repos\stalker\alembic\versions\31b1e22b455e_added_exclude_and_check_constraints_to_.py", line 121, in upgrade
    from stalker.models.task import TimeLog, add_exclude_constraint
ImportError: cannot import name add_exclude_constraint

@fredrikaverpil
Copy link
Contributor Author

Ah, I was too fast with reporting this issue. The user in postgres was not "superuser". When associating the user with this role, the Python 3.5 command completed without issues.

@fredrikaverpil
Copy link
Contributor Author

Hm. There's no mention about the "superuser" role in the Stalker docs on "Installing a database". Should the stalker db owner have this role set at all times?

@fredrikaverpil
Copy link
Contributor Author

Figured I'd quickly mention that the upgrade of the database doesn't work in Python 2.7 even if my user has the "superuser" role. Here, I'm still seeing the ImportError for add_exclude_constraint.

@eoyilmaz
Copy link
Owner

Could you be importing the wrong Stalker version. I mean it seams to me that the alembic script is trying to import stalker.models.task.add_exclude_constraint() from the wrong version of Stalker.

File "c:\users\iruser\skalman\condaenvs\skalman_py27\lib\site-packages\alembic\runtime\migration.py", line 312, in run_migrations
...
File "C:\Users\iruser\code\repos\stalker\alembic\versions\31b1e22b455e_added_exclude_and_check_constraints_to_.py", line 121, in upgrade

@fredrikaverpil
Copy link
Contributor Author

Could you be importing the wrong Stalker version.

Probably, yes. Now when I reinstalled everything and retried this it all worked just fine without issues.

@fredrikaverpil
Copy link
Contributor Author

@eoyilmaz about the "superuser" role. Does your database owner (user) have this role?
I didn't use to have that... but I figured if this is necessary during the upgrade, I probably need it in order to successfully dump and read a dump back in, right?

@eoyilmaz
Copy link
Owner

Yes my database user has superuser role, and as you've said it is probably necessary only during the upgrade.

@fredrikaverpil
Copy link
Contributor Author

it is probably necessary only during the upgrade.

I wonder if that's really the case. I believe you actually need the supervisor role in order restore a backed up database (as in backed up via pg_dump). Perhaps it's even required in order to perform the SQL dump (backup) itself.

I feel this is something which should be in the docs. I'm now setting my stalker db user to have this supervisor role since I'm unsure how this role works.

@eoyilmaz
Copy link
Owner

eoyilmaz commented Mar 22, 2017 via email

@fredrikaverpil
Copy link
Contributor Author

Ok. Do you know why this role must be enabled during an alembic upgrade of the db?

@eoyilmaz
Copy link
Owner

eoyilmaz commented Mar 24, 2017 via email

@fredrikaverpil
Copy link
Contributor Author

Ok, thanks for clarifying! :)

@fredrikaverpil
Copy link
Contributor Author

I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants