Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to v60.4 fails #96

Closed
leancode opened this issue Nov 15, 2022 · 8 comments
Closed

Upgrade to v60.4 fails #96

leancode opened this issue Nov 15, 2022 · 8 comments
Labels
Bug Stating that it's a feature is just lame - I'll need to fix this sometime soon.

Comments

@leancode
Copy link
Contributor

leancode commented Nov 15, 2022

Today I tried to upgrade from 56 (I think - the last one before the 60 series) and the upgrade failed with this

Screenshot from 2022-11-15 07-54-59

After chasing this around I found the problem to be in setup/mail-users.sh.
The problem is that the script was trying to add the quota column to the users table when it already existed and this was not properly caught by the script. The elif line did not return correctly that the column already existed:

elif sqlite3 $db_path ".schema users" | grep --invert-match quota; then
    echo "ALTER TABLE users ADD COLUMN quota TEXT NOT NULL DEFAULT '0';" | sqlite3 $db_path;
fi

The quick fix was to comment the line out and re-run the install and I am back up and running, but this is a bug.

Trying to nail this down and come up with a solution, I found that:

sqlite3 /home/user-data/mail/users.sqlite ".schema users"

when run in the terminal works and gives the table structure with the quota field as follows:

CREATE TABLE IF NOT EXISTS "users" (
  "id" INTEGER PRIMARY KEY AUTOINCREMENT,
  "email" TEXT NOT NULL,
  "password" TEXT NOT NULL,
  "extra",
  "privileges" TEXT NOT NULL DEFAULT '',
  "quota" TEXT NOT NULL DEFAULT '0',
  "can_sent_as_any" INTEGER,
  UNIQUE ("email" ASC)
);

But notice how this is in multiple lines! So the inverse grep only filters out the quota line and still returns truthy.

I played around with sqllite3 --line option but could not get it to work. Ultimately it worked replacing:

elif sqlite3 $db_path ".schema users" | grep --invert-match quota; then
    echo "ALTER TABLE users ADD COLUMN quota TEXT NOT NULL DEFAULT '0';" | sqlite3 $db_path;
fi

with

else
    sql=$(sqlite3 $db_path "SELECT sql FROM sqlite_schema WHERE name = 'users'");
    if echo $sql | grep --invert-match quota; then
        echo "ALTER TABLE users ADD COLUMN quota TEXT NOT NULL DEFAULT '0';" | sqlite3 $db_path;
    fi
fi

There might be more elegant versions. I am really not a bash expert, but for all it worth I've put that into a pull request here:
#97

leancode added a commit to leancode/power-mailinabox that referenced this issue Nov 15, 2022
This is related to Issue ddavness#96 "Upgrade to v60.4 fails"
@ddavness
Copy link
Owner

Interesting. What distribution/version of sqlite do you happen to be running? Likely because MIAB assumes that .schema users would return everything in one line:

image

@ddavness ddavness added the Bug Stating that it's a feature is just lame - I'll need to fix this sometime soon. label Nov 15, 2022
@leancode
Copy link
Contributor Author

debian 11
sqlite3 --version
3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ealt1

@ddavness
Copy link
Owner

I see, I can kinda reproduce the problem when running .schema users --indent, so I am positive this could be the result of some interaction with some configuration file; What are the contents of /root/.sqliterc?

sudo cat /root/.sqliterc

(It's possible that this is caused by a configuration setting somewhere, however MIAB should still just work around this kind of stuff)

@leancode
Copy link
Contributor Author

cat: /root/.sqliterc: No such file or directory

@leancode
Copy link
Contributor Author

There is nothing in /etc/ either that I can see. This machine's sole purpose is to run the mail server. It was originally a fresh install with only the setup.sh run. There is nothing else on there.

@ddavness
Copy link
Owner

Alright, let's chalk it up to the mysteries of life (or something like that)

@leancode
Copy link
Contributor Author

Yep, something like that. I have really no idea. I am just happy that I was able to debug it and get up and running again fast. Thanks for your fast responses and your great work!

ddavness added a commit that referenced this issue Nov 20, 2022
* Fix bug with quota field detection

This is related to Issue #96 "Upgrade to v60.4 fails"

* Update setup/mail-users.sh

sqlite_schema isn't supported everywhere yet

Co-authored-by: David Duque <github@duqued.net>
@ddavness
Copy link
Owner

Fixed on v60.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Stating that it's a feature is just lame - I'll need to fix this sometime soon.
Projects
None yet
Development

No branches or pull requests

2 participants