Skip to content

Simplify fsupgrade-1.sh db-upgrade step: replace temp-file + 3x sed -i with an in-memory pipeline #659

@kojiromike

Description

@kojiromike

What

The per-site DB upgrade block in docker/openemr/7.0.4/upgrade/fsupgrade-1.sh (and its byte-identical copy at docker/openemr/8.0.0/upgrade/fsupgrade-1.sh) writes a TEMPsql_upgrade.php, runs sed -i against it three times with heavy shell-escaped $/bracket noise, runs it with php -f, then deletes it. The whole shuffle can be a single pipeline:

{
    printf '<?php $_GET["site"] = "%s"; ?>' "${sitename}"
    cat /var/www/localhost/htdocs/openemr/sql_upgrade.php
} | sed -e "/input type='submit'/d" \
        -e "s/!empty(\$_POST\['form_submit'\])/empty(\$_POST\['form_submit'\])/" \
        -e "s/^[ \t]*\$form_old_version[ \t=].*\$/\$form_old_version = \"${priorOpenemrVersion}\";/" \
    | php

Why

  • Eliminates a temp file on the image's writable layer.
  • Collapses three sed -i calls into one sed -e … -e … -e ….
  • Removes the -i dependency (GNU-specific flag) and trims shell escaping.

Considerations

  • Verify whether sql_upgrade.php references __FILE__ or __DIR__ — piping to php from stdin changes those values vs php -f <path>. If it does, the pipeline needs a small shim or this change isn't safe.
  • Test the 5.0.1 → 5.0.2 upgrade path against a real fixture before landing.
  • Apply to both 7.0.4 and 8.0.0 copies in lockstep.

Originally suggested by @kojiromike in review of #652.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions