Skip to content

Commit a296ccf

Browse files
authored
HortusFox: start applying db migrations (#16324)
1 parent f0fc577 commit a296ccf

2 files changed

Lines changed: 41 additions & 11 deletions

File tree

ct/hortusfox.sh

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
33
# Copyright (c) 2021-2026 community-scripts ORG
4-
# Author: MickLesk (CanbiZ)
4+
# Author: MickLesk (CanbiZ) | Co-Author: Tom Frenzel (tomfrenzel)
55
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
66
# Source: https://github.com/danielbrendel/hortusfox-web
77

@@ -34,29 +34,56 @@ function update_script() {
3434
systemctl stop apache2
3535
msg_ok "Stopped Service"
3636

37-
msg_info "Backing up current HortusFox installation"
38-
cd /opt
39-
mv /opt/hortusfox/ /opt/hortusfox-backup
40-
msg_ok "Backed up current HortusFox installation"
37+
cd /opt/hortusfox
38+
if [[ ! -s app/migrations/migrations.list ]]; then
39+
msg_info "Rebuilding HortusFox migration history"
40+
local database_tables
41+
database_tables="$(mariadb -u root -D hortusfox -NBe "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE();")"
42+
: >app/migrations/migrations.list
43+
local migration migration_file table_name
44+
for migration in app/migrations/*.php; do
45+
migration_file="${migration##*/}"
46+
table_name="${migration_file%.php}"
47+
if [[ "$migration_file" == "VersionModel.php" ]] || grep -Fxq "$table_name" <<<"$database_tables"; then
48+
php -r 'echo hash("sha512", $argv[1]), PHP_EOL;' -- "$migration_file" >>app/migrations/migrations.list
49+
fi
50+
done
51+
msg_ok "Rebuilt HortusFox migration history"
52+
fi
53+
if [[ ! -f app/migrations/verhist.json && -f ~/.hortusfox ]]; then
54+
printf '["%s"]\n' "$(<~/.hortusfox)" >app/migrations/verhist.json
55+
fi
56+
57+
create_backup \
58+
/opt/hortusfox/.env \
59+
/opt/hortusfox/app/migrations/migrations.list \
60+
/opt/hortusfox/app/migrations/verhist.json \
61+
/opt/hortusfox/public/img \
62+
/opt/hortusfox/public/attachments \
63+
/opt/hortusfox/public/backup \
64+
/opt/hortusfox/public/exports \
65+
/opt/hortusfox/public/snd \
66+
/opt/hortusfox/public/themes
4167

4268
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "hortusfox" "danielbrendel/hortusfox-web" "tarball"
69+
restore_backup
4370

4471
msg_info "Updating HortusFox"
4572
cd /opt/hortusfox
46-
cp /opt/hortusfox-backup/.env /opt/hortusfox/.env
47-
cp -a /opt/hortusfox-backup/public/img/. /opt/hortusfox/public/img/
4873
export COMPOSER_ALLOW_SUPERUSER=1
4974
$STD composer install --no-dev --optimize-autoloader
75+
$STD php asatru migrate:list
5076
$STD php asatru migrate:upgrade
51-
$STD php asatru plants:attributes
5277
$STD php asatru calendar:classes
78+
$STD php asatru plants:attributes
79+
$STD php asatru aquashell:config
5380
chown -R www-data:www-data /opt/hortusfox
54-
rm -r /opt/hortusfox-backup
5581
msg_ok "Updated HortusFox"
5682

5783
msg_info "Starting Service"
5884
systemctl start apache2
5985
msg_ok "Started Service"
86+
6087
msg_ok "Updated successfully!"
6188
fi
6289
exit

install/hortusfox-install.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Copyright (c) 2021-2026 community-scripts ORG
4-
# Author: MickLesk (CanbiZ)
4+
# Author: MickLesk (CanbiZ) | Co-Author: Tom Frenzel (tomfrenzel)
55
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
66
# Source: https://github.com/danielbrendel/hortusfox-web
77

@@ -36,12 +36,15 @@ msg_ok "Composer dependencies installed"
3636

3737
msg_info "Running DB migration"
3838
$STD php asatru migrate:fresh
39+
HORTUSFOX_VERSION="$(<~/.hortusfox)"
40+
printf '["%s"]\n' "$HORTUSFOX_VERSION" >/opt/hortusfox/app/migrations/verhist.json
3941
msg_ok "Migration finished"
4042

4143
msg_info "Setting up HortusFox"
4244
$STD mariadb -u root -D $MARIADB_DB_NAME -e "INSERT IGNORE INTO AppModel (workspace, language, created_at) VALUES ('Default Workspace', 'en', NOW());"
43-
$STD php asatru plants:attributes
4445
$STD php asatru calendar:classes
46+
$STD php asatru plants:attributes
47+
$STD php asatru aquashell:config
4548
ADMIN_EMAIL="admin@example.com"
4649
ADMIN_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13)"
4750
ADMIN_HASH=$(php -r "echo password_hash('$ADMIN_PASS', PASSWORD_BCRYPT);")

0 commit comments

Comments
 (0)