Broke ghost-cli updating it while doing a batch ghost update

Issue Summary
I was doing a ghost update batch job in one terminal window and for whatever reason I decided to do a ghost-cli and npm update in another terminal window on the same server… Little did I know… that it will blow up in my face.

Right now no cli command works anymore, it outputs the below error message. I tried to remove /usr/bin/ghost as well as /usr/lib/node_modules/ghost-cli and reinstall ghost-cli but it seems that some mysql connection is stuck somewhere and I don’t know how to unstuck it. Any ghost command (including ghost doctor) fails with the below error. Any help is highly appreciated. Thanks!

Steps to Reproduce

  1. Run sudo npm install -g ghost-cli@latest while there’s a ghost update process runing…
  2. Run also sudo npm install -g npm while there’s a ghost update process running…

Setup information

Ghost Version
4.41.1 to 4.41.2

Node.js Version
14.19.1

How did you install Ghost?
Ghost was installed through ghost install cli command a long time ago.

Provide details of your host & operating system
Ubuntu 20.04.4

Database type
MariaDB 10.3.34

Browser & OS version
N/A

Relevant log / error output

    OS: Ubuntu, v20.04.4 LTS
    Node Version: v14.19.1
    Ghost-CLI Version: 1.19.0
    Environment: production
    Command: 'ghost ls'
An error occurred.
Message: 'Can't add new command when connection is in closed state'

