mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Multi-db support
This commit is contained in:
parent
dad5173a13
commit
c032143c47
22
.env.travis
Normal file
22
.env.travis
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
APP_ENV=development
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_URL=http://ninja.dev
|
||||||
|
APP_KEY=SomeRandomStringSomeRandomString
|
||||||
|
APP_CIPHER=AES-256-CBC
|
||||||
|
APP_LOCALE=en
|
||||||
|
|
||||||
|
MULTI_DB_ENABLED=true
|
||||||
|
MULTI_DB_CACHE_ENABLED=true
|
||||||
|
|
||||||
|
DB_TYPE=db-ninja-1
|
||||||
|
DB_STRICT=false
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_USERNAME=ninja
|
||||||
|
DB_PASSWORD=ninja
|
||||||
|
|
||||||
|
DB_DATABASE0=ninja0
|
||||||
|
DB_DATABASE1=ninja1
|
||||||
|
DB_DATABASE2=ninja2
|
||||||
|
|
||||||
|
MAIL_DRIVER=log
|
||||||
|
TRAVIS=true
|
48
.travis.yml
48
.travis.yml
@ -44,21 +44,21 @@ before_script:
|
|||||||
# prevent MySQL went away error
|
# prevent MySQL went away error
|
||||||
- mysql -u root -e 'SET @@GLOBAL.wait_timeout=28800;'
|
- mysql -u root -e 'SET @@GLOBAL.wait_timeout=28800;'
|
||||||
# copy configuration files
|
# copy configuration files
|
||||||
- cp .env.example .env
|
- cp .env.travis .env
|
||||||
- cp tests/_bootstrap.php.default tests/_bootstrap.php
|
- cp tests/_bootstrap.php.default tests/_bootstrap.php
|
||||||
- php artisan key:generate --no-interaction
|
- php artisan key:generate --no-interaction
|
||||||
- sed -i 's/APP_ENV=production/APP_ENV=development/g' .env
|
|
||||||
- sed -i 's/APP_DEBUG=false/APP_DEBUG=true/g' .env
|
|
||||||
- sed -i 's/MAIL_DRIVER=smtp/MAIL_DRIVER=log/g' .env
|
|
||||||
- sed -i 's/PHANTOMJS_CLOUD_KEY/#PHANTOMJS_CLOUD_KEY/g' .env
|
|
||||||
- sed -i '$a NINJA_DEV=true' .env
|
- sed -i '$a NINJA_DEV=true' .env
|
||||||
- sed -i '$a TRAVIS=true' .env
|
|
||||||
# create the database and user
|
# create the database and user
|
||||||
- mysql -u root -e "create database IF NOT EXISTS ninja;"
|
- mysql -u root -e "create database IF NOT EXISTS ninja0;"
|
||||||
- mysql -u root -e "GRANT ALL PRIVILEGES ON ninja.* To 'ninja'@'localhost' IDENTIFIED BY 'ninja'; FLUSH PRIVILEGES;"
|
- mysql -u root -e "create database IF NOT EXISTS ninja1;"
|
||||||
|
- mysql -u root -e "create database IF NOT EXISTS ninja2;"
|
||||||
|
- mysql -u root -e "GRANT ALL PRIVILEGES ON ninja0.* To 'ninja'@'localhost' IDENTIFIED BY 'ninja'; FLUSH PRIVILEGES;"
|
||||||
|
- mysql -u root -e "GRANT ALL PRIVILEGES ON ninja1.* To 'ninja'@'localhost' IDENTIFIED BY 'ninja'; FLUSH PRIVILEGES;"
|
||||||
|
- mysql -u root -e "GRANT ALL PRIVILEGES ON ninja2.* To 'ninja'@'localhost' IDENTIFIED BY 'ninja'; FLUSH PRIVILEGES;"
|
||||||
# migrate and seed the database
|
# migrate and seed the database
|
||||||
- php artisan migrate --no-interaction
|
- php artisan migrate --database=ninja0 --seed --no-interaction
|
||||||
- php artisan db:seed --no-interaction # default seed
|
- php artisan migrate --database=ninja1 --seed --no-interaction
|
||||||
|
- php artisan migrate --database=ninja2 --seed --no-interaction
|
||||||
# Start webserver on ninja.dev:8000
|
# Start webserver on ninja.dev:8000
|
||||||
- php artisan serve --host=ninja.dev --port=8000 & # '&' allows to run in background
|
- php artisan serve --host=ninja.dev --port=8000 & # '&' allows to run in background
|
||||||
# Start PhantomJS
|
# Start PhantomJS
|
||||||
@ -69,6 +69,7 @@ before_script:
|
|||||||
- curl -L http://ninja.dev:8000/update
|
- curl -L http://ninja.dev:8000/update
|
||||||
- php artisan ninja:create-test-data 4 true
|
- php artisan ninja:create-test-data 4 true
|
||||||
- php artisan db:seed --no-interaction --class=UserTableSeeder # development seed
|
- php artisan db:seed --no-interaction --class=UserTableSeeder # development seed
|
||||||
|
- sed -i 's/DB_TYPE=db-ninja-1/DB_TYPE=db-ninja-2/g' .env
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- php ./vendor/codeception/codeception/codecept run --debug acceptance APICest.php
|
- php ./vendor/codeception/codeception/codecept run --debug acceptance APICest.php
|
||||||
@ -92,17 +93,22 @@ script:
|
|||||||
after_script:
|
after_script:
|
||||||
- php artisan ninja:check-data --no-interaction
|
- php artisan ninja:check-data --no-interaction
|
||||||
- cat .env
|
- cat .env
|
||||||
- mysql -u root -e 'select * from accounts;' ninja
|
- mysql -u root -e 'select * from lookup_companies;' ninja0
|
||||||
- mysql -u root -e 'select * from users;' ninja
|
- mysql -u root -e 'select * from lookup_accounts;' ninja0
|
||||||
- mysql -u root -e 'select * from account_gateways;' ninja
|
- mysql -u root -e 'select * from lookup_contacts;' ninja0
|
||||||
- mysql -u root -e 'select * from clients;' ninja
|
- mysql -u root -e 'select * from lookup_invitations;' ninja0
|
||||||
- mysql -u root -e 'select * from contacts;' ninja
|
- mysql -u root -e 'select * from accounts;' ninja1
|
||||||
- mysql -u root -e 'select * from invoices;' ninja
|
- mysql -u root -e 'select * from users;' ninja1
|
||||||
- mysql -u root -e 'select * from invoice_items;' ninja
|
- mysql -u root -e 'select * from account_gateways;' ninja1
|
||||||
- mysql -u root -e 'select * from invitations;' ninja
|
- mysql -u root -e 'select * from clients;' ninja1
|
||||||
- mysql -u root -e 'select * from payments;' ninja
|
- mysql -u root -e 'select * from contacts;' ninja1
|
||||||
- mysql -u root -e 'select * from credits;' ninja
|
- mysql -u root -e 'select * from invoices;' ninja1
|
||||||
- mysql -u root -e 'select * from expenses;' ninja
|
- mysql -u root -e 'select * from invoice_items;' ninja1
|
||||||
|
- mysql -u root -e 'select * from invitations;' ninja1
|
||||||
|
- mysql -u root -e 'select * from payments;' ninja1
|
||||||
|
- mysql -u root -e 'select * from credits;' ninja1
|
||||||
|
- mysql -u root -e 'select * from expenses;' ninja1
|
||||||
|
- mysql -u root -e 'select * from accounts;' ninja2
|
||||||
- cat storage/logs/laravel-error.log
|
- cat storage/logs/laravel-error.log
|
||||||
- cat storage/logs/laravel-info.log
|
- cat storage/logs/laravel-info.log
|
||||||
- FILES=$(find tests/_output -type f -name '*.png' | sort -nr)
|
- FILES=$(find tests/_output -type f -name '*.png' | sort -nr)
|
||||||
|
@ -4,6 +4,8 @@ namespace App\Console\Commands;
|
|||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use DB;
|
use DB;
|
||||||
|
use Mail;
|
||||||
|
use Exception;
|
||||||
use App\Models\DbServer;
|
use App\Models\DbServer;
|
||||||
use App\Models\LookupCompany;
|
use App\Models\LookupCompany;
|
||||||
use App\Models\LookupAccount;
|
use App\Models\LookupAccount;
|
||||||
@ -70,6 +72,16 @@ class InitLookup extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->info($this->log);
|
$this->info($this->log);
|
||||||
|
|
||||||
|
if ($this->option('validate') && $errorEmail) {
|
||||||
|
Mail::raw($this->log, function ($message) use ($errorEmail, $database) {
|
||||||
|
$message->to($errorEmail)
|
||||||
|
->from(CONTACT_EMAIL)
|
||||||
|
->subject("Check-Lookups [{$database}]: " . strtoupper($this->isValid ? RESULT_SUCCESS : RESULT_FAILURE));
|
||||||
|
});
|
||||||
|
} elseif (! $this->isValid) {
|
||||||
|
throw new Exception('Check data failed!!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initCompanies($dbServerId, $offset = 0)
|
private function initCompanies($dbServerId, $offset = 0)
|
||||||
|
@ -351,6 +351,7 @@ class AppController extends BaseController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Artisan::call('ninja:check-data');
|
Artisan::call('ninja:check-data');
|
||||||
|
//Artisan::call('ninja:check-data');
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
return RESULT_FAILURE;
|
return RESULT_FAILURE;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
|
use Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ExpenseCategory.
|
* Class ExpenseCategory.
|
||||||
@ -68,7 +69,7 @@ class LookupModel extends Eloquent
|
|||||||
$isUser = $className == 'App\Models\User';
|
$isUser = $className == 'App\Models\User';
|
||||||
|
|
||||||
// check if we've cached this lookup
|
// check if we've cached this lookup
|
||||||
if (env('MULTI_DB_CACHE_ENABLED') && $server = session($key)) {
|
if (env('MULTI_DB_CACHE_ENABLED') && $server = Cache::get($key)) {
|
||||||
static::setDbServer($server, $isUser);
|
static::setDbServer($server, $isUser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,7 +88,7 @@ class LookupModel extends Eloquent
|
|||||||
abort("Looked up {$className} not found: {$field} => {$value}");
|
abort("Looked up {$className} not found: {$field} => {$value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
session([$key => $server]);
|
Cache::put($key, $server, 120);
|
||||||
} else {
|
} else {
|
||||||
config(['database.default' => $current]);
|
config(['database.default' => $current]);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ class LanguageSeeder extends Seeder
|
|||||||
['name' => 'Italian', 'locale' => 'it'],
|
['name' => 'Italian', 'locale' => 'it'],
|
||||||
['name' => 'German', 'locale' => 'de'],
|
['name' => 'German', 'locale' => 'de'],
|
||||||
['name' => 'French', 'locale' => 'fr'],
|
['name' => 'French', 'locale' => 'fr'],
|
||||||
['name' => 'Brazilian Portuguese', 'locale' => 'pt_BR'],
|
['name' => 'Portuguese - Brazilian', 'locale' => 'pt_BR'],
|
||||||
['name' => 'Dutch', 'locale' => 'nl'],
|
['name' => 'Dutch', 'locale' => 'nl'],
|
||||||
['name' => 'Spanish', 'locale' => 'es'],
|
['name' => 'Spanish', 'locale' => 'es'],
|
||||||
['name' => 'Norwegian', 'locale' => 'nb_NO'],
|
['name' => 'Norwegian', 'locale' => 'nb_NO'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user