Files
amneziavpnphp/migrations
infosave b819eb35b0 fix(awg2): resolve issue #50 client key generation and install timeout
Issue #50 (AmneziaWG 2.0 / awg2): "Failed to generate client keys" when
creating clients, and "Invalid server response" on first install.

- VpnClient::generateClientKeys() built its own password-only SSH command
  (PubkeyAuthentication=no, no sudo), bypassing VpnServer::executeCommand.
  That broke key-based servers and hosts where docker requires sudo. Route
  it through executeCommand so SSH-key auth and docker sudo auto-detection
  apply, matching every other remote operation.
- VpnClient::getNextClientIP() read /opt/amnezia/awg/wg0.conf only; AWG2
  uses awg0.conf. Read awg0.conf first, fall back to wg0.conf.
- deploy route: lift PHP time limit (set_time_limit(0) + ignore_user_abort)
  so the multi-minute awg2 docker build is not killed mid-request, which
  produced the truncated, non-JSON "Invalid server response".
- migration 070: drop `--no-cache` from the awg2 docker build so layers are
  reused, making installs and retries fast and idempotent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 10:31:59 +03:00
..

Database Migrations

This directory contains SQL migration files that are automatically executed when the database container is first initialized.

Execution Order

Migration files are executed in alphabetical order by MySQL's Docker entrypoint. Files are numbered to ensure correct execution sequence:

  1. 001_init.sql - Main database schema and tables
  2. 002_translations_ru.sql - Russian translations
  3. 003_translations_es.sql - Spanish translations
  4. 004_translations_de.sql - German translations
  5. 005_translations_fr.sql - French translations
  6. 006_translations_zh.sql - Chinese translations

Adding New Migrations

When creating new migration files:

  1. Use numerical prefix (e.g., 007_add_feature.sql)
  2. Ensure the number is higher than existing migrations
  3. Use descriptive names
  4. Always use ON DUPLICATE KEY UPDATE for INSERT statements to make migrations idempotent

Manual Execution

To manually run migrations in an existing database:

# Single migration
docker compose exec db mysql -uroot -prootpassword amnezia_panel < migrations/001_init.sql

# All migrations in order
for file in migrations/*.sql; do
  echo "Executing $file..."
  docker compose exec -T db mysql -uroot -prootpassword amnezia_panel < "$file"
done

Regenerating Translation Migrations

To regenerate translation migrations from the current database:

# Export translations for a specific language
docker compose exec -T db mysql -uroot -prootpassword amnezia_panel \
  --default-character-set=utf8mb4 \
  -e "SELECT CONCAT('(''', language_code, ''', ''', translation_key, ''', ''', 
      REPLACE(translation_value, '''', ''''''), '''),') 
      FROM translations WHERE language_code = 'ru' ORDER BY translation_key;" \
  | grep -v "CONCAT" > /tmp/translations_ru.sql

# Then wrap with INSERT statement and ON DUPLICATE KEY UPDATE