Project

General

Profile

Actions

Support #3679

closed

Automatic DB Update

Added by Carsten Rose almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Carsten Rose
Target version:
-
Start date:
05.05.2017
Due date:
% Done:

0%

Estimated time:
Discuss:
Prio Planung:
Vote:

Description

After first installing a QFQ extension or after updating a QFQ extension, it's (often) necessary to update the DB schema.

On every start of QFQ, ask for table version and start update if necessary.

  • Single '.sql' file for every table version update.

First installation of QFQ extension.

  • Missing DB
  • Play formEditor.sql.

Update QFQ installation.

  • Retrieve table version.
  • Update table if necessary.
  • Play formEditor.sql.
Actions #1

Updated by Carsten Rose almost 7 years ago

  • Description updated (diff)
Actions #2

Updated by Carsten Rose almost 7 years ago

Recherchiert welche Tools es gibt, um automatisiert MySQL Schema Update Scripts erstellen zu lassen: kein Open Source gefunden.

Aber das ist vermutlich auch gar nicht so wichtig:
  • Das Tool muesste manuell aufgerufen werden - theoretisch koennte es bei 'git commit' oder 'git tag' getriggert werden, aber ich denke es kommt nicht haeufig genug vor als das sich der Aufwand fuer die Implentierung lohnt. Evtl. kann mit dem folgenden Ansatz auch erstmal Praxiserfahrung gesammelt werden um dann genauer zu sagen was noetig ist.
  • Es gibt Schema Updates aber nicht so viele.
  • Manchmal sind die Updates mit weiterer Logik verbunden (Bsp: der Default einer neuen Spalte soll in Zukunft anders sein als die aktuellen Werte enthalten - 2 SQL Statements sind noetig)
  • Beim programmieren koennte die SQL Anweisung direkt im Update Skript eingebaut werden.

Notes

Konzeptidee

  • Es gibt eine PHP Datei mit einem statisch konifugriertem Array fuer alle Updates. $update[<tablename>][<version>]
  • In jeder Tabelle steht im 'Comment' die aktuelle Version (numerischer Wert, fortlaufend).
  • Check beim Start von QFQ ob ein Update noetig ist:
    • In `config.qfq.ini` steht eine Versionsnummer. Ist die unterschiedlich zu `ext_emconf.php`, wird der Update Process getriggert.
    • Das Update-array wird gelesen.
    • Von jeder MySQL Tabelle wird die Versionsnummer gelesen.
    • Pro Tabelle wird jeder Update durchgefuehrt. Anschliessend wird die neue Versionsnummer im Tabellen 'comment'-Feld eingetragen.
  • Wenn alles gut durchgelaufen ist wird die neue Versionsnummer in config.qfq.ini eingetragen.
  • Achtung: nur ein PHP Prozess darf den Update aufeinmal ausfuehren. Entsprechendes Locking einbauen.
Actions #3

Updated by Carsten Rose almost 7 years ago

  • Status changed from New to Closed
Actions #4

Updated by Carsten Rose almost 7 years ago

Final implementation:

  • Read the extension version number.
  • Read the QFQ database version number: stored in the comment field of table 'Form'. Format: Version=x.y.z
  • If versions different:
    • Read the update array 'DatabaseUpdateData.php'.
    • Play all changes after 'old' upto 'new'.
    • Save new QFQ database version in the comment field of table 'Form'
  • In a new QFQ installation, the comment field of table 'Form' is empty. On the first call of QFQ, the version string
    will be set. Also the 'formEditor.sql' will be played initially.
Actions

Also available in: Atom PDF