8000 Upgrade from v1.12.0 to v1.12.1 failed with database migration · Issue #6936 · hedgedoc/hedgedoc · GitHub
[go: up one dir, main page]

Skip to content

Upgrade from v1.12.0 to v1.12.1 failed with database migration #6936

Open

Description

@Splinter7914

Description

I updated my docker image to v1.12.1 and on start the contained failed with. My service is running with OIDC setup.

xiting…
2026-11-04T22:09:05.160Z error:         Migration 20260922038700-add-profile-provider.js (up) failed: Original error: type "enum_Users_profileProvider" already exists
2026-11-04T22:09:05.160Z error:         Database migration failed.
This can be the result of upgrading from quite old versions and requires manual database intervention.
See https://docs.hedgedoc.org/guides/migration-troubleshooting/ for help.

Switched back to v1.12.0 and service started up fine.

Running in docker with

  • postgres
  • oidc

Steps to reproduce

Upgrade from hedgedoc v1.12.0 to v1.12.1

Expected behaviour

Service starts up

Logs

Config

Your Setup

  • Host OS: Debian 13, running in docker
  • HedgeDoc version: v1.12.0

Additional context

No response

Activity

  1. ramereth commented on Nov 4, 2026

    @ramereth

    We hit this too (PostgreSQL, Docker). The already exists error is a follow-on
    failure. The first start on 1.12.1 fails earlier in the same migration, and
    that error is probably already gone from your logs:

    Migration 20260922038700-add-profile-provider.js (up) failed: Original error: Cannot read properties of undefined (reading 'toString')
    

    The cause is queryInterface.changeColumn('Users', 'profileid', { unique: false }):
    with no type, Sequelize 5.22.5 throws while building the SQL. On PostgreSQL the
    addColumn before it has already committed the enum type and the column, but
    the migration isn't recorded in SequelizeMeta. Every later start then fails on
    CREATE TYPE, before the catch gets to check for an existing column.

    Reproduced with the stock images and default settings, upgrading a fresh 1.12.0
    database:

    Database 1.12.0 → 1.12.1
    SQLite works
    MariaDB 11 fails on every start with the toString error
    PostgreSQL 16 toString error first, then type "enum_Users_profileProvider" already exists on every start after
    docker network create hd
    docker run -d --rm --name hd-db --network hd -e POSTGRES_PASSWORD=pw -e POSTGRES_USER=hd -e POSTGRES_DB=hd postgres:16
    E="-e CMD_DB_URL=postgres://hd:pw@hd-db:5432/hd -e CMD_DOMAIN=localhost -e CMD_SESSION_SECRET=x"
    docker run -d --name hd-old --network hd $E quay.io/hedgedoc/hedgedoc:1.12.0   # wait for "HTTP Server listening"
    docker rm -f hd-old
    docker run --rm --network hd $E quay.io/hedgedoc/hedgedoc:1.12.1   # toString error
    docker run --rm --network hd $E quay.io/hedgedoc/hedgedoc:1.12.1   # already exists

    The test suite runs against in-memory SQLite only (mocha-suite in
    package.json), which would explain why this wasn't caught. A fix probably
    needs both: drop the profileid unique constraint some other way (for example
    removeConstraint, or changeColumn with type: Sequelize.STRING), and make
    the enum creation safe to rerun after a partial failure.

    Rolling back to 1.12.0, as you did, is safe: in our reproduction 1.12.0 starts
    fine on the half-migrated database.

    Workaround on PostgreSQL (tested on the reproduction and on our production
    instance): take a dump, check the constraint name with \d "Users", then finish
    the migration by hand in one transaction. 1.12.1 then starts and runs the
    remaining migrations. We haven't tried this on MariaDB.

    BEGIN;
    ALTER TABLE "Users" DROP CONSTRAINT "Users_profileid_key";
    CREATE INDEX user_profile_provider_index ON "Users" ("profileProvider");
    CREATE UNIQUE INDEX user_profile_id_profile_provider_index ON "Users" (profileid, "profileProvider");
    UPDATE "Users" SET "profileProvider" = 'email' WHERE email IS NOT NULL AND password IS NOT NULL;
    INSERT INTO "SequelizeMeta" (name) VALUES ('20260922038700-add-profile-provider.js');
    COMMIT;

    One more thing to check first: the next migration,
    20261001120000-user-email-unique.js (#6882), fails with Validation error if
    two local accounts share an email address, which the race in #6875 could
    create. We had one such pair, created 50 ms apart. To find them:

    SELECT email, count(*) FROM "Users" WHERE email IS NOT NULL GROUP BY email HAVING count(*) > 1;

    We kept the account that owned notes and set email = NULL on the unused one,
    inside the same transaction before the UPDATE ... 'email' line.

  2. soundstorm commented on Nov 5, 2026

    @soundstorm

    Also updating to 1.12.1 and then to 1.12.2 still failes on the enum_Users_profileProvider, the migration is not cancelled/rolled back and would still need manual intervention. Just rolled back to 1.12.0.

    Edit (more info):
    We're using OIDC in a Docker (quay.io/hedgedoc/hedgedoc:latest) in default Postgres setup.

    CMD_ALLOW_EMAIL_REGISTER=false
    HD_AUTH_SYNC_SOURCE=authentik
    CMD_OAUTH2_...
    

    Only checked after downgrade to 1.12.0:

    hedgedoc=# \dT+ "enum_Users_profileProvider"
                                                             List of data types
     Schema |             Name             |       Internal name        | Size |  Elements  |  Owner   | Access privileges | Description
    --------+------------------------------+----------------------------+------+------------+----------+-------------------+-------------
     public | "enum_Users_profileProvider" | enum_Users_profileProvider | 4    | dropbox   +| hedgedoc |                   |
            |                              |                            |      | email     +|          |                   |
            |                              |                            |      | facebook  +|          |                   |
            |                              |                            |      | github    +|          |                   |
            |                              |                            |      | gitlab    +|          |                   |
            |                              |                            |      | google    +|          |                   |
            |                              |                            |      | ldap      +|          |                   |
            |                              |                            |      | mattermost+|          |                   |
            |                              |                            |      | oauth2    +|          |                   |
            |                              |                            |      | openid    +|          |                   |
            |                              |                            |      | saml      +|          |                   |
            |                              |                            |      | twitter    |          |                   |
    
    hedgedoc=# \d "Users"
                                  Table "public.Users"
         Column      |             Type             | Collation | Nullable | Default
    -----------------+------------------------------+-----------+----------+---------
     id              | uuid                         |           | not null |
     profileid       | character varying(255)       |           |          |
     profile         | text                         |           |          |
     history         | text                         |           |          |
     createdAt       | timestamp with time zone     |           |          |
     updatedAt       | timestamp with time zone     |           |          |
     accessToken     | text                         |           |          |
     refreshToken    | text                         |           |          |
     email           | text                         |           |          |
     password        | text                         |           |          |
     deleteToken     | uuid                         |           |          |
     profileProvider | "enum_Users_profileProvider" |           |          |
    Indexes:
        "Users_pkey" PRIMARY KEY, btree (id)
        "Users_profileid_key" UNIQUE CONSTRAINT, btree (profileid)
    Referenced by:
        TABLE ""Authors"" CONSTRAINT "Author_user_fkey" FOREIGN KEY ("userId") REFERENCES "Users"(id) ON DELETE CASCADE
        TABLE ""Notes"" CONSTRAINT "Notes_owner_fkey" FOREIGN KEY ("ownerId") REFERENCES "Users"(id) ON DELETE CASCADE
    
    hedgedoc=# SELECT name FROM "SequelizeMeta" ORDER BY name DESC LIMIT 5;
                         name
    -----------------------------------------------
     20260622225700-remove-temp.js
     20220901102800-convert-history-to-longtext.js
     20200321153000-fix-account-deletion.js
     20180525153000-user-add-delete-token.js
     20180326103000-use-text-in-tokens.js
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0