zulip / docker-zulip

Container configurations, images, and examples for Zulip.
https://zulip.com/
Apache License 2.0
550 stars 227 forks source link

Wrong database tables for docker with Zulip 7.0 #428

Open aspil opened 5 months ago

aspil commented 5 months ago

I noticed this when I tried to import data from a Zulip server to its docker counterpart. The source server runs on version 7.0 with postgres 14 so I made the appropriate changes to docker-compose.yml :

...
database:
    image: "zulip/zulip-postgresql:14"
...
zulip:
    image: "zulip/docker-zulip:7.0-0"
    restart: unless-stopped
    build:
      context: .
      args:
        # Change these if you want to build zulip from a different repo/branch
        ZULIP_GIT_URL: https://github.com/zulip/zulip.git
        ZULIP_GIT_REF: "7.0"
...

When I connected to the container and executed the import command I got this error:

Processing dump: /home/zulip/zulip-export-nk1u3fcl ...
2024-01-23 08:45:34.834 INFO [] Importing realm dump /home/zulip/zulip-export-nk1u3fcl
2024-01-23 08:45:34.835 INFO [] Importing realm data from /home/zulip/zulip-export-nk1u3fcl/realm.json
Traceback (most recent call last):
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/zulip/deployments/2023-05-31-16-36-45/zerver/lib/db.py", line 35, in execute
    wrapper_execute(self, super().execute, query, vars)
  File "/home/zulip/deployments/2023-05-31-16-36-45/zerver/lib/db.py", line 20, in wrapper_execute
    action(sql, params)
psycopg2.errors.NotNullViolation: null value in column "default_code_block_language" of relation "zerver_realm" violates not-null constraint
DETAIL:  Failing row contains (...).

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

Traceback (most recent call last):
  File "./manage.py", line 150, in <module>
    execute_from_command_line(sys.argv)
  File "./manage.py", line 115, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/home/zulip/deployments/2023-05-31-16-36-45/zerver/management/commands/import.py", line 101, in handle
    do_import_realm(path, subdomain, num_processes)
  File "/home/zulip/deployments/2023-05-31-16-36-45/zerver/lib/import_realm.py", line 976, in do_import_realm
    realm.save()
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/base.py", line 814, in save
    self.save_base(
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/base.py", line 877, in save_base
    updated = self._save_table(
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/base.py", line 1020, in _save_table
    results = self._do_insert(
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/base.py", line 1061, in _do_insert
    return manager._insert(
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/query.py", line 1805, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1820, in execute_sql
    cursor.execute(sql, params)
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/srv/zulip-venv-cache/80adc5a65d3947b00c17d97d243aa9d941435ad3/zulip-py3-venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/zulip/deployments/2023-05-31-16-36-45/zerver/lib/db.py", line 35, in execute
    wrapper_execute(self, super().execute, query, vars)
  File "/home/zulip/deployments/2023-05-31-16-36-45/zerver/lib/db.py", line 20, in wrapper_execute
    action(sql, params)
django.db.utils.IntegrityError: null value in column "default_code_block_language" of relation "zerver_realm" violates not-null constraint
DETAIL:  Failing row contains (...).

I connected to the database of both the original server and the container and found that the zulip database tables differ. Specifically, in docker database the column default_code_block_language of relation zerver_realm does indeed have a not-null constraint when it clearly shouldn't (column is declared here). There are other differences among the two databases as well. It seems like the docker container uses the db schema of Zulip 8.0 even though the container has the 7.0 version.

I'm not sure if it's a bug or I'm missing something here but I'd appreciate any help!