LycheeOrg / Lychee

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.
https://lycheeorg.github.io/
MIT License
3.41k stars 302 forks source link

Migration on docker fails with "Branch is not master" #2254

Closed DLYSY closed 9 months ago

DLYSY commented 9 months ago

Detailed description of the problem

When using the docker image and mysql as a database, and upgrading to the version 5.1.0, the migration fails with the error Branch is not master, I was upgrading from version 5.0.3. Downgrading to the old version 5.0.3 works and the lychee page displays correctly. Looking at the attached logs, it seems like there are something wrong with database.

Steps to reproduce the issue

Steps to reproduce the behavior:

  1. Run docker stop lychee
  2. Change the docker image from lycheeorg/lychee:5.0.3 to lycheeorg/lychee:v5.1.0
  3. Run docker run lycheeorg/lychee:v5.1.0
  4. Reload the web page
  5. After the login, you can see the Migration result of Branch is not master

Screenshots

image

Output of the diagnostics

-------------------------------------
  _               _                
 | |   _   _  ___| |__   ___  ___  
 | |  | | | |/ __|  _ \ / _ \/ _ \ 
 | |__| |_| | (__| | | |  __/  __/ 
 |_____\__, |\___|_| |_|\___|\___| 
       |___/                       
-------------------------------------
Lychee Version: 5.1.0 (release)
Lychee Commit:  28dec12
https://github.com/LycheeOrg/Lychee/commit/28dec12cbc229956834231182dead2b8a3cc0203
-------------------------------------
**** Make sure the /conf /uploads /sym /logs folders exist ****
**** Create the symbolic link for the /uploads folder ****
**** Create the symbolic link for the /sym folder ****
**** Create the symbolic link for the /logs folder ****
**** Copy the .env to /conf ****
**** Inject .env values ****
**** Generate the key (to make sure that cookies cannot be decrypted etc) ****
   INFO  Application key set successfully.  
**** Migrate the database ****
   INFO  Running migrations.  
  2024_01_13_124937_create_oauth_credentials_table ................ 140ms FAIL
In Connection.php line 822:

  SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and refer  
  enced column 'id' in foreign key constraint 'oauth_credentials_user_id_fore  
  ign' are incompatible. (Connection: mysql, SQL: alter table `oauth_credenti  
  als` add constraint `oauth_credentials_user_id_foreign` foreign key (`user_  
  id`) references `users` (`id`) on delete cascade on update cascade)          

In Connection.php line 580:

  SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and refer  
  enced column 'id' in foreign key constraint 'oauth_credentials_user_id_fore  
  ign' are incompatible.                                                       

**** Make sure user.css exists and symlink it ****
**** Make sure custom.js exists and symlink it ****
**** Create user and use PUID/PGID ****
    User UID :  1000
    User GID :  1000
**** Make sure Laravel's log exists ****
**** Set Permissions ****
**** Start cron daemon ****
Starting periodic command scheduler: cron.
**** Setup complete, starting the server. ****
    Diagnostics
    -----------
    Warning: Dropbox import not working. dropbox_key is empty.
    Warning: APP_URL is still set to default, this will break access to all your images
            and assets if you are using Lychee behind a sub-domain.
    Error: APP_URL (http://lo*****st) does not match the current url (http://192.********8081).
          This will break WebAuthn authentication.
    Error: Database is behind file version. Please apply the migrations.
    Info: Latest version of PHP is 8.3
    Warning: git (software) is not available.

    System Information
    ------------------
    Lychee Version (git):                    ?? (28dec12) -- Could not compare.
    DB Version:                              5.0.3

    composer install:                        --no-dev
    APP_ENV:                                 development
    APP_DEBUG:                               false
    APP_URL:                                 default
    APP_DIR:                                 default
    LOG_VIEWER_ENABLED:                      true
    LIVEWIRE_ENABLED:                        true

    System:                                  Linux
    PHP Version:                             8.2.7
    PHP User agent:                          Lychee/4 (https://lycheeorg.github.io/)
    Timezone:                                Asia/Shanghai
    Max uploaded file size:                  100M
    Max post size:                           100M
    Livewire chunk size:                     12.00 MB
    Max execution time:                      3600
    MySQL Version:                           8.3.0

    exec() Available:                        yes
    Imagick Available:                       1
    Imagick Enabled:                         1
    Imagick Version:                         1691
    GD Version:                              2.3.3
    Number of foreign key:                   0 found.

    Config Information
    ------------------
    layout:                                  justified
    date_format_photo_thumb:                 M j, Y, g:i:s A e
    date_format_photo_overlay:               M j, Y, g:i:s A e
    date_format_sidebar_uploaded:            M j, Y, g:i:s A e
    date_format_sidebar_taken_at:            M j, Y, g:i:s A e
    date_format_hero_min_max:                F Y
    date_format_hero_created_at:             M j, Y, g:i:s A T
    date_format_album_thumb:                 M Y
    upload_chunk_size:                       0
    nsfw_banner_blur_backdrop:               0
    search_pagination_limit:                 1000
    search_minimum_length_required:          4
    photo_layout_justified_row_height:       320
    photo_layout_masonry_column_width:       300
    photo_layout_grid_column_width:          250
    photo_layout_square_column_width:        200
    photo_layout_gap:                        12
    display_thumb_album_overlay:             always
    display_thumb_photo_overlay:             hover
    default_album_thumb_aspect_ratio:        1/1
    use_album_compact_header:                0
    login_button_position:                   left
    back_button_enabled:                     0
    back_button_text:                        Return to Home
    back_button_url:                         /
    version:                                 050003
    check_for_updates:                       0
    sorting_photos_col:                      taken_at
    sorting_photos_order:                    ASC
    sorting_albums_col:                      max_taken_at
    sorting_albums_order:                    ASC
    imagick:                                 1
    skip_duplicates:                         0
    small_max_width:                         0
    small_max_height:                        360
    medium_max_width:                        1920
    medium_max_height:                       1080
    lang:                                    zh_CN
    image_overlay_type:                      desc
    default_license:                         
    compression_quality:                     90
    grants_full_photo_access:                1
    delete_imported:                         0
    mod_frame_enabled:                       1
    mod_frame_refresh:                       30
    thumb_2x:                                1
    small_2x:                                1
    medium_2x:                               1
    landing_page_enable:                     0
    site_owner:                              
    landing_title:                           
    landing_subtitle:                        
    sm_facebook_url:                         
    sm_flickr_url:                          
    sm_twitter_url:                         
    sm_instagram_url:                        
    sm_youtube_url:                         
    landing_background:                      dist/cat.webp
    site_title:                              
    footer_show_copyright:                   1
    site_copyright_begin:                    2022
    site_copyright_end:                      2023
    footer_additional_text:                  
    footer_show_social_media:                0
    search_public:                           0
    SL_enable:                               0
    SL_for_admin:                            0
    recent_age:                              1
    grants_download:                         0
    photos_wraparound:                       1
    map_display:                             0
    zip64:                                   1
    map_display_public:                      0
    map_provider:                            Wikimedia
    force_32bit_ids:                         0
    map_include_subalbums:                   0
    update_check_every_days:                 3
    has_exiftool:                            0
    share_button_visible:                    0
    import_via_symlink:                      0
    has_ffmpeg:                              1
    location_decoding:                       0
    location_decoding_timeout:               30
    location_show:                           1
    location_show_public:                    0
    rss_enable:                              0
    rss_recent_days:                         7
    rss_max_items:                           100
    prefer_available_xmp_metadata:           0
    editor_enabled:                          1
    lossless_optimization:                   0
    swipe_tolerance_x:                       150
    swipe_tolerance_y:                       250
    local_takestamp_video_formats:           .avi|.mov
    log_max_num_line:                        1000
    unlock_password_photos_with_url_param:   0
    nsfw_visible:                            1
    nsfw_blur:                               0
    nsfw_warning:                            0
    nsfw_warning_admin:                      0
    nsfw_banner_override:                    
    map_display_direction:                   1
    album_subtitle_type:                     oldstyle
    upload_processing_limit:                 4
    new_photos_notification:                 0
    legacy_id_redirection:                   1
    zip_deflate_level:                       6
    SA_enabled:                              1
    default_album_protection:                1
    album_decoration:                        layers
    album_decoration_orientation:            row
    allow_username_change:                   1
    auto_fix_orientation:                    1
    use_job_queues:                          0
    random_album_id:                         starred
    use_last_modified_date_when_no_exif_date: 0
    ffmpeg_path:                             
    ffprobe_path:                            

Browser and system

Workaround

Downgrading to v5.0.3

ildyria commented 9 months ago

I wished you had used a docker compose.

You can also log into the container:

docker exec -it lychee bash

and then

php artisan migrate

But I agree that we need to investigate this migration.

DLYSY commented 9 months ago

我也不秀自己那蹩脚的四级英语了,看不懂的自己想办法翻译吧

To encourage active collaboration, Lychee strongly encourages pull requests, not just bug reports.

Remember, bug reports are created in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the bug report will automatically see any activity or that others will jump in to fix it. Creating a bug report serves to help yourself and others start on the path to fixing the problem.

我承认这是良好的社区规则,但我本职和专业为大数据分析,不熟悉 SQL 和 PHP ,对于我无法自行解决我遇到的问题,我很抱歉。不过令我更加遗憾的是,看到社区对这个问题没有给予足够的重视。

自从v5.0.0以来,虽然开发者们在短时间内积极跟新了数个小版本,但我依然遇到了非常多的问题,如Profile界面403等问题,虽然没有像这个问题一样严重,但总是无形之中影响正常使用。

现在因为此 issue 描述问题使我无法继续使用Lychee的更高版本。眼看修复和解决无望,我将会将 Lychee 降级到最后可用的v5.0.3迁移数据并停止使用Lychee

d7415 commented 9 months ago

(From a Google translation, so some nuance may be lost)

Seeing that there is no hope of repair and resolution

I'm not sure how you get this from

we need to investigate this migration.

ildyria commented 9 months ago

我也不秀自己那蹩脚的四级英语了,看不懂的自己想办法翻译吧

Google translate is doing a pretty good job. :)

我承认这是良好的社区规则,但我本职和专业为大数据分析,不熟悉 SQL 和 PHP ,对于我无法自行解决我遇到的问题,我很抱歉。不过令我更加遗憾的是,看到社区对这个问题没有给予足够的重视。

Yeah... Unfortunately, the Lychee community is very small as I am pretty much the only active developer on this project. My time is very limited:

I am dedicating all my free time left to Lychee (for which I am not paid). I see issues pilling up, I try to resolve them when I can, picking up the most urgent at first.

自从v5.0.0以来,虽然开发者们在短时间内积极跟新了数个小版本,但我依然遇到了非常多的问题,如Profile界面403等问题,虽然没有像这个问题一样严重,但总是无形之中影响正常使用。

We try to avoid issues as much as possible, but that takes time (which I don't necessarily have). The fact that we pushed that many small versions actually shows that we are actively fixing bugs, improving the stability of Lychee and listening to feedback.

现在因为此 issue 描述问题使我无法继续使用Lychee的更高版本。眼看修复和解决无望,我将会将 Lychee 降级到最后可用的v5.0.3迁移数据并停止使用Lychee

I don't know how you use Lychee, but if you are using docker compose (which I surely hope). Updating just requires you to:

  1. edit the compose to latest tag (or simply use latest)
  2. docker compose down
  3. docker compose pull
  4. docker compose up -d

That is literally what I am doing to update my install. Docker compose up will trigger the entrypoint.sh and make sure that you are running the latest version of the database (hence why I consider this issue as Low priority).

As as mentioned here , give us some time to investigate... Since version 5.1.1 we lost one of our dev. So yes our code throughput is very limited.

DLYSY commented 9 months ago

English(Translate by ChatGPT 3.5)

I don't know how you use Lychee, but if you are using docker compose (which I surely hope). Updating just requires you to:

  1. edit the compose to latest tag (or simply use latest)
  2. docker compose down
  3. docker compose pull
  4. docker compose up -d

That is literally what I am doing to update my install. Docker compose up will trigger the entrypoint.sh and make sure that you are running the latest version of the database (hence why I consider this issue as Low priority).

As as mentioned here, give us some time to investigate... Since version 5.1.1 we lost one of our dev. So yes our code throughput is very limited.

Perhaps my initial description when submitting the issue wasn't accurate enough, I just mentioned:

  1. Run docker run lycheeorg/lychee:v5.1.0

But actually, I omitted many parameters in between because I thought providing information such as database hostname and user parameters would be useless for troubleshooting. In my initial issue description, I also referenced the logs, where I saw database errors:

2024_01_13_124937_create_oauth_credentials_table ................ 140ms FAIL
In Connection.php line 822:

SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'oauth_credentials_user_id_foreign' are incompatible. (Connection: mysql, SQL: alter table `oauth_credentials` add constraint `oauth_credentials_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade on update cascade)

