redash: DB migration failed (change type of json fields from varchar to json) in the latest Docker image
Issue Summary
After upgrading to the latest Redash Docker image, the db migration process failed. It might be related to the recent commit ec1c4d07deca7b9b8a49504a28f0a00a0feb59ab.
Steps to Reproduce
- Update to the latest Docker image.
- run command
docker-compose run --rm server manage db upgrade.
[2024-01-15 21:56:29,506][PID:3862][INFO][xmlschema] Resource 'XMLSchema.xsd' is already loaded
[2024-01-15 21:56:30,190][PID:3862][INFO][alembic.runtime.migration] Context impl PostgresqlImpl.
[2024-01-15 21:56:30,190][PID:3862][INFO][alembic.runtime.migration] Will assume transactional DDL.
[2024-01-15 21:56:30,243][PID:3862][INFO][alembic.runtime.migration] Running upgrade 7ce5925f832b -> 7205816877ec, change type of json fields from varchar to json
Traceback (most recent call last):
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.DatatypeMismatch: result of USING clause for column "data" cannot be cast automatically to type jsonb
HINT: You might need to add an explicit cast.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 9, in <module>
manager()
File "/venv/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/venv/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/venv/lib/python3.8/site-packages/flask/cli.py", line 357, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/venv/lib/python3.8/site-packages/flask_migrate/cli.py", line 134, in upgrade
_upgrade(directory, revision, sql, tag, x_arg)
File "/venv/lib/python3.8/site-packages/flask_migrate/__init__.py", line 95, in wrapped
f(*args, **kwargs)
File "/venv/lib/python3.8/site-packages/flask_migrate/__init__.py", line 280, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "/venv/lib/python3.8/site-packages/alembic/command.py", line 403, in upgrade
script.run_env()
File "/venv/lib/python3.8/site-packages/alembic/script/base.py", line 583, in run_env
util.load_python_file(self.dir, "env.py")
File "/venv/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
module = load_module_py(module_id, path)
File "/venv/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "migrations/env.py", line 93, in <module>
run_migrations_online()
File "migrations/env.py", line 85, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/venv/lib/python3.8/site-packages/alembic/runtime/environment.py", line 948, in run_migrations
self.get_context().run_migrations(**kw)
File "/venv/lib/python3.8/site-packages/alembic/runtime/migration.py", line 627, in run_migrations
step.migration_fn(**kw)
File "/redash/migrations/versions/7205816877ec_change_type_of_json_fields_from_varchar_.py", line 62, in upgrade
op.alter_column('query_results', 'data',
File "<string>", line 8, in alter_column
File "<string>", line 3, in alter_column
File "/venv/lib/python3.8/site-packages/alembic/operations/ops.py", line 1943, in alter_column
return operations.invoke(alt)
File "/venv/lib/python3.8/site-packages/alembic/operations/base.py", line 445, in invoke
return fn(self, operation)
File "/venv/lib/python3.8/site-packages/alembic/operations/toimpl.py", line 53, in alter_column
operations.impl.alter_column(
File "/venv/lib/python3.8/site-packages/alembic/ddl/postgresql.py", line 174, in alter_column
self._exec(
File "/venv/lib/python3.8/site-packages/alembic/ddl/impl.py", line 207, in _exec
return conn.execute(construct, multiparams)
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/venv/lib/python3.8/site-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1068, in _execute_ddl
ret = self._execute_context(
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self._handle_dbapi_exception(
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
util.raise_(
File "/venv/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
raise exception
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/venv/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DatatypeMismatch) result of USING clause for column "data" cannot be cast automatically to type jsonb
HINT: You might need to add an explicit cast.
[SQL: ALTER TABLE query_results ALTER COLUMN data TYPE JSONB USING data::text]
(Background on this error at: http://sqlalche.me/e/13/f405)
Any other info e.g. Why do you consider this to be a bug? What did you expect to happen instead?
Technical details:
- Redash Version: latest
- Browser/OS: Chrome
- How did you install Redash: Docker
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 22 (22 by maintainers)
@AndrewChubatiuk
docker-compose run --rm server manage db upgrade