Docker で Redash を扱っていて、バージョンアップする際、6 → 7 に上げる際に起動しなくなる。
ログを確認すると、DB のフィールドが変更になったためのエラーが出ている。
$ docker logs <container-id>
HINT: Perhaps you meant to reference the column "users.email".
[SQL: 'SELECT users.profile_image_url AS users_profile_image_url, users.groups AS users_groups, users.updated_at AS users_updated_at, users.created_at AS users_created_at, users.id AS users_id, users.org_id AS users_org_id, users.name AS users_name, users.email AS users_email, users.password_hash AS users_password_hash, users.api_key AS users_api_key, users.disabled_at AS users_disabled_at, users.details AS users_details \nFROM users \nWHERE users.id = %(id_1)s AND %(param_1)s = users.org_id'] [parameters: {'id_1': u'1', 'param_1': 1}] (Background on this error at: http://sqlalche.me/e/f405)
[2022-09-09 04:16:20,248][PID:10][ERROR][redash] Exception on /favicon.ico [GET]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1636, in full_dispatch_request
request_started.send(self)
File "/usr/local/lib/python2.7/dist-packages/blinker/base.py", line 267, in send
for receiver in self.receivers_for(sender)]
File "/app/redash/models/users.py", line 54, in update_user_active_at
if current_user.is_authenticated and not current_user.is_api_user():
File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 343, in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 302, in _get_current_object
return self.__local()
File "/usr/local/lib/python2.7/dist-packages/flask_login/utils.py", line 26, in <lambda>
current_user = LocalProxy(lambda: _get_user())
File "/usr/local/lib/python2.7/dist-packages/flask_login/utils.py", line 302, in _get_user
current_app.login_manager._load_user()
File "/usr/local/lib/python2.7/dist-packages/flask_login/login_manager.py", line 317, in _load_user
return self.reload_user()
File "/usr/local/lib/python2.7/dist-packages/flask_login/login_manager.py", line 279, in reload_user
user = self.user_callback(user_id)
File "/app/redash/authentication/__init__.py", line 63, in load_user
user = models.User.get_by_id_and_org(user_id, org)
File "/app/redash/models/mixins.py", line 28, in get_by_id_and_org
return query.one()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2954, in one
ret = self.one_or_none()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2924, in one_or_none
ret = list(self)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2995, in __iter__
return self._execute_and_instances(context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 3018, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 948, in execute
return meth(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
exc_info
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 265, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 509, in do_execute
cursor.execute(statement, parameters)
ProgrammingError: (psycopg2.ProgrammingError) column users.details does not exist
LINE 1: ..._api_key, users.disabled_at AS users_disabled_at, users.deta...
DB のマイグレーションが必要。
cd /opt/redash
sudo docker-compose exec server /bin/bash
もしくは
kubectl exec -it ${podname} -- /bin/bash
Docker コンテナ内で
redash@81a857097192:/app$ /app/bin/docker-entrypoint manage db upgrade
[2022-09-09 05:10:34,736][PID:704][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[2022-09-09 05:10:34,756][PID:704][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
[2022-09-09 05:10:36,360][PID:704][INFO][alembic.runtime.migration] Context impl PostgresqlImpl.
[2022-09-09 05:10:36,361][PID:704][INFO][alembic.runtime.migration] Will assume transactional DDL.
[2022-09-09 05:10:36,368][PID:704][INFO][alembic.runtime.migration] Running upgrade 71477dadd6ef -> 640888ce445d, Add new scheduling data.
[2022-09-09 05:10:36,451][PID:704][INFO][alembic.runtime.migration] Running upgrade 640888ce445d -> e7f8a917aa8e, Add user details JSON column.
[2022-09-09 05:10:36,467][PID:704][INFO][alembic.runtime.migration] Running upgrade e7f8a917aa8e -> 73beceabb948, bring_back_null_schedule
[2022-09-09 05:10:36,476][PID:704][INFO][alembic.runtime.migration] Running upgrade 73beceabb948 -> 98af61feea92, add_encrypted_options_to_data_sources
[2022-09-09 05:10:36,483][PID:704][INFO][alembic.runtime.migration] Running upgrade 98af61feea92 -> e5c7a4e2df4d, remove_query_tracker_keys
これで実行できる。
追記: 8 → 9 のバージョンアップの際にも、 manage db upgrade が必要。
コメント