From 335831e7038a64d1a1c2801836fe370ec6ce1942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Mon, 5 Jul 2021 14:42:13 +0200 Subject: [PATCH] Allow migration with no SQLite databases Update the documentation Update the dependencies Bump the package version --- flexiapi/README.md | 6 +- .../app/Console/Commands/ImportDatabase.php | 122 ++++++++++-------- flexiapi/composer.lock | 34 ++--- flexisip-account-manager.spec | 2 +- 4 files changed, 86 insertions(+), 78 deletions(-) diff --git a/flexiapi/README.md b/flexiapi/README.md index d7fea24..23d050c 100644 --- a/flexiapi/README.md +++ b/flexiapi/README.md @@ -109,11 +109,11 @@ FlexiAPI is shipped with several console commands that you can launch using the ### Migrate an old database -FlexiAPI needs an empty database to run its migration. The following console command allow you to import simultanously an exisiting FlexiSIP database and the old FlexiAPI SQLite database file in the new one. To do so, please specify the new database configuration in the `.env` file and run the following command. +FlexiAPI needs an empty database to run its migration. The following console command allow you to import simultanously an exisiting FlexiSIP database and the old FlexiAPI SQLite database file (if you have one) in the new one. To do so, please specify the new database configuration in the `.env` file and run the following command. - php artisan db:import {old_dbname} {old_sqlite_file_path} --username={old_username} --password={old_password} + php artisan db:import {old_dbname} {old_sqlite_file_path?} --username={old_username} --password={old_password} -You can also specify the `port`, `host` and `database type` as a parameter. +You can also specify the `port`, `host` and `database type` as a parameter, as well as the table name for the accounts (default `accounts`), passwords (default `passwords`) and aliases (default `aliases`). ### Clear Expired Nonces for DIGEST authentication diff --git a/flexiapi/app/Console/Commands/ImportDatabase.php b/flexiapi/app/Console/Commands/ImportDatabase.php index 0052c25..a960226 100644 --- a/flexiapi/app/Console/Commands/ImportDatabase.php +++ b/flexiapi/app/Console/Commands/ImportDatabase.php @@ -17,7 +17,7 @@ use App\PhoneChangeCode; class ImportDatabase extends Command { - protected $signature = 'db:import {dbname} {sqlitefilepath} {--u|username=} {--p|password=} {--P|port=3306} {--t|type=mysql} {--host=localhost}'; + protected $signature = 'db:import {dbname} {sqlite-file-path?} {--u|username=} {--p|password=} {--P|port=3306} {--t|type=mysql} {--host=localhost} {--accounts-table=accounts} {--aliases-table=aliases} {--passwords-table=passwords}'; protected $description = 'Import an existing Flexisip database into FlexiAPI'; private $_pagination = 1000; @@ -52,10 +52,14 @@ class ImportDatabase extends Command 'prefix' => '', ], 'default'); - $capsule->addConnection([ - 'driver' => 'sqlite', - 'database' => $this->argument('sqlitefilepath'), - ], 'sqlite'); + if (!$this->argument('sqlite-file-path')) { + $this->confirm('No SQLite database file was specified : Do you wish to continue?'); + } else { + $capsule->addConnection([ + 'driver' => 'sqlite', + 'database' => $this->argument('sqlite-file-path'), + ], 'sqlite'); + } $capsule->setAsGlobal(); @@ -65,7 +69,7 @@ class ImportDatabase extends Command return 1; } - $accountsCount = Capsule::table('accounts')->count(); + $accountsCount = Capsule::table($this->option('accounts-table'))->count(); if ($this->confirm($accountsCount . ' accounts will be migrated : Do you wish to continue?')) { // Accounts @@ -76,7 +80,7 @@ class ImportDatabase extends Command $bar = $this->output->createProgressBar($pages); for ($page = 0; $page <= $pages; $page++) { - $originAccounts = Capsule::table('accounts') + $originAccounts = Capsule::table($this->option('accounts-table')) ->take($this->_pagination) ->skip($page*$this->_pagination) ->get() @@ -104,11 +108,11 @@ class ImportDatabase extends Command // Passwords $this->info('Migrating the passwords'); - $pages = Capsule::table('accounts')->count() / $this->_pagination; + $pages = Capsule::table($this->option('passwords-table'))->count() / $this->_pagination; $bar = $this->output->createProgressBar($pages); for ($page = 0; $page <= $pages; $page++) { - $originPasswords = Capsule::table('passwords') + $originPasswords = Capsule::table($this->option('passwords-table')) ->take($this->_pagination) ->skip($page*$this->_pagination) ->get() @@ -129,11 +133,11 @@ class ImportDatabase extends Command // Aliases $this->info('Migrating the aliases'); - $pages = Capsule::table('aliases')->count() / $this->_pagination; + $pages = Capsule::table($this->option('aliases-table'))->count() / $this->_pagination; $bar = $this->output->createProgressBar($pages); for ($page = 0; $page <= $pages; $page++) { - $originAliases = Capsule::table('aliases') + $originAliases = Capsule::table($this->option('aliases-table')) ->take($this->_pagination) ->skip($page*$this->_pagination) ->get() @@ -149,62 +153,66 @@ class ImportDatabase extends Command $bar->finish(); - $this->newLine(); + // SQLite database migration - $this->info('Migrating the admins'); + if ($this->argument('sqlite-file-path')) { + $this->newLine(); - $originAdmins = Capsule::connection('sqlite') - ->table('admins') - ->get() - ->map(function ($element) { - return (array)$element; - }) - ->toArray(); - Admin::insert($originAdmins); + $this->info('Migrating the admins'); - $this->info('Migrating the api keys'); + $originAdmins = Capsule::connection('sqlite') + ->table('admins') + ->get() + ->map(function ($element) { + return (array)$element; + }) + ->toArray(); + Admin::insert($originAdmins); - $originApiKeys = Capsule::connection('sqlite') - ->table('api_keys') - ->get() - ->map(function ($element) { - return (array)$element; - }) - ->toArray(); - ApiKey::insert($originApiKeys); + $this->info('Migrating the api keys'); - $this->info('Migrating the nonces'); + $originApiKeys = Capsule::connection('sqlite') + ->table('api_keys') + ->get() + ->map(function ($element) { + return (array)$element; + }) + ->toArray(); + ApiKey::insert($originApiKeys); - $originNonces = Capsule::connection('sqlite') - ->table('nonces') - ->get() - ->map(function ($element) { - return (array)$element; - }) - ->toArray(); - DigestNonce::insert($originNonces); + $this->info('Migrating the nonces'); - $this->info('Migrating the email changed'); + $originNonces = Capsule::connection('sqlite') + ->table('nonces') + ->get() + ->map(function ($element) { + return (array)$element; + }) + ->toArray(); + DigestNonce::insert($originNonces); - $originEmailChanged = Capsule::connection('sqlite') - ->table('email_changed') - ->get() - ->map(function ($element) { - return (array)$element; - }) - ->toArray(); - EmailChanged::insert($originEmailChanged); + $this->info('Migrating the email changed'); - $this->info('Migrating the phone change code'); + $originEmailChanged = Capsule::connection('sqlite') + ->table('email_changed') + ->get() + ->map(function ($element) { + return (array)$element; + }) + ->toArray(); + EmailChanged::insert($originEmailChanged); - $originPhoneChangeCodes = Capsule::connection('sqlite') - ->table('phone_change_codes') - ->get() - ->map(function ($element) { - return (array)$element; - }) - ->toArray(); - PhoneChangeCode::insert($originPhoneChangeCodes); + $this->info('Migrating the phone change code'); + + $originPhoneChangeCodes = Capsule::connection('sqlite') + ->table('phone_change_codes') + ->get() + ->map(function ($element) { + return (array)$element; + }) + ->toArray(); + PhoneChangeCode::insert($originPhoneChangeCodes); + } $this->enableForeignKeyCheck(); diff --git a/flexiapi/composer.lock b/flexiapi/composer.lock index be26539..57fc0a7 100644 --- a/flexiapi/composer.lock +++ b/flexiapi/composer.lock @@ -532,16 +532,16 @@ }, { "name": "endroid/qr-code", - "version": "4.2.0", + "version": "4.2.1", "source": { "type": "git", "url": "https://github.com/endroid/qr-code.git", - "reference": "d6d964bda88ea9e40032018208b073845cbd3c2e" + "reference": "4ef4c7815cf928392eecdb8cf7fd3ae45e6e3f59" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/endroid/qr-code/zipball/d6d964bda88ea9e40032018208b073845cbd3c2e", - "reference": "d6d964bda88ea9e40032018208b073845cbd3c2e", + "url": "https://api.github.com/repos/endroid/qr-code/zipball/4ef4c7815cf928392eecdb8cf7fd3ae45e6e3f59", + "reference": "4ef4c7815cf928392eecdb8cf7fd3ae45e6e3f59", "shasum": "" }, "require": { @@ -592,7 +592,7 @@ ], "support": { "issues": "https://github.com/endroid/qr-code/issues", - "source": "https://github.com/endroid/qr-code/tree/4.2.0" + "source": "https://github.com/endroid/qr-code/tree/4.2.1" }, "funding": [ { @@ -600,7 +600,7 @@ "type": "github" } ], - "time": "2021-06-27T06:44:36+00:00" + "time": "2021-07-03T10:50:07+00:00" }, { "name": "erusev/parsedown", @@ -979,16 +979,16 @@ }, { "name": "laravel/framework", - "version": "v8.49.0", + "version": "v8.49.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "855a919d08b45f93cb3cf709736528c3d1531884" + "reference": "62aee1bfeefd82f160c7aa3b4c63cb2f053215c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/855a919d08b45f93cb3cf709736528c3d1531884", - "reference": "855a919d08b45f93cb3cf709736528c3d1531884", + "url": "https://api.github.com/repos/laravel/framework/zipball/62aee1bfeefd82f160c7aa3b4c63cb2f053215c0", + "reference": "62aee1bfeefd82f160c7aa3b4c63cb2f053215c0", "shasum": "" }, "require": { @@ -1143,7 +1143,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2021-06-29T13:50:21+00:00" + "time": "2021-07-02T16:50:12+00:00" }, { "name": "laravel/tinker", @@ -1727,16 +1727,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.10.5", + "version": "v4.11.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4432ba399e47c66624bc73c8c0f811e5c109576f" + "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4432ba399e47c66624bc73c8c0f811e5c109576f", - "reference": "4432ba399e47c66624bc73c8c0f811e5c109576f", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/fe14cf3672a149364fb66dfe11bf6549af899f94", + "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94", "shasum": "" }, "require": { @@ -1777,9 +1777,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.5" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.11.0" }, - "time": "2021-05-03T19:11:20+00:00" + "time": "2021-07-03T13:36:55+00:00" }, { "name": "opis/closure", diff --git a/flexisip-account-manager.spec b/flexisip-account-manager.spec index 14d047c..199afcb 100644 --- a/flexisip-account-manager.spec +++ b/flexisip-account-manager.spec @@ -8,7 +8,7 @@ #%define _datadir %{_datarootdir} #%define _docdir %{_datadir}/doc -%define build_number 84 +%define build_number 85 %define var_dir /var/opt/belledonne-communications %define opt_dir /opt/belledonne-communications/share/flexisip-account-manager