Database migration problem when upgrading from 4.8.0 to 5.37 (solved)

I know, the version is really ancient, and I solved the problem myself, but I just want to document it in case somebody else has this problem.

After starting the server, it crashes with the following message:

{
  "level": "error",
  "ts": 1627662181.338535,
  "caller": "sqlstore/store.go:201",
  "msg": "Failed to apply database migrations.",
  "error": "migration failed: column \"schemeid\" does not exist in line 0: CREATE TABLE IF NOT EXISTS teams (\n    id VARCHAR(26) PRIMARY KEY,\n    createat bigint,\n    updateat bigint,\n    deleteat bigint,\n    displayname VARCHAR(64),\n    name VARCHAR(64),\n    description VARCHAR(255),\n    email VARCHAR(128),\n    type VARCHAR(255),\n    companyname VARCHAR(64),\n    alloweddomains VARCHAR(1000),\n    inviteid VARCHAR(32),\n    schemeid VARCHAR(26),\n    UNIQUE(name)\n);\n\nCREATE INDEX IF NOT EXISTS idx_teams_invite_id ON teams (inviteid);\nCREATE INDEX IF NOT EXISTS idx_teams_update_at ON teams (updateat);\nCREATE INDEX IF NOT EXISTS idx_teams_create_at ON teams (createat);\nCREATE INDEX IF NOT EXISTS idx_teams_delete_at ON teams (deleteat);\nCREATE INDEX IF NOT EXISTS idx_teams_scheme_id ON teams (schemeid);\n\nALTER TABLE teams ADD COLUMN IF NOT EXISTS allowopeninvite boolean;\nALTER TABLE teams ADD COLUMN IF NOT EXISTS lastteamiconupdate bigint;\nALTER TABLE teams ADD COLUMN IF NOT EXISTS description VARCHAR(255);\nALTER TABLE teams ADD COLUMN IF NOT EXISTS groupconstrained boolean;\n (details: pq: column \"schemeid\" does not exist)"
}

When restarting it again, it crashes with

{
  "level": "error",
  "ts": 1627662192.0421996,
  "caller": "sqlstore/store.go:201",
  "msg": "Failed to apply database migrations.",
  "error": "Dirty database version 1. Fix and force version."
}

I think this merge request - https://github.com/mattermost/mattermost-server/pull/16938 - didn’t take ancient database schema versions into account.

Solution

  1. Delete schema_migrations table contents.

  2. Upgrade to 5.33 first, and after that you can upgrade to 5.34 and up without problems.

2 Likes