Switch from dbstructure.json to dbstructure.php
This commit is contained in:
parent
e511790d62
commit
fad99b8619
File diff suppressed because it is too large
Load diff
1369
config/dbstructure.php
Normal file
1369
config/dbstructure.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,7 @@
|
|||
namespace Friendica\Database;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -22,6 +22,13 @@ require_once 'include/text.php';
|
|||
*/
|
||||
class DBStructure
|
||||
{
|
||||
/**
|
||||
* Database structure definition loaded from config/dbstructure.php
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $definition = [];
|
||||
|
||||
/*
|
||||
* Converts all tables from MyISAM to InnoDB
|
||||
*/
|
||||
|
@ -822,43 +829,36 @@ class DBStructure
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the database structure definition from the /config/dbstructure.json file
|
||||
*
|
||||
* Expected format:
|
||||
* "table_name": {
|
||||
* "comment": "meaningful table comment",
|
||||
* "fields": {
|
||||
* "field_name1": {"type": "int unsigned", "not null": "1", "extra": "auto_increment", "primary": "1", "comment": "meaningful field comment"},
|
||||
* "field_name2": {"type": "varchar(50)", "not null": "1", "default": "", "comment": "meaningful field comment"},
|
||||
* },
|
||||
* "indexes": {
|
||||
* "PRIMARY": ["field_name1"],
|
||||
* "name": ["UNIQUE", "field_name2"]
|
||||
* }
|
||||
* }
|
||||
* Loads the database structure definition from the config/dbstructure.php file.
|
||||
*
|
||||
* @see config/dbstructure.php
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function definition() {
|
||||
public static function definition()
|
||||
{
|
||||
if (!self::$definition) {
|
||||
$a = \Friendica\BaseObject::getApp();
|
||||
|
||||
$filename = $a->getBasePath() . '/config/dbstructure.json';
|
||||
$filename = $a->getBasePath() . '/config/dbstructure.php';
|
||||
|
||||
if (!is_readable($filename)) {
|
||||
throw new Exception('Missing database structure config file config/dbstructure.json');
|
||||
throw new Exception('Missing database structure config file config/dbstructure.php');
|
||||
}
|
||||
|
||||
$json = file_get_contents($filename);
|
||||
$definition = require $filename;
|
||||
|
||||
$database = json_decode($json, true);
|
||||
|
||||
if (!$database) {
|
||||
throw new Exception('Corrupted database structure config file config/dbstructure.json');
|
||||
if (!$definition) {
|
||||
throw new Exception('Corrupted database structure config file config/dbstructure.php');
|
||||
}
|
||||
|
||||
Addon::callHooks('dbstructure_definition', $database);
|
||||
self::$definition = $definition;
|
||||
} else {
|
||||
$definition = self::$definition;
|
||||
}
|
||||
|
||||
return $database;
|
||||
Hook::callAll('dbstructure_definition', $definition);
|
||||
|
||||
return $definition;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ trait VFSTrait
|
|||
$this->setConfigFile('config.ini.php');
|
||||
$this->setConfigFile('settings.ini.php');
|
||||
$this->setConfigFile('local.ini.php');
|
||||
$this->setConfigFile('dbstructure.json');
|
||||
$this->setConfigFile('dbstructure.php');
|
||||
}
|
||||
|
||||
protected function setConfigFile($filename)
|
||||
|
|
|
@ -20,7 +20,7 @@ require_once 'include/dba.php';
|
|||
* This function is responsible for doing post update changes to the data
|
||||
* (not the structure) in the database.
|
||||
*
|
||||
* Database structure changes are done in src/Database/DBStructure.php
|
||||
* Database structure changes are done in config/dbstructure.php
|
||||
*
|
||||
* If there is a need for a post process to a structure change, update this file
|
||||
* by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
|
||||
|
@ -31,7 +31,7 @@ require_once 'include/dba.php';
|
|||
* You are currently on version 4711 and you are preparing changes that demand an update script.
|
||||
*
|
||||
* 1. Create a function "update_4712()" here in the update.php
|
||||
* 2. Apply the needed structural changes in src/Database/DBStructure.php
|
||||
* 2. Apply the needed structural changes in config/dbStructure.php
|
||||
* 3. Set DB_UPDATE_VERSION in boot.php to 4712.
|
||||
*
|
||||
* If you need to run a script before the database update, name the function "pre_update_4712()"
|
||||
|
|
Loading…
Reference in a new issue