linuxserver / docker-bookstack

A Docker container for the BookStack documentation wiki
GNU General Public License v3.0
779 stars 109 forks source link

SQLSTATE during migration #206

Closed macthecadillac closed 7 months ago

macthecadillac commented 7 months ago

Is there an existing issue for this?

Current Behavior

2020_12_30_173528_add_owned_by_field_to_entities ................. 14ms FAIL

Illuminate\Database\QueryException

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'owned_by' (SQL: alter table pages add owned_by int unsigned not null)

at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760 756▕ // If an exception occurs when attempting to run a query, we'll format the error 757▕ // message to include the bindings with SQL, which will make this exception a 758▕ // lot more helpful to the developer instead of just the database's errors. 759▕ catch (Exception $e) { ➜ 760▕ throw new QueryException( 761▕ $query, $this->prepareBindings($bindings), $e 762▕ ); 763▕ } 764▕ }

  +9 vendor frames

10 /app/www/database/migrations/2020_12_30_173528_add_owned_by_field_to_entities.php:19 Illuminate\Support\Facades\Facade::__callStatic()

  +25 vendor frames

36 /app/www/artisan:35 Illuminate\Foundation\Console\Kernel::handle()

Expected Behavior

Successful Migration and application startup.

Steps To Reproduce

#!/bin/bash
podman pod create --hostname example.com --name bookstack-server

podman network create bookstack-net

podman run \
    --detach \
    --name mariadb \
    --pod bookstack-server \
    --label io.containers.autoupdate=registry \
    --label PODMAN_SYSTEMD_UNIT=mariadb.service \
    --network bookstack-net \
    --env MYSQL_DATABASE=bookstack \
    --env MYSQL_USER=bookstack \
    --env MYSQL_PASSWORD=db_pass \
    --env MYSQL_ROOT_PASSWORD=root_pw \
    --env TZ="US/Pacific" \
    --volume /home/bookstack/data/bookstack_db:/config:Z \
    lscr.io/linuxserver/mariadb:latest

podman run \
    --detach \
    --name bookstack \
    --pod bookstack-server \
    --label io.containers.autoupdate=registry \
    --label PODMAN_SYSTEMD_UNIT=bookstack.service \
    --network bookstack-net \
    --publish 6875:80 \
    --env APP_URL='https://example.com/bookstack' \
    --env DB_HOST=mariadb.dns.podman \
    --env DB_PORT=3306 \
    --env DB_USER=bookstack \
    --env DB_PASS=db_pass \
    --env DB_DATABASE=bookstack \
    --volume /home/bookstack/data/bookstack_app:/config:Z \
    lscr.io/linuxserver/bookstack:latest

Run the script. Error shows up in podman container logs bookstack

Environment

- OS: Debian GNU/Linux 12 (bookworm)
- How docker service was installed: sudo apt install podman

CPU architecture

x86-64

Docker creation

podman pod create --hostname example.com --name bookstack-server

podman network create bookstack-net

podman run \
    --detach \
    --name mariadb \
    --pod bookstack-server \
    --label io.containers.autoupdate=registry \
    --label PODMAN_SYSTEMD_UNIT=mariadb.service \
    --network bookstack-net \
    --env MYSQL_DATABASE=bookstack \
    --env MYSQL_USER=bookstack \
    --env MYSQL_PASSWORD=db_pass \
    --env MYSQL_ROOT_PASSWORD=root_pw \
    --env TZ="US/Pacific" \
    --volume /home/bookstack/data/bookstack_db:/config:Z \
    lscr.io/linuxserver/mariadb:latest

podman run \
    --detach \
    --name bookstack \
    --pod bookstack-server \
    --label io.containers.autoupdate=registry \
    --label PODMAN_SYSTEMD_UNIT=bookstack.service \
    --network bookstack-net \
    --publish 6875:80 \
    --env APP_URL='https://example.com/bookstack' \
    --env DB_HOST=mariadb.dns.podman \
    --env DB_PORT=3306 \
    --env DB_USER=bookstack \
    --env DB_PASS=db_pass \
    --env DB_DATABASE=bookstack \
    --volume /home/bookstack/data/bookstack_app:/config:Z \
    lscr.io/linuxserver/bookstack:latest

Container logs

[migrations] started
[migrations] 01-nginx-site-confs-default: skipped
[migrations] 02-default-location: skipped
[migrations] done
usermod: no changes
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    911
User GID:    911
───────────────────────────────────────

using keys found in /config/keys
App Key found - setting variable for seds
Running config - DB_HOST set
Waiting for DB to be available

   INFO  Running migrations.

  2020_12_30_173528_add_owned_by_field_to_entities ................. 14ms FAIL

   Illuminate\Database\QueryException

  SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'owned_by' (SQL: alter table `pages` add `owned_by` int unsigned not null)

  at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
    756▕         // If an exception occurs when attempting to run a query, we'll format the error
    757▕         // message to include the bindings with SQL, which will make this exception a
    758▕         // lot more helpful to the developer instead of just the database's errors.
    759▕         catch (Exception $e) {
  ➜ 760▕             throw new QueryException(
    761▕                 $query, $this->prepareBindings($bindings), $e
    762▕             );
    763▕         }
    764▕     }

      +9 vendor frames
  10  /app/www/database/migrations/2020_12_30_173528_add_owned_by_field_to_entities.php:19
      Illuminate\Support\Facades\Facade::__callStatic()

      +25 vendor frames
  36  /app/www/artisan:35
      Illuminate\Foundation\Console\Kernel::handle()
[custom-init] No custom files found, skipping...
[ls.io-init] done.
github-actions[bot] commented 7 months ago

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

ssddanbrown commented 7 months ago

Is this an upgrade of an old version? Or a new instance? If a new instance, please delete your volume folder contents and re-create the containers from fresh data, then share the error you see on first run. The error you've shared above should only really occur on subsequent migration runs, not the first.

macthecadillac commented 7 months ago

Thanks for the very prompt response and this fantastic piece of software.

It's a new instance, but yes the initial error was a bit different. I did a full system reset through podman system reset and deleted all the files in the volumes, it somehow fixed itself. I suppose the original problem I faced came from the --userns keep-id option, but once I removed that it was no longer an issue.