In Connection.php line 580:

SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'oauth_credentials_user_id_foreign' are incompatible.

This obviously isn't a problem that switching to Docker compose can solve. Indeed, Docker Compose can facilitate deployment more quickly, but as long as used properly, Docker CLI can achieve the same purpose completely. Here, I also provide the complete usage of my Docker CLI:

docker run -d \
    --name=lychee \
    --restart=always \
    -v /srv/docker/lychee/conf:/conf \
    -v /srv/docker/lychee/uploads:/uploads \
    -v /srv/docker/lychee/sym:/sym \
    -e DB_CONNECTION=mysql \
    -e DB_HOST=mysql \
    -e DB_PORT=3306 \
    -e DB_DATABASE=lychee \
    -e DB_USERNAME=lychee \
    -e DB_PASSWORD=password \
    -p 8081:80 \
    --network mysqlbridge \
    lycheeorg/lychee

The update theme of v5.1.0 is:

Version 5.1.0 - Oauth supported for major providers.

Which corresponds directly to the table oauth_credentials, I don't think this is a coincidence.

You can also log into the container:

docker exec -it lychee bash

and then

php artisan migrate

But I agree that we need to investigate this migration.

I did try manual migration, but the error message was identical to what was presented in the log above.

Yeah... Unfortunately, the Lychee community is very small as I am pretty much the only active developer on this project. My time is very limited:

  • I have a full-time job.
  • I have a girlfriend (lucky me).
  • I am a top-sport ballroom dancer (which means ~10h of training per week)
  • I am a photographer (when I have the time)

I am dedicating all my free time left to Lychee (for which I am not paid). I see issues piling up, I try to resolve them when I can, picking up the most urgent at first.

Seeing no hope for fixing and solving, I will downgrade lychee to the last available v5.0.3, migrate the data, and stop using Lychee.

I understand the dilemma of open-source community developers, and I am very grateful for selfless contributors like you, but considering that my image service based on Lychee is almost unusable (it has been going on for about a month), I cannot rely on a long and unpredictable fix (especially when the issue is classified as low priority in the issue tracker). Temporarily disabling Lychee is a necessary step.

中文原文

I don't know how you use Lychee, but if you are using docker compose (which I surely hope). Updating just requires you to:

  1. edit the compose to latest tag (or simply use latest)
  2. docker compose down
  3. docker compose pull
  4. docker compose up -d

That is literally what I am doing to update my install. Docker compose up will trigger the entrypoint.sh and make sure that you are running the latest version of the database (hence why I consider this issue as Low priority).

As as mentioned here , give us some time to investigate... Since version 5.1.1 we lost one of our dev. So yes our code throughput is very limited.

也许是在我最初提交 issue 时的表述不够准确,我仅仅说明我

  1. Run docker run lycheeorg/lychee:v5.1.0

但其实我省略了中间很多的参数,因为我认为提供数据库主机名、用户等参数信息对解决问题是无用的。我在最初的issue说明中也引用了日志,我看到日志中说明了数据库错误:

  2024_01_13_124937_create_oauth_credentials_table ................ 140ms FAIL In Connection.php line 822:

SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and refer enced column 'id' in foreign key constraint 'oauth_credentials_user_id_foreign' are incompatible. (Connection: mysql, SQL: alter table `oauth_credentials` add constraint `oauth_credentials_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade on update cascade)

In Connection.php line 580:

 SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and refer enced column 'id' in foreign key constraint 'oauth_credentials_user_id_foreign' are incompatible.

这显然不是改用docker conpose所能解决的问题。诚然,docker compose可以更快速的实现部署,但只要使用得当,docker cli也是完全可以实现相同目的的。我这里也给出我docker cli的完整用法:

docker run -d \
    --name=lychee \
    --restart=always \
    -v /srv/docker/lychee/conf:/conf \
    -v /srv/docker/lychee/uploads:/uploads \
    -v /srv/docker/lychee/sym:/sym \
    -e DB_CONNECTION=mysql \
    -e DB_HOST=mysql \
    -e DB_PORT=3306 \
    -e DB_DATABASE=lychee \
    -e DB_USERNAME=lychee \
    -e DB_PASSWORD=password \
    -p 8081:80 \
    --network mysqlbridge \
    lycheeorg/lychee

v5.1.0的更新主题是

Version 5.1.0 - Oauth supported for major providers.

刚好对应表oauth_credentials,我认为这并非巧合。

You can also log into the container:

docker exec -it lychee bash

and then

php artisan migrate

But I agree that we need to investigate this migration.

我并不是没有尝试手动迁移,但其报错信息与上文日志中呈现的别无二致。

Yeah... Unfortunately, the Lychee community is very small as I am pretty much the only active developer on this project. My time is very limited:

  • I have a full time job.
  • I have a girlfriend (lucky me).
  • I am a top-sport ballroom dancer (which means ~10h of training per week)
  • I am a photographer (when I have the time)

I am dedicating all my free time left to Lychee (for which I am not paid). I see issues pilling up, I try to resolve them when I can, picking up the most urgent at first.

眼看修复和解决无望,我将会将lychee降级到最后可用的v5.0.3迁移数据并停止使用Lychee

我明白开源社区开发者的困境,也很感谢你这样的无私奉献者,但鉴于目前我基于Lychee的图片服务处于几乎不可用的状态(大概已经持续了1个月),我不能寄希望于一个漫长且不可预测的修复(更何况还在issue被列为低优先级的情况下),暂时停用Lychee实属无奈之举。

d7415 commented 9 months ago

This sounds a lot like #2206, except you're past that version (possibly by starting at 5.0.3?) and you are setting DB_CONNECTION so it can't be the same thing.

I guess it could be worth double checking that /conf/.env in your container has the correct settings (especially DB_CONNECTION) in case that issue has a wider scope than we thought.

DLYSY commented 9 months ago

This sounds a lot like #2206, except you're past that version (possibly by starting at 5.0.3?) and you are setting so it can't be the same thing.DB_CONNECTION

I guess it could be worth double checking that in your container has the correct settings (especially ) in case that issue has a wider scope than we thought./conf/.env``DB_CONNECTION

I have read #2206 before I open this issue. Unfortunately it's helpless.

This is my /conf/.env:

APP_NAME=...
APP_ENV=development
APP_KEY=...
APP_DEBUG=false
APP_URL=...
APP_FORCE_HTTPS=true

# enable or disable debug bar. By default it is disabled.
# Do note that this disable CSP!!
DEBUGBAR_ENABLED=false

# enable or disable log viewer. By default it is enabled.
LOG_VIEWER_ENABLED=true

##############################################################################
# IMPORTANT: To migrate from Lychee v3 you *MUST* use the same MySQL/MariaDB #
#            server as v3.                                                   #
##############################################################################

# Table prefix (e.g. lychee_) of a Lychee v3 instance for migration
DB_OLD_LYCHEE_PREFIX=

# DB_CONNECTION can be sqlite, mysql or pgsql. For sqlite the other entries are
# not required, but an existing sqlite3 database may be specified if desired. In
# this case, please use an absolute path. DB_DATABASE may be omitted but should
# *not* be left blank.
DB_CONNECTION=mysql
DB_HOST=mysql
DB_DATABASE=lychee
DB_USERNAME=lychee
DB_PASSWORD=...
DB_LOG_SQL=false

# List foreign keys in diagnostic page
DB_LIST_FOREIGN_KEYS=true

# Application timezone. If not specified, the server's default timezone is used.
# Requires a named timezone identifier.
# See https://www.php.net/manual/en/timezones.php for the list of supported timezones.
# Don't use a timezone offset (like +01:00) or a timezone abbreviation (like CEST)
TIMEZONE=Asia/Shanghai

# Visibility of directories and (media) files in LYCHEE_UPLOADS
# Possible values are:
#
#  - private: world group has neither read nor write access
#  - public: world group has read access but no write access (the default)
#  - world: world group has read and write access
#
# The default should suffice for most installations.
# For improved security, change this setting to "private".
# Some rare setups may require directories and files to be world writeable.
# In this case, use "world" here.
# USE WITH PRECAUTIONS: world writeable files and folders may be a SECURITY RISK.
# LYCHEE_IMAGE_VISIBILITY=public

# folders in which the files will be stored
# LYCHEE_UPLOADS="/var/www/html/Lychee-Laravel/public/uploads/"
# LYCHEE_DIST="/var/www/html/Lychee-Laravel/public/dist/"
# LYCHEE_SYM="/var/www/html/Lychee-Laravel/public/sym/"
# url to access those files
# LYCHEE_UPLOADS_URL="uploads/"
# LYCHEE_DIST_URL="dist/"
# LYCHEE_SYM_URL="sym/"

# Support for token based authentication used by API requests. Enabled by default.
# ENABLE_TOKEN_AUTH=true

CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
# `sync` if jobs needs to be executed live (default) or `database` if they can be defered.
QUEUE_CONNECTION=sync

SECURITY_HEADER_HSTS_ENABLE=false
SESSION_SECURE_COOKIE=false

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=
MAIL_FROM_NAME=
MAIL_FROM_ADDRESS=

# The trusted proxies if Lychee is behind a reverse proxy
# Accepted values:
#  - `null`: no proxy
#  - `*`: any proxy
#  - <ip address>[,<ip address>]: a comma-seperated list of IP addresses
TRUSTED_PROXIES=null

# Comma-separated list of class names of diagnostics checks that should be skipped.
#SKIP_DIAGNOSTICS_CHECKS=
ildyria commented 9 months ago

I am closing this because the title is clearly a duplicate of #2206 which will be fixed shortly once #2286 is merged.