Stack: Error: Can't add new command when connection is in closed state
    at Connection._addCommandClosedState (/usr/lib/node_modules/ghost-cli/node_modules/mysql2/lib/connection.js:148:17)
    at Connection.end (/usr/lib/node_modules/ghost-cli/node_modules/mysql2/lib/connection.js:855:26)
    at MySQLExtension.isDeprecated (/usr/lib/node_modules/ghost-cli/extensions/mysql/index.js:64:25)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /usr/lib/node_modules/ghost-cli/lib/utils/deprecation-checks.js:54:43
    at async Promise.all (index 3)
    at async deprecationChecks (/usr/lib/node_modules/ghost-cli/lib/utils/deprecation-checks.js:36:38)```

Hey @dsecareanu! :wave: Sorry about that! Would you be able to update to Ghost-CLI v1.19.1 with sudo npm install -g ghost-cli@latest - I think that should stop CLI erroring out :slightly_smiling_face:

Hah, yes, this works, why didn’t I think of it as well (tried to force the update, but that didn’t work).

However, the ghost update or ghost ls gets stuck now before confirming the command and existing…

Thanks!

Odd! I’m trying to reproduce the issue but you should be able to downgrade CLI in the mean time - sudo npm install -g ghost-cli@1.18.2

@dsecareanu I believe I’ve found the issue and I’ve published Ghost-CLI 1.19.2. Would you be able to give that a go? - sudo npm install -g ghost-cli@latest

1 Like

Yes, all works now as expected, thanks a lot!

The problem does not seem so easy to resolve when running ghost on a docker container …
Today the site has gone down, not only my site, others that are running on docker with the same configuration are with there sites down.
Can someone take a look?
Here is the log:

ERROR alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Referencing column 'member_id' and referenced column 'id' in foreign key constraint 'members_cancel_events_member_id_foreign' are incompatible.
alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Referencing column 'member_id' and referenced column 'id' in foreign key constraint 'members_cancel_events_member_id_foreign' are incompatible.
{"config":{"transaction":false},"name":"2022-03-07-14-37-add-members-cancel-events-table.js"}
"Error occurred while executing the following migration: 2022-03-07-14-37-add-members-cancel-events-table.js"
Error ID:
    300
----------------------------------------
MigrationScriptError: alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Referencing column 'member_id' and referenced column 'id' in foreign key constraint 'members_cancel_events_member_id_foreign' are incompatible.
    at DatabaseStateManager.makeReady (/var/lib/ghost/versions/4.40.0/core/server/data/db/state-manager.js:95:32)
    at MigrationScriptError.KnexMigrateError (/var/lib/ghost/versions/4.40.0/node_modules/knex-migrator/lib/errors.js:7:26)
    at new MigrationScriptError (/var/lib/ghost/versions/4.40.0/node_modules/knex-migrator/lib/errors.js:25:26)
    at /var/lib/ghost/versions/4.40.0/node_modules/knex-migrator/lib/index.js:1032:19
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
Error: alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Referencing column 'member_id' and referenced column 'id' in foreign key constraint 'members_cancel_events_member_id_foreign' are incompatible.
    at Packet.asError (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/packets/packet.js:728:17)
    at Query.execute (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/commands/command.js:29:26)
    at Connection.handlePacket (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/connection.js:456:32)
    at PacketParser.onPacket (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/connection.js:85:12)
    at PacketParser.executeStart (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/packet_parser.js:75:16)
    at Socket.<anonymous> (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/connection.js:92:25)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
    at readableAddChunk (internal/streams/readable.js:267:9)
    at Socket.Readable.push (internal/streams/readable.js:206:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
[2022-03-23 20:09:46] WARN Ghost is shutting down
[2022-03-23 20:09:46] WARN Ghost has shut down
[2022-03-23 20:09:46] WARN Your site is now offline
[2022-03-23 20:09:46] WARN Ghost was running for a few seconds

Using on the docker composer the command suggested doesn’t seems to resolver

command: sh -c "npm install -g ghost-cli@latest

And here is my docker compose:

version: '3.1'
#volumes:
#  mysql-volume:
#  ghost-volume:

services:
 mysql:  
  image: mysql:8.0
  container_name: mysql_ghost
  volumes:
    - /volume1/docker/Ghost/mysql-volume:/var/lib/mysql
  environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_DATABASE: db
    MYSQL_USER:blog-user
    MYSQL_PASSWORD: XXXXXX

 ghost:
#  build: ./ghost
  image: ghost:latest
  container_name: ghost
  volumes:
    - .../Ghost/content:/var/lib/ghost/content
  restart: always
  ports:
    - 2368:2368
  environment:
    NODE_ENV: production
    url: https://XXXXXX.com
    database__client: mysql
    database__connection__host: mysql
    database__connection__user: blog-user
    database__connection__password: XXXXXXXX
    database__connection__database: db
    mail__transport: SMTP
    mail__from: 'Design RepCom <postmaster@XXXXX>'
    mail__options__service: Mailgun
    mail__options__host: smtp.eu.mailgun.org
    mail__options__port: 587
    mail__options__secureConnection: 'false'
    mail__options__auth__user: 'postmaster@XXXXX'
    mail__options__auth__pass: 'XXXXX'
  depends_on:
    - mysql

@dsecareanu Excellent! :slightly_smiling_face:

@jorgeruimachado Your issue is unrelated, but it’s likely due to this. Please follow the advice in that FAQ

I will try that… Thanks :pray:

I have this:

mysql> show variables like 'character%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8mb4                        |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8mb4                        |
| character_set_system     | utf8mb3                        |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)

Still errors after this change. I was already running with mysql version 8 before this error showed

by now the information regarding de default character set is showing as utf8mb4

ERROR create table `members_cancel_events` (`id` varchar(24) not null, `member_id` varchar(24) not null, `from_plan` varchar(255) not null, `created_at` datetime not null) default character set utf8mb4 - Tablespace '`db`.`members_cancel_events`' exists.
create table `members_cancel_events` (`id` varchar(24) not null, `member_id` varchar(24) not null, `from_plan` varchar(255) not null, `created_at` datetime not null) default character set utf8mb4 - Tablespace '`db`.`members_cancel_events`' exists.
{"config":{"transaction":false},"name":"2022-03-07-14-37-add-members-cancel-events-table.js"}
"Error occurred while executing the following migration: 2022-03-07-14-37-add-members-cancel-events-table.js"
Error ID:
    300
Error Code: 
    ER_TABLESPACE_EXISTS
----------------------------------------
MigrationScriptError: create table `members_cancel_events` (`id` varchar(24) not null, `member_id` varchar(24) not null, `from_plan` varchar(255) not null, `created_at` datetime not null) default character set utf8mb4 - Tablespace '`db`.`members_cancel_events`' exists.
    at DatabaseStateManager.makeReady (/var/lib/ghost/versions/4.40.0/core/server/data/db/state-manager.js:95:32)
    at MigrationScriptError.KnexMigrateError (/var/lib/ghost/versions/4.40.0/node_modules/knex-migrator/lib/errors.js:7:26)
    at new MigrationScriptError (/var/lib/ghost/versions/4.40.0/node_modules/knex-migrator/lib/errors.js:25:26)
    at /var/lib/ghost/versions/4.40.0/node_modules/knex-migrator/lib/index.js:1032:19
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
Error: create table `members_cancel_events` (`id` varchar(24) not null, `member_id` varchar(24) not null, `from_plan` varchar(255) not null, `created_at` datetime not null) default character set utf8mb4 - Tablespace '`db`.`members_cancel_events`' exists.
    at Packet.asError (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/packets/packet.js:728:17)
    at Query.execute (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/commands/command.js:29:26)
    at Connection.handlePacket (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/connection.js:456:32)
    at PacketParser.onPacket (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/connection.js:85:12)
    at PacketParser.executeStart (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/packet_parser.js:75:16)
    at Socket.<anonymous> (/var/lib/ghost/versions/4.40.0/node_modules/mysql2/lib/connection.js:92:25)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
    at readableAddChunk (internal/streams/readable.js:267:9)
    at Socket.Readable.push (internal/streams/readable.js:206:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.