Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] Can't upgrade DB schema to version 8 when using postgres #1045

@tblaschke

Description

@tblaschke

Describe the bug
Hi, it seems that upgrading the DB schema fails during the upgrade of version 0.5 to version 0.6 while using postgres as DB.

This causes my lldap instance to be inaccessible, as I can't startup v0.6 and reverting to v0.5 fails due to the schema beeing too new. (Had to restore the DB from a backup)

To Reproduce
Steps to reproduce the behavior:

  1. Setup an lldap instance v0.5 using postgres as DB
  2. Upgrade lldap to v0.6

Expected behavior
Update from v0.5 to v0.6 should work even when using Postgres

Logs
LLDAP logs

2024-11-21T17:06:18.705491180+00:00  INFO     set_up_server [ 4.39ms | 93.87% / 100.00% ]
2024-11-21T17:06:18.705513535+00:00  INFO     ┝━ i [info]: Starting LLDAP version 0.6.0
2024-11-21T17:06:18.715020826+00:00  DEBUG    ┝━ get_schema_version [ 269µs | 6.13% ]
2024-11-21T17:06:18.721196526+00:00  DEBUG    │  ┕━ 🐛 [debug]:  | return: Some(SchemaVersion(5))
2024-11-21T17:06:18.721204849+00:00  INFO     ┝━ i [info]: Upgrading DB schema from version 5
2024-11-21T17:06:18.721205922+00:00  INFO     ┝━ i [info]: Upgrading DB schema to version 6
2024-11-21T17:06:18.751703272+00:00  INFO     ┝━ i [info]: Upgrading DB schema to version 7
2024-11-21T17:06:18.757698108+00:00  INFO     ┕━ i [info]: Upgrading DB schema to version 8
Error: while creating base tables

Caused by:
    0: Execution Error: error returned from database: syntax error at or near "LIMIT"
    1: error returned from database: syntax error at or near "LIMIT"
    2: error returned from database: syntax error at or near "LIMIT"
    3: syntax error at or near "LIMIT"

Postgres logs


PostgreSQL Database directory appears to contain a database; Skipping initialization
2024-11-21 17:06:08.272 GMT [1] LOG:  starting PostgreSQL 16.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014, 64-bit
2024-11-21 17:06:08.272 GMT [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-11-21 17:06:08.272 GMT [1] LOG:  listening on IPv6 address "::", port 5432
2024-11-21 17:06:08.273 GMT [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-11-21 17:06:08.277 GMT [24] LOG:  database system was shut down at 2024-11-21 17:04:06 GMT
2024-11-21 17:06:08.284 GMT [1] LOG:  database system is ready to accept connections
2024-11-21 17:06:18.721 GMT [35] LOG:  execute sqlx_s_1: SELECT "version" FROM "metadata"
2024-11-21 17:06:18.725 GMT [36] LOG:  statement: BEGIN
2024-11-21 17:06:18.725 GMT [36] LOG:  execute sqlx_s_1: ALTER TABLE "groups" ADD COLUMN "lowercase_display_name" varchar(255) NOT NULL DEFAULT 'UNSET'
2024-11-21 17:06:18.737 GMT [36] LOG:  execute sqlx_s_2: ALTER TABLE "users" ADD COLUMN "lowercase_email" varchar(255) NOT NULL DEFAULT 'UNSET'
2024-11-21 17:06:18.740 GMT [36] LOG:  execute sqlx_s_3: UPDATE "groups" SET "lowercase_display_name" = LOWER("display_name")
2024-11-21 17:06:18.743 GMT [36] LOG:  execute sqlx_s_4: UPDATE "users" SET "lowercase_email" = LOWER("email")
2024-11-21 17:06:18.743 GMT [36] LOG:  execute sqlx_s_5: UPDATE "metadata" SET "version" = $1
2024-11-21 17:06:18.743 GMT [36] DETAIL:  parameters: $1 = '6'
2024-11-21 17:06:18.743 GMT [36] LOG:  statement: COMMIT
2024-11-21 17:06:18.751 GMT [35] LOG:  statement: BEGIN
2024-11-21 17:06:18.752 GMT [35] LOG:  execute sqlx_s_2: ALTER TABLE "metadata" ADD COLUMN "private_key_hash" bytea
2024-11-21 17:06:18.755 GMT [35] LOG:  execute sqlx_s_3: ALTER TABLE "metadata" ADD COLUMN "private_key_location" varchar(255)
2024-11-21 17:06:18.756 GMT [35] LOG:  execute sqlx_s_4: UPDATE "metadata" SET "version" = $1
2024-11-21 17:06:18.756 GMT [35] DETAIL:  parameters: $1 = '7'
2024-11-21 17:06:18.756 GMT [35] LOG:  statement: COMMIT
2024-11-21 17:06:18.757 GMT [36] LOG:  statement: BEGIN
2024-11-21 17:06:18.762 GMT [36] LOG:  execute sqlx_s_6: SELECT "user_id", "group_id", COUNT("memberships"."user_id") AS "cnt" FROM "memberships" GROUP BY "user_id", "group_id" HAVING COUNT("memberships"."user_id") > $1
2024-11-21 17:06:18.762 GMT [36] DETAIL:  parameters: $1 = '1'
2024-11-21 17:06:18.762 GMT [36] ERROR:  syntax error at or near "LIMIT" at character 68
2024-11-21 17:06:18.762 GMT [36] STATEMENT:  DELETE FROM "memberships" WHERE "user_id" = $1 AND "group_id" = $2 LIMIT $3
2024-11-21 17:06:18.762 GMT [36] LOG:  could not receive data from client: Connection reset by peer

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendIssues that require a backend changebugSomething isn't workingrustPull requests that update Rust code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions