Created
July 23, 2025 18:59
-
-
Save jfinstrom/ad3ccfd3818f35b33d735be7ffd3a631 to your computer and use it in GitHub Desktop.
An example of using the built in doctrine for managing tables in FreePBX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
die('Do not run this it is for example, make your own with this information'); | |
include '/etc/freepbx.conf'; | |
$host = 'localhost'; | |
$port = 3306; | |
$database = 'asterisk'; | |
$user = 'freepbxuser'; | |
$password = 'NoBodyWouldSetAPasswordTo123456'; | |
$dsn = sprintf('mysql:host=%s;port=%s;dbname=%s', $host, $port, $database); | |
$MyDatabase = new FreePBX\Database($dsn, $user, $password); | |
// Examples of each data type as a column | |
$tables = [ | |
'example_table' => [ | |
'columns' => [ | |
'id' => [ | |
'type' => 'integer', | |
'autoincrement' => true, | |
'unsigned' => true, | |
'notnull' => true, | |
'primarykey' => true, | |
], | |
'string_col' => [ | |
'type' => 'string', | |
'length' => 100, | |
'notnull' => false, | |
'default' => null, | |
], | |
'integer_col' => [ | |
'type' => 'integer', | |
'notnull' => false, | |
], | |
'bigint_col' => [ | |
'type' => 'bigint', | |
'notnull' => false, | |
], | |
'smallint_col' => [ | |
'type' => 'smallint', | |
'notnull' => false, | |
], | |
'boolean_col' => [ | |
'type' => 'boolean', | |
'notnull' => false, | |
'default' => 0, | |
], | |
'date_col' => [ | |
'type' => 'date', | |
'notnull' => false, | |
], | |
'datetime_col' => [ | |
'type' => 'datetime', | |
'notnull' => false, | |
], | |
'float_col' => [ | |
'type' => 'float', | |
'precision' => 10, | |
'scale' => 2, | |
'notnull' => false, | |
], | |
'decimal_col' => [ | |
'type' => 'decimal', | |
'precision' => 12, | |
'scale' => 4, | |
'notnull' => false, | |
], | |
'text_col' => [ | |
'type' => 'text', | |
'notnull' => false, | |
], | |
'blob_col' => [ | |
'type' => 'blob', | |
'notnull' => false, | |
], | |
], | |
'indexes' => [ | |
'string_col_idx' => [ | |
'type' => 'index', | |
'cols' => ['string_col'], | |
], | |
'unique_text_col' => [ | |
'type' => 'unique', | |
'cols' => ['text_col'], | |
], | |
], | |
], | |
]; | |
$dryrun = false; | |
$migrate = $MyDatabase->migrate('nonemptystring'); | |
// https://github.com/FreePBX/framework/blob/300c25b6fbe9677a57c57a085792994e132c3b2e/amp_conf/htdocs/admin/libraries/BMO/Database/Migration.class.php#L133 | |
$migrate->modifyMultiple($tables, $dryrun); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment