feat(docker,pgsql): support postgresql in Dockerfile.prod, entrypoint and migrations

This commit is contained in:
michele 2026-09-11 18:39:11 +02:00
parent a0c441638e
commit f59c40af68
3 changed files with 47 additions and 39 deletions

View File

@ -13,10 +13,9 @@ public function up(): void
// Approccio alternativo: modificare la colonna per avere un valore di default // Approccio alternativo: modificare la colonna per avere un valore di default
// e creare una stored procedure per generare il codice // e creare una stored procedure per generare il codice
// Prima, creiamo una stored procedure per generare il codice univoco // Prima, creiamo una stored procedure per generare il codice univoco solo su MySQL
if (DB::connection()->getDriverName() !== 'sqlite') { if (DB::connection()->getDriverName() === 'mysql') {
DB::unprepared('DROP PROCEDURE IF EXISTS generate_codice_univoco'); DB::unprepared('DROP PROCEDURE IF EXISTS generate_codice_univoco');
}
try { try {
DB::unprepared(' DB::unprepared('
@ -52,6 +51,7 @@ public function up(): void
} catch (\Exception $e) { } catch (\Exception $e) {
echo "Errore nella creazione della stored procedure: " . $e->getMessage() . "\n"; echo "Errore nella creazione della stored procedure: " . $e->getMessage() . "\n";
} }
}
// Aggiornare i record esistenti che non hanno codice_univoco // Aggiornare i record esistenti che non hanno codice_univoco
try { try {

View File

@ -11,6 +11,8 @@ RUN apt-get update && apt-get install -y \
libxml2-dev \ libxml2-dev \
libzip-dev \ libzip-dev \
libicu-dev \ libicu-dev \
libpq-dev \
postgresql-client \
default-mysql-client \ default-mysql-client \
mdbtools \ mdbtools \
nodejs \ nodejs \
@ -18,7 +20,7 @@ RUN apt-get update && apt-get install -y \
&& apt-get clean && rm -rf /var/lib/apt/lists/* && apt-get clean && rm -rf /var/lib/apt/lists/*
# PHP extensions # PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd intl zip RUN docker-php-ext-install pdo_mysql pdo_pgsql pgsql mbstring exif pcntl bcmath gd intl zip
# Composer # Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

View File

@ -35,9 +35,15 @@ rm -f \
if [[ "${WAIT_FOR_DB:-true}" == "true" ]] && [[ -n "${DB_HOST:-}" ]]; then if [[ "${WAIT_FOR_DB:-true}" == "true" ]] && [[ -n "${DB_HOST:-}" ]]; then
for i in {1..30}; do for i in {1..30}; do
if [[ "${DB_CONNECTION:-mysql}" == "pgsql" ]]; then
if pg_isready -h "${DB_HOST}" -p "${DB_PORT:-5432}" -U "${DB_USERNAME:-postgres}" >/dev/null 2>&1; then
break
fi
else
if mysqladmin ping -h "${DB_HOST}" -P "${DB_PORT:-3306}" -u "${DB_USERNAME:-root}" -p"${DB_PASSWORD:-}" --silent; then if mysqladmin ping -h "${DB_HOST}" -P "${DB_PORT:-3306}" -u "${DB_USERNAME:-root}" -p"${DB_PASSWORD:-}" --silent; then
break break
fi fi
fi
sleep 2 sleep 2
done done
fi fi