Skip to content

IBX-11939: [Doctrine Migrations] Added Doctrine Migrations-based schema and data install path (inlined SQL) - #785

Merged
Steveb-p merged 35 commits into
4.6from
doctrine-migrations-installer-inline-sql
Oct 5, 2026
Merged

Steveb-p merged 35 commits into
4.6from
doctrine-migrations-installer-inline-sql

Conversation

@Steveb-p

@Steveb-p Steveb-p commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor
Question Answer
JIRA issue IBX-11939
Type feature
Target Ibexa version v4.6
BC breaks no

Note

Test-side companion — ibexa/test-core#57.
Moves the baseline fixture import into its own BaseFixtureHook (priority 950, between the
schema hooks and FixtureHook), switchable with a load_base_fixture option.
It matters here because under the Doctrine Migrations path the baseline repository content
arrives as core's ImportDataMigration rather than as a loaded fixture, and FixtureImporter
truncates every table a fixture touches before inserting — so a package's own fixture writing
into those tables would take the baseline's rows with it unless it implements AppendOnlyFixture.
Packages whose integration tests load their own fixtures depend on it; the rest are unaffected.

Note

Shared library — ibexa/doctrine-migrations.
Every migration in the table below extends the AbstractSqlMigration / SqlPlatform base it provides.
Merged on all three branches:
#1 (4.6 baseline) · #3 (6.0 baseline) · #4 (enable_service_migrations fix) · #6 (DBAL 4).
The fix reached 5.0 and 6.0 via merge-ups #9 and #10 — which is why #5 was closed rather than merged.
Also merged on 4.6: #13 (Ibexa SQL migrations are non-transactional on MySQL) and #19 (SqlPlatform, with MariaDB as a platform of its own).

Related PRs:

Package 4.6 5.0 6.0
ibexa/activity-log #166 #167 #168 ⏭️
ibexa/cart #172 #173 🔄 #174 ⏭️
ibexa/collaboration – #115 #116 ⏭️
ibexa/connector-ai – #198 #199 ⏭️
ibexa/connector-payum ⚠️ #39 #40 #41 🩹
ibexa/core this PR 🩹 #787 🔄 🩹 #788 🩹
ibexa/corporate-account #369 #370 🔄 #371 ⏭️
ibexa/discounts – #341 🩹 #342 🩹 ⏭️
ibexa/discounts-codes – #50 #51 ⏭️
ibexa/doctrine-schema #41 #42 #43
ibexa/fieldtype-page #208 🩹 #209 🔄 🩹 #210 🩹 ⏭️
ibexa/form-builder #240 🩹 #241 🔄 🩹 #242 🩹 ⏭️
ibexa/measurement #133 #134 🔄 #135 ⏭️
ibexa/messenger – #22 #23
ibexa/migrations #438 #439 #440 ⏭️
ibexa/oauth2-server 🔄 #48 #49 #50 ⏭️
ibexa/order-management #188 #189 🔄 #190
ibexa/payment #204 #205 🔄 #206 ⏭️
ibexa/product-catalog #1543 #1544 🔄 #1545 ⏭️
ibexa/product-catalog-date-time-attribute – #53 #54 ⏭️
ibexa/product-catalog-symbol-attribute – #17 #18 ⏭️
ibexa/scheduler #168 #169 🔄 #170 ⏭️
ibexa/segmentation #186 #187 🔄 #188 🩹
ibexa/share – #190 #191 ⏭️
ibexa/shipping #154 #155 🔄 #156 ⏭️
ibexa/shopping-list – #66 #67 ⏭️
ibexa/site-context – – #121
ibexa/site-factory #172 #173 🔄 🩹 #174 🩹 ⏭️
ibexa/taxonomy ⚠️ #431 🩹 #432 🩹 #433 🩹
ibexa/translations-management – #174 #175 ⏭️
ibexa/user #128 #129 🔄 #130 ⏭️
ibexa/workflow #191 🩹 #192 🔄 🩹 #193 🩹 ⏭️

🔄 = this branch adds an upgrade migration (renames/FK-retargets existing schema), not just a fresh baseline.
🩹 = this branch also received a backported delta migration, converted from a legacy ibexa/installer upgrade/db/*.sql script (4.6.0 or later) that the original baseline-only migration didn't cover. See IBX-11939 upgrade-scripts backport report or that package's own PR description for details.
⚠️ = fixes a different, related problem (missing SchemaBuilderEvent support for a plain Doctrine ORM entity/table) — not a Doctrine Migrations baseline/upgrade migration like the rest of this table. See that package's own PR description for details.
⏭️ = struck through and closed as unnecessary — that tier needs no changes of its own. Everything it requires arrives through the normal merge-up from the tier below; the branch is kept, so the PR can be reopened if genuinely tier-specific work turns up.

Alternative to #784, using the same IbexaMigrationInterface + IbexaMigrationTag + TaggedMigrationsRunner/IbexaOnlyDependencyFactory mechanism, but with InstallSchemaMigration/ImportDataMigration implemented as plain Doctrine\Migrations\AbstractMigration subclasses with all SQL inlined directly in PHP (via addSql()), instead of Ibexa's AbstractVersion + YAML manifest + one-SQL-statement-per-file mechanism. This drops the 509 generated YAML/SQL resource files in favor of two self-contained PHP migration classes.

Adds an ibexa/doctrine-migrations-based alternative to the event-driven SchemaBuilderEvent mechanism CoreInstaller currently uses to install the core schema and bootstrap data, controlled by a new ibexa.installer.schema_builder_event.enabled setting (defaults to true, preserving current behavior).

  • Enabled (default): CoreInstaller keeps dispatching SchemaBuilderEvent and importing cleandata.sql directly - unchanged.
  • Disabled: schema creation and data import are each modeled as a Doctrine migration (InstallSchemaMigration, ImportDataMigration), tagged with IbexaMigrationTag for discovery, and executed via TaggedMigrationsRunner through IbexaOnlyDependencyFactory - an independent Doctrine Migrations DependencyFactory scoped to only Ibexa-tagged migrations, so a project's own migrations are never accidentally picked up. The runner hands each migration to Doctrine's Migrator (DependencyFactory::getMigrator()), the same one ibexa:doctrine:migrations:migrate uses, so each runs in its own transaction where the platform allows it, and a failure throws MigrationFailedException, naming the migration it came from. Each migration's execution is recorded in the standard Doctrine Migrations versioning table, making repeated installs idempotent.

InstallSchemaMigration's SQL (mysql/postgresql/sqlite) is generated from the existing schema.yaml; ImportDataMigration's SQL is generated from the existing per-DBMS cleandata.sql files, with the mysql statements also reused verbatim for sqlite (which previously had no cleandata support at all). Long or naturally multi-line statements (CREATE TABLE, multi-row INSERT, long ALTER TABLE ... ADD CONSTRAINT) use PHP NOWDOC for readability; verified byte-for-byte equivalent (aside from whitespace) to the SQL produced by #784.

Requires ibexa/doctrine-migrations (~4.6.x-dev).

OrmEntitiesSchemaSubscriber, which contributes the tables of plain Doctrine ORM entities to SchemaBuilderEvent (ibexa/taxonomy#431 and ibexa/connector-payum#39 use it), was extracted into #852 and is already on 4.6, so it's no longer part of this PR.

For QA:

ibexa-4.6-install-matrix.sh (below) installs Ibexa DXP 4.6 with this PR and the other IBX-11939 4.6 PRs pinned in, for headless, experience and commerce on MariaDB, MySQL and PostgreSQL - 9 installs, each into a fresh database. It uses the Doctrine Migrations install path by default; -p legacy runs the old SchemaBuilderEvent path into separate databases, and once both have run, the script also compares their tables.

You'll need Docker, PHP 7.4-8.3, composer 2 with updates.ibexa.co credentials that can see development branches (plus a GitHub token for the ibexa org), and node with yarn 1.x - the installer's data migrations need built assets. --skip-assets stubs them out if you only care about the database, but then the back office can't be browsed.

chmod +x ibexa-4.6-install-matrix.sh
./ibexa-4.6-install-matrix.sh -p legacy   # the old path first, as a baseline
./ibexa-4.6-install-matrix.sh             # the Doctrine Migrations path, compared against it

An install is marked OK when ibexa:install succeeds, the database has content and an admin user, the log shows the expected path ran, the doctrine:schema:update the installer runs part-way through has nothing left to create, and - on the migrations path - every tagged migration was executed. What I got locally, the same on all three databases:

Edition Content objects Migrations executed
headless 19 12
experience 30 20
commerce 31 25

The logs show a few "Migration ... was executed but did not result in any SQL statements" warnings - those are index migrations with nothing to add on a fresh install. ibexa/oauth2-server#48 isn't part of any edition, so it isn't covered. --help lists the rest (a single edition or database, other images and ports, --teardown).

To switch an existing 4.6 project over by hand instead, you need this PR and the other IBX-11939 4.6 PRs installed; the script's BRANCHES map lists them. ibexa/doctrine-migrations comes in through ibexa/installer#213 but has no Flex recipe yet, so register its bundle next to DoctrineMigrationsBundle, which the 4.6 skeletons already have:

// config/bundles.php
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Ibexa\Bundle\DoctrineMigrations\IbexaDoctrineMigrationsBundle::class => ['all' => true],

Then turn off the event-driven schema building. It defaults to true, which keeps the old SchemaBuilderEvent path:

# config/packages/ibexa_installer.yaml
ibexa:
    installer:
        schema_builder_event:
            enabled: false

After clearing the cache, ibexa:install runs the tagged migrations instead. The log then says "Executed N queries on database" with no progress bar, where the old path says "Executing N queries" with one. ibexa:doctrine:migrations:status should show nothing new afterwards. With enabled: false but no bundle, ibexa:install stops at the schema import with an error naming the missing service.

ibexa-4.6-install-matrix.sh
#!/usr/bin/env bash
#
# QA install matrix for IBX-11939 on Ibexa DXP 4.6.
#
# Builds one project per edition (headless, experience, commerce) with the IBX-11939 pull request
# branches pinned in, then runs `ibexa:install` against a fresh database on each engine (MariaDB,
# MySQL, PostgreSQL), by default through the new Doctrine Migrations install path. Each install is
# checked and the results are summarised at the end.
#
# Requirements: docker, PHP 7.4-8.3 with pdo_mysql and pdo_pgsql, composer 2, node with yarn 1.x
# (unless --skip-assets), and composer credentials for updates.ibexa.co (with access to development
# branches) plus a github.com token with access to the ibexa organisation. Run with --help for the
# options.

set -uo pipefail

SKELETON_VERSION_DEFAULT='~4.6.0'
EDITIONS_DEFAULT='headless,experience,commerce'
DATABASES_DEFAULT='mariadb,mysql,postgresql'

# The pull request branches under test. A package is only pinned in the editions that install it.
declare -A BRANCHES=(
    [core]='doctrine-migrations-installer-inline-sql'                   # ibexa/core#785
    [installer]='doctrine-migrations-installer-inline-sql'              # ibexa/installer#213
    [doctrine-schema]='feature/dump-sql-sqlite-platform-4.6'            # ibexa/doctrine-schema#41
    [taxonomy]='feature/schema-builder-event-taxonomy-4.6'              # ibexa/taxonomy#431
    [connector-payum]='feature/schema-builder-event-payment-token-4.6'  # ibexa/connector-payum#39
    [activity-log]='feature/schema-migration-4.6'                       # ibexa/activity-log#166
    [cart]='feature/schema-migration-4.6'                               # ibexa/cart#172
    [corporate-account]='feature/schema-migration-4.6'                  # ibexa/corporate-account#369
    [fieldtype-page]='feature/schema-migration-4.6'                     # ibexa/fieldtype-page#208
    [form-builder]='feature/schema-migration-4.6'                       # ibexa/form-builder#240
    [measurement]='feature/schema-migration-4.6'                        # ibexa/measurement#133
    [migrations]='feature/schema-migration-4.6'                         # ibexa/migrations#438
    [order-management]='feature/schema-migration-4.6'                   # ibexa/order-management#188
    [payment]='feature/schema-migration-4.6'                            # ibexa/payment#204
    [product-catalog]='feature/schema-migration-4.6'                    # ibexa/product-catalog#1543
    [scheduler]='feature/schema-migration-4.6'                          # ibexa/scheduler#168
    [segmentation]='feature/schema-migration-4.6'                       # ibexa/segmentation#186
    [shipping]='feature/schema-migration-4.6'                           # ibexa/shipping#154
    [site-factory]='feature/schema-migration-4.6'                       # ibexa/site-factory#172
    [user]='feature/schema-migration-4.6'                               # ibexa/user#128
    [workflow]='feature/schema-migration-4.6'                           # ibexa/workflow#191
)

DB_PASSWORD="${DB_PASSWORD:-ibexa}"
MARIADB_IMAGE="${MARIADB_IMAGE:-mariadb:10.11}"
MYSQL_IMAGE="${MYSQL_IMAGE:-mysql:8.0}"
POSTGRES_IMAGE="${POSTGRES_IMAGE:-postgres:14}"
MARIADB_PORT="${MARIADB_PORT:-13307}"
MYSQL_PORT="${MYSQL_PORT:-13306}"
POSTGRES_PORT="${POSTGRES_PORT:-15432}"
CONTAINER_PREFIX='ibexa-qa-46'
# Marks a directory as created by this script, so --clean never deletes anything else.
WORKDIR_MARKER='.ibexa-qa-install-matrix'

read -ra PHP <<< "${PHP_BIN:-php}"
read -ra COMPOSER <<< "${COMPOSER_BIN:-composer}"
export COMPOSER_MEMORY_LIMIT=-1

usage() {
    cat <<EOF
Usage: $(basename "$0") [options]

Installs Ibexa DXP 4.6 with the IBX-11939 pull requests for every edition/database combination.
An install passes when ibexa:install succeeds, the database has content and an admin user, the
log shows the expected install path ran, doctrine:schema:update (which the installer runs part-way
through) had nothing left to create, and - on the Doctrine Migrations path - every tagged migration
was executed. Once both install paths have run, their table lists must match too.

Options:
  -e, --editions LIST       Comma-separated editions (default: ${EDITIONS_DEFAULT})
  -d, --databases LIST      Comma-separated databases (default: ${DATABASES_DEFAULT})
  -p, --install-path PATH   'migrations' (default) for the new Doctrine Migrations install path,
                            'legacy' for the SchemaBuilderEvent path. Each path installs into its own
                            databases; once both have run, their table lists are compared
  -w, --workdir DIR         Where projects and logs are created (default: ./ibexa-qa-4.6)
  -s, --skeleton VERSION    Skeleton version to start from (default: ${SKELETON_VERSION_DEFAULT})
      --skip-assets         Don't build frontend assets (saves a few minutes per edition). The installs
                            still work, but the back office can't be browsed afterwards
      --rebuild             Rebuild existing projects instead of reusing them
      --clean               Remove this script's containers and work directory before starting
      --teardown            Remove this script's containers and work directory, then exit
  -h, --help                Show this help

Environment overrides:
  PHP_BIN, COMPOSER_BIN     Commands to run PHP and composer (e.g. PHP_BIN="symfony php")
  MARIADB_IMAGE, MYSQL_IMAGE, POSTGRES_IMAGE   (default: ${MARIADB_IMAGE}, ${MYSQL_IMAGE}, ${POSTGRES_IMAGE})
  MARIADB_PORT, MYSQL_PORT, POSTGRES_PORT      Host ports (default: ${MARIADB_PORT}, ${MYSQL_PORT}, ${POSTGRES_PORT})
  DB_PASSWORD               Database root password (default: ibexa)

Examples:
  $(basename "$0")                                    # all 9 combinations
  $(basename "$0") -e commerce -d postgresql          # a single combination
  $(basename "$0") -p legacy && $(basename "$0")      # both paths, comparing their tables
EOF
}

info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33mWARNING:\033[0m %s\n' "$*" >&2; }
die() { printf '\033[1;31mERROR:\033[0m %s\n' "$*" >&2; exit 1; }

EDITIONS="$EDITIONS_DEFAULT"
DATABASES="$DATABASES_DEFAULT"
INSTALL_PATH='migrations'
WORKDIR='./ibexa-qa-4.6'
SKELETON_VERSION="$SKELETON_VERSION_DEFAULT"
SKIP_ASSETS=0
REBUILD=0
CLEAN=0
TEARDOWN=0

while [[ $# -gt 0 ]]; do
    case "$1" in
        -e|--editions) EDITIONS="${2:?}"; shift 2 ;;
        -d|--databases) DATABASES="${2:?}"; shift 2 ;;
        -p|--install-path) INSTALL_PATH="${2:?}"; shift 2 ;;
        -w|--workdir) WORKDIR="${2:?}"; shift 2 ;;
        -s|--skeleton) SKELETON_VERSION="${2:?}"; shift 2 ;;
        --skip-assets) SKIP_ASSETS=1; shift ;;
        --rebuild) REBUILD=1; shift ;;
        --clean) CLEAN=1; shift ;;
        --teardown) TEARDOWN=1; shift ;;
        -h|--help) usage; exit 0 ;;
        *) usage >&2; die "Unknown option: $1" ;;
    esac
done

IFS=',' read -ra EDITION_LIST <<< "$EDITIONS"
IFS=',' read -ra DATABASE_LIST <<< "$DATABASES"
for edition in "${EDITION_LIST[@]}"; do
    [[ "$edition" =~ ^(headless|experience|commerce)$ ]] || die "Unknown edition: $edition"
done
for database in "${DATABASE_LIST[@]}"; do
    [[ "$database" =~ ^(mariadb|mysql|postgresql)$ ]] || die "Unknown database: $database"
done
[[ "$INSTALL_PATH" =~ ^(migrations|legacy)$ ]] || die "--install-path must be 'migrations' or 'legacy'"

mkdir -p "$WORKDIR" && WORKDIR="$(cd "$WORKDIR" && pwd)"
LOG_DIR="$WORKDIR/logs"

remove_everything() {
    info "Removing containers ${CONTAINER_PREFIX}-*"
    for database in mariadb mysql postgresql; do
        docker rm -f -v "${CONTAINER_PREFIX}-${database}" >/dev/null 2>&1 || true
    done
    if [[ -f "$WORKDIR/$WORKDIR_MARKER" ]]; then
        info "Removing $WORKDIR"
        rm -rf "$WORKDIR"
    elif [[ -n "$(ls -A "$WORKDIR" 2>/dev/null)" ]]; then
        warn "$WORKDIR wasn't created by this script, leaving it alone"
    fi
}

if [[ $TEARDOWN -eq 1 ]]; then
    remove_everything
    exit 0
fi
if [[ $CLEAN -eq 1 ]]; then
    remove_everything
fi
mkdir -p "$LOG_DIR" && touch "$WORKDIR/$WORKDIR_MARKER"

check_prerequisites() {
    command -v docker >/dev/null || die "docker is required"
    docker info >/dev/null 2>&1 || die "docker is installed but not running, or not accessible to $(whoami)"
    "${PHP[@]}" -v >/dev/null 2>&1 || die "PHP not found (set PHP_BIN)"
    "${COMPOSER[@]}" --version >/dev/null 2>&1 || die "composer not found (set COMPOSER_BIN)"

    local php_version
    php_version="$("${PHP[@]}" -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')"
    case "$php_version" in
        7.4|8.0|8.1|8.2|8.3) ;;
        *) warn "Ibexa DXP 4.6 supports PHP 7.4-8.3, found $php_version" ;;
    esac
    for extension in pdo_mysql pdo_pgsql intl gd xsl; do
        "${PHP[@]}" -m 2>/dev/null | grep -qix "$extension" || warn "PHP extension '$extension' isn't loaded"
    done
    if [[ $SKIP_ASSETS -eq 0 ]]; then
        command -v node >/dev/null && command -v yarn >/dev/null \
            || die "Building frontend assets needs node and yarn 1.x (or pass --skip-assets)"
    fi
    if [[ -z "${COMPOSER_AUTH:-}" ]]; then
        "${COMPOSER[@]}" config --global http-basic.updates.ibexa.co >/dev/null 2>&1 \
            || warn "No composer credentials for updates.ibexa.co found; the development branches won't resolve without them"
        "${COMPOSER[@]}" config --global github-oauth.github.com >/dev/null 2>&1 \
            || warn "No github.com token configured for composer; downloading the branches may fail"
    fi
}

container_name() { echo "${CONTAINER_PREFIX}-$1"; }

database_port() {
    case "$1" in
        mariadb) echo "$MARIADB_PORT" ;;
        mysql) echo "$MYSQL_PORT" ;;
        postgresql) echo "$POSTGRES_PORT" ;;
    esac
}

start_database() {
    local database="$1" name port
    name="$(container_name "$database")"
    port="$(database_port "$database")"

    if [[ "$(docker inspect -f '{{.State.Running}}' "$name" 2>/dev/null)" == 'true' ]]; then
        info "Reusing running container $name (127.0.0.1:$port)"
    else
        docker rm -f -v "$name" >/dev/null 2>&1 || true
        info "Starting $name on 127.0.0.1:$port"
        case "$database" in
            mariadb)
                docker run -d -q --name "$name" -p "127.0.0.1:$port:3306" -e MARIADB_ROOT_PASSWORD="$DB_PASSWORD" \
                    "$MARIADB_IMAGE" --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_520_ci >/dev/null ;;
            mysql)
                docker run -d -q --name "$name" -p "127.0.0.1:$port:3306" -e MYSQL_ROOT_PASSWORD="$DB_PASSWORD" \
                    "$MYSQL_IMAGE" --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_520_ci >/dev/null ;;
            postgresql)
                docker run -d -q --name "$name" -p "127.0.0.1:$port:5432" -e POSTGRES_PASSWORD="$DB_PASSWORD" \
                    "$POSTGRES_IMAGE" >/dev/null ;;
        esac || die "Couldn't start $name - is port $port already taken? Set $(tr '[:lower:]' '[:upper:]' <<< "${database/postgresql/postgres}")_PORT to use another one"
    fi

    # Probes go over TCP: the images' initialisation phase runs a temporary server without
    # networking, so a socket-based probe would succeed too early.
    local attempt
    for attempt in $(seq 1 90); do
        case "$database" in
            mariadb) docker exec "$name" mariadb-admin ping -h 127.0.0.1 -uroot -p"$DB_PASSWORD" --silent >/dev/null 2>&1 && return 0 ;;
            mysql) docker exec "$name" mysqladmin ping -h 127.0.0.1 -uroot -p"$DB_PASSWORD" --silent >/dev/null 2>&1 && return 0 ;;
            postgresql) docker exec "$name" pg_isready -h 127.0.0.1 -U postgres >/dev/null 2>&1 && return 0 ;;
        esac
        sleep 2
    done
    die "$name didn't become ready; see 'docker logs $name'"
}

# Runs a SQL query in the database's own container, printing the bare result.
query() {
    local database="$1" dbname="$2" sql="$3" name
    name="$(container_name "$database")"
    case "$database" in
        mariadb) docker exec "$name" mariadb -uroot -p"$DB_PASSWORD" -N -B -e "$sql" "$dbname" 2>/dev/null ;;
        mysql) docker exec "$name" mysql -uroot -p"$DB_PASSWORD" -N -B -e "$sql" "$dbname" 2>/dev/null ;;
        postgresql) docker exec "$name" psql -U postgres -d "$dbname" -tA -c "$sql" 2>/dev/null ;;
    esac
}

# Lists a database's tables, without the Doctrine Migrations bookkeeping table only one path creates.
list_tables() {
    local database="$1" dbname="$2" schema_filter
    [[ "$database" == 'postgresql' ]] && schema_filter="table_schema = 'public'" || schema_filter="table_schema = '$dbname'"
    query "$database" "$dbname" "SELECT table_name FROM information_schema.tables WHERE $schema_filter AND table_name <> 'doctrine_migration_versions' ORDER BY table_name" | sort
}

write_env_local() {
    local project="$1" database="$2" dbname="$3" port
    port="$(database_port "$database")"
    case "$database" in
        mariadb)
            printf 'DATABASE_URL="mysql://root:%s@127.0.0.1:%s/%s?serverVersion=mariadb-%s&charset=utf8mb4"\nDATABASE_CHARSET=utf8mb4\nDATABASE_COLLATION=utf8mb4_unicode_520_ci\n' \
                "$DB_PASSWORD" "$port" "$dbname" "$(docker exec "$(container_name mariadb)" mariadb -uroot -p"$DB_PASSWORD" -N -B -e 'SELECT VERSION()' 2>/dev/null | cut -d- -f1)" ;;
        mysql)
            printf 'DATABASE_URL="mysql://root:%s@127.0.0.1:%s/%s?serverVersion=%s&charset=utf8mb4"\nDATABASE_CHARSET=utf8mb4\nDATABASE_COLLATION=utf8mb4_unicode_520_ci\n' \
                "$DB_PASSWORD" "$port" "$dbname" "${MYSQL_IMAGE##*:}" ;;
        postgresql)
            printf 'DATABASE_URL="postgresql://postgres:%s@127.0.0.1:%s/%s?serverVersion=%s&charset=utf8"\nDATABASE_CHARSET=utf8\n' \
                "$DB_PASSWORD" "$port" "$dbname" "${POSTGRES_IMAGE##*:}" ;;
    esac > "$project/.env.local.$database-$INSTALL_PATH"
    cp "$project/.env.local.$database-$INSTALL_PATH" "$project/.env.local"
}

build_project() {
    local edition="$1" project="$WORKDIR/$edition" log="$LOG_DIR/$edition-build.log"

    if [[ -f "$project/.qa-build-complete" && $REBUILD -eq 0 ]]; then
        info "[$edition] Reusing the project in $project (--rebuild to start over)"
        write_install_path_config "$project"
        prepare_assets "$edition"
        return
    fi
    rm -rf "$project"

    info "[$edition] Creating the project from ibexa/$edition-skeleton:$SKELETON_VERSION (log: $log)"
    "${COMPOSER[@]}" create-project --no-install --no-scripts --no-interaction \
        "ibexa/$edition-skeleton:$SKELETON_VERSION" "$project" > "$log" 2>&1 \
        || { warn "[$edition] create-project failed, see $log"; return 1; }

    # The skeleton's own lock file lists every package the edition installs.
    local -a requirements=("ibexa/$edition:4.6.x-dev")
    local package
    for package in "${!BRANCHES[@]}"; do
        if grep -q "\"name\": \"ibexa/$package\"" "$project/composer.lock"; then
            requirements+=("ibexa/$package:dev-${BRANCHES[$package]} as 4.6.x-dev")
        fi
    done

    info "[$edition] Pinning ${#requirements[@]} requirements and updating (this takes a few minutes)"
    (
        cd "$project" \
            && "${COMPOSER[@]}" config minimum-stability dev \
            && "${COMPOSER[@]}" config prefer-stable true \
            && "${COMPOSER[@]}" require --no-update --no-interaction "${requirements[@]}" \
            && "${COMPOSER[@]}" update --no-scripts --no-interaction --with-all-dependencies
    ) >> "$log" 2>&1 || {
        warn "[$edition] composer update failed, see $log"
        grep -q -i -E 'could not be found|found .* but' "$log" \
            && warn "[$edition] A branch didn't resolve: check your updates.ibexa.co credentials give access to development branches"
        return 1
    }

    # ibexa/doctrine-migrations has no Flex recipe, so its bundle has to be registered by hand.
    if ! grep -q 'IbexaDoctrineMigrationsBundle' "$project/config/bundles.php"; then
        sed -i.bak "s#^\(\s*\)Doctrine\\\\Bundle\\\\MigrationsBundle\\\\DoctrineMigrationsBundle::class => \['all' => true\],#&\n\1Ibexa\\\\Bundle\\\\DoctrineMigrations\\\\IbexaDoctrineMigrationsBundle::class => ['all' => true],#" \
            "$project/config/bundles.php" && rm -f "$project/config/bundles.php.bak"
        grep -q 'IbexaDoctrineMigrationsBundle' "$project/config/bundles.php" \
            || { warn "[$edition] Couldn't register IbexaDoctrineMigrationsBundle in config/bundles.php"; return 1; }
    fi

    write_install_path_config "$project"

    prepare_assets "$edition" || return 1

    # Records exactly which commits this edition was built from, for the test report.
    {
        echo "Built $(date -Iseconds) from ibexa/$edition-skeleton:$SKELETON_VERSION"
        for package in $(printf '%s\n' "${!BRANCHES[@]}" | sort); do
            (cd "$project" && "${COMPOSER[@]}" show "ibexa/$package" 2>/dev/null) \
                | awk -v p="ibexa/$package" '$1 == "source" && $3 == "[git]" {print p, $NF}'
        done
    } > "$project/tested-commits.txt"

    touch "$project/.qa-build-complete"
}

# The installer's data migrations resolve asset URLs, so a 4.6 install needs at least an asset
# manifest. A real one comes from the skeleton's own auto-scripts (yarn install plus the Encore
# builds); --skip-assets writes an empty one instead.
prepare_assets() {
    local edition="$1" project="$WORKDIR/$1" log="$LOG_DIR/$1-build.log"
    if [[ $SKIP_ASSETS -eq 1 ]]; then
        if [[ ! -f "$project/public/build/manifest.json" ]]; then
            mkdir -p "$project/public/build" && echo '{}' > "$project/public/build/manifest.json"
        fi
        return 0
    fi
    [[ -f "$project/.qa-assets-built" ]] && return 0

    info "[$edition] Building frontend assets (this takes a few minutes)"
    (cd "$project" && "${COMPOSER[@]}" run-script auto-scripts) >> "$log" 2>&1 \
        || { warn "[$edition] Building frontend assets failed, see $log (or pass --skip-assets)"; return 1; }
    touch "$project/.qa-assets-built"
}

write_install_path_config() {
    local project="$1" enabled='false'
    [[ "$INSTALL_PATH" == 'legacy' ]] && enabled='true'
    cat > "$project/config/packages/ibexa_qa_install_path.yaml" <<EOF
# Written by $(basename "$0"): 'false' installs through the Doctrine Migrations path (IBX-11939),
# 'true' through the legacy SchemaBuilderEvent path.
ibexa:
    installer:
        schema_builder_event:
            enabled: $enabled
EOF
}

declare -A RESULTS=()

install_variant() {
    local edition="$1" database="$2" project="$WORKDIR/$1" dbname="ibexa_$1_${INSTALL_PATH}"
    local log="$LOG_DIR/$edition-$database-$INSTALL_PATH.log" started=$SECONDS

    info "[$edition/$database] Installing into $dbname (log: $log)"
    write_env_local "$project" "$database" "$dbname"
    rm -rf "$project/var/cache"

    local console=("${PHP[@]}" -d memory_limit=-1 bin/console --no-interaction)
    if ! (
        cd "$project" \
            && "${console[@]}" doctrine:database:drop --force --if-exists \
            && "${console[@]}" doctrine:database:create \
            && "${console[@]}" ibexa:install "ibexa-$edition"
    ) > "$log" 2>&1; then
        RESULTS["$edition/$database"]="FAIL  ibexa:install failed, see $log"
        warn "[$edition/$database] ibexa:install failed, see $log"
        return
    fi

    local problems=() content_count admin_count
    content_count="$(query "$database" "$dbname" 'SELECT COUNT(*) FROM ezcontentobject')"
    admin_count="$(query "$database" "$dbname" "SELECT COUNT(*) FROM ezuser WHERE login = 'admin'")"
    [[ "${content_count:-0}" -gt 0 ]] || problems+=('no content objects')
    [[ "${admin_count:-0}" -eq 1 ]] || problems+=('no admin user')
    # The installer's provisioners run doctrine:schema:update part-way through. If it has anything to
    # do, the schema install missed an ORM-mapped table, which this would otherwise paper over.
    grep -q -i 'schema updated successfully' "$log" && problems+=('doctrine:schema:update had to change the schema')

    if [[ "$INSTALL_PATH" == 'migrations' ]]; then
        # The schema step reports "Executed N queries on database" on the Doctrine Migrations path and
        # "Executing N queries on database" on the legacy one (the installer's own SQL files say "from").
        grep -q -E 'Executed [0-9]+ queries on database' "$log" || problems+=('no Doctrine Migrations schema install in the log')
        grep -q -E 'Executing [0-9]+ queries on database' "$log" && problems+=('the legacy schema path ran instead')
        local status new executed
        status="$(cd "$project" && "${console[@]}" ibexa:doctrine:migrations:status 2>&1)"
        echo "$status" >> "$log"
        new="$(awk -F'|' '$3 ~ /^ *New *$/ {gsub(/ /, "", $4); print $4}' <<< "$status")"
        executed="$(awk -F'|' '$3 ~ /^ *Executed *$/ {gsub(/ /, "", $4); print $4}' <<< "$status")"
        [[ "${new:-x}" == '0' && "${executed:-0}" -gt 0 ]] \
            || problems+=("migrations status: executed=${executed:-?} new=${new:-?}")
    fi

    if [[ "$INSTALL_PATH" == 'legacy' ]]; then
        grep -q -E 'Executing [0-9]+ queries on database' "$log" || problems+=('no legacy schema install in the log')
    fi

    # Once both install paths have run for this edition and database, their tables should match,
    # apart from the Doctrine Migrations bookkeeping table.
    local other='legacy' comparison='' ours theirs
    [[ "$INSTALL_PATH" == 'legacy' ]] && other='migrations'
    theirs="$(list_tables "$database" "ibexa_${edition}_${other}")"
    if [[ -n "$theirs" ]]; then
        ours="$(list_tables "$database" "$dbname")"
        if [[ "$ours" == "$theirs" ]]; then
            comparison=", same tables as the $other install"
        else
            problems+=("tables differ from the $other install: $(diff <(echo "$ours") <(echo "$theirs") | grep '^[<>]' | tr '\n' ' ')")
        fi
    fi

    local duration=$((SECONDS - started))
    if [[ ${#problems[@]} -eq 0 ]]; then
        RESULTS["$edition/$database"]="OK    ${content_count} content objects$([[ "$INSTALL_PATH" == 'migrations' ]] && echo ", ${executed} migrations executed")${comparison} (${duration}s)"
    else
        RESULTS["$edition/$database"]="FAIL  $(IFS=';'; echo "${problems[*]}"), see $log"
        warn "[$edition/$database] ${problems[*]}"
    fi
}

check_prerequisites
info "Install path: $INSTALL_PATH | editions: $EDITIONS | databases: $DATABASES | work directory: $WORKDIR"

for database in "${DATABASE_LIST[@]}"; do
    start_database "$database"
done

for edition in "${EDITION_LIST[@]}"; do
    if ! build_project "$edition"; then
        for database in "${DATABASE_LIST[@]}"; do
            RESULTS["$edition/$database"]="FAIL  project build failed, see $LOG_DIR/$edition-build.log"
        done
        continue
    fi
    for database in "${DATABASE_LIST[@]}"; do
        install_variant "$edition" "$database"
    done
done

echo
info "Results ($INSTALL_PATH install path)"
failed=0
for edition in "${EDITION_LIST[@]}"; do
    for database in "${DATABASE_LIST[@]}"; do
        result="${RESULTS["$edition/$database"]}"
        printf '  %-22s %s\n' "$edition/$database" "$result"
        [[ "$result" == OK* ]] || failed=1
    done
done
cat <<EOF

Projects: $WORKDIR/<edition> (the commits each was built from are in tested-commits.txt)
Logs:     $LOG_DIR
Each project's .env.local points at the database installed last. To switch, copy one of the
.env.local.<database>-<install path> files over it and clear the cache (rm -rf var/cache). The
databases keep running for inspection; remove everything with: $0 --teardown -w $WORKDIR
EOF
exit $failed

Checklist:

  • Provided PR description.
  • Tested the solution manually.
  • Provided automated test coverage.
  • Checked that target branch is set correctly (main for features, the oldest supported for bugs).
  • Ran PHP CS Fixer for new PHP code (use $ composer fix-cs).
  • Asked for a review (ping @ibexa/engineering).

@Steveb-p

Copy link
Copy Markdown
Contributor Author

Companion PR in ibexa/installer, adjusting AbstractProductInstaller for CoreInstaller's new constructor arguments: ibexa/installer#213

@Steveb-p
Steveb-p requested a review from a team July 20, 2026 07:34
@ibexa-workflow-automation-1
ibexa-workflow-automation-1 Bot requested review from ViniTou, alongosz, barw4, bnowak, ciastektk, konradoboza, mikadamczyk, tbialcz and wiewiurdp and removed request for a team July 20, 2026 07:34
@Steveb-p
Steveb-p force-pushed the doctrine-migrations-installer-inline-sql branch from 7114546 to 4e9c810 Compare July 24, 2026 11:12
Steveb-p added a commit that referenced this pull request Jul 24, 2026
Replaces the AbstractVersion + YAML manifest + one-SQL-statement-per-file
mechanism with InstallSchemaMigration/ImportDataMigration implemented as
plain Doctrine\Migrations\AbstractMigration subclasses with all SQL inlined
via addSql(), still implementing IbexaMigrationInterface and tagged with
IbexaMigrationTag so TaggedMigrationsRunner/IbexaOnlyDependencyFactory work
unchanged. Long/multiline statements use PHP NOWDOC for readability, with
CREATE TABLE bodies pretty-printed one column per line.

Same conversion as #785 for the 4.6 line, adapted for this
branch's ibexa_*-renamed schema and dbal 3.x platform class names
(AbstractMySQLPlatform/PostgreSQLPlatform instead of MySqlPlatform/
PostgreSqlPlatform).
Steveb-p added a commit that referenced this pull request Jul 24, 2026
Replaces the AbstractVersion + YAML manifest + one-SQL-statement-per-file
mechanism with InstallSchemaMigration/ImportDataMigration implemented as
plain Doctrine\Migrations\AbstractMigration subclasses with all SQL inlined
via addSql(), still implementing IbexaMigrationInterface and tagged with
IbexaMigrationTag so TaggedMigrationsRunner/IbexaOnlyDependencyFactory work
unchanged. Long/multiline statements use PHP NOWDOC for readability, with
CREATE TABLE bodies pretty-printed one column per line.

Same conversion as #785 for the 4.6 line, adapted for this
branch's ibexa_*-renamed schema and dbal 3.x platform class names
(AbstractMySQLPlatform/PostgreSQLPlatform instead of MySqlPlatform/
PostgreSqlPlatform).
Steveb-p added a commit that referenced this pull request Sep 29, 2026
…line-sql' into base/ibx-11939-4.6-merged-5.0

#785 was rebased onto 4.6 after #852 landed there. Its tree is identical to
the pre-rebase head f75405c this base already contains, so this merge only records the
rebased history and keeps the base's own tree (-s ours). A regular merge would have gone back
to the old merge base and re-applied the lines of #785 that earlier merges here resolved the
5.0 way.
Each CREATE TABLE now lists one column, index or constraint per line, and ALTER TABLE and
CREATE INDEX statements longer than 120 characters are wrapped. Only whitespace changes,
apart from the comma moving in front of SQLite's --(DC2Type:...) comments, which keeps each
comment with its column.
ibexa/doctrine-migrations#19 makes MariaDB a platform of its own, so each migration now
lists SqlPlatform::MARIADB and runs its MySQL SQL there too.
… does on MariaDB

On MariaDB, DBAL creates a JSON column as LONGTEXT with a (DC2Type:json) comment, which is
what the legacy SchemaBuilderEvent path gets too. MariaDB turns MySQL's native JSON into
LONGTEXT with utf8mb4_bin and a json_valid() check instead, which DBAL 2.13 then reads back
as TEXT. Those tables now come from install-schema-json-tables.mariadb.sql on MariaDB and
install-schema-json-tables.mysql.sql on MySQL, ahead of the rest of install-schema-mysql.sql.
@Steveb-p
Steveb-p force-pushed the doctrine-migrations-installer-inline-sql branch from a85ac43 to c351f4a Compare October 2, 2026 11:28
It replaces installer's upgrade/db/ibexa-4.6.20-to-4.6.21.sql, so 4.6.21 is the release it is for.
The target version only orders Ibexa migrations: it now runs after the 4.6.0 baselines
instead of right after core's own, which is fine since it only needs core's tables.
@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
14.8% Duplication on New Code (required ≤ 3%)
E Security Rating on New Code (required ≥ A)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@Steveb-p
Steveb-p merged commit 6542c85 into 4.6 Oct 5, 2026
35 of 36 checks passed
@Steveb-p
Steveb-p deleted the doctrine-migrations-installer-inline-sql branch October 5, 2026 10:37
Steveb-p added a commit to ibexa/user that referenced this pull request Oct 5, 2026
…ches

Points CI at ibexa/test-core#68 (the test case), ibexa/core#785 with ibexa/installer#213 (the
Doctrine Migrations path). Must be removed before merging.
Steveb-p added a commit that referenced this pull request Oct 5, 2026
…Command

#785 replaced InstallerTagPass with a !tagged_locator for the command's $installers argument,
and both of those reached this branch through the base - but InstallPlatformCommand kept 5.0's
array-typed constructor, so ibexa:install failed with a TypeError before doing anything. Ported
the matching change from #785: ServiceLocator in, has()/get() for the lookup, and
getProvidedServices() for listing the available types.
Comment thread composer.json Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants