mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 13:34:03 +00:00
Make sure DatabaseCacheBootstrapper runs after DatabaseTenancyBootstrapper, misc wip changes
This commit is contained in:
parent
59718317a3
commit
8f5e12a202
6 changed files with 70 additions and 8 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -30,4 +30,16 @@ RUN echo "apc.enable_cli=1" >> "$PHP_INI_DIR/php.ini"
|
|||
# Only used on GHA
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
|
||||
|
||||
# Conditionally install and configure Xdebug (last step for faster rebuilds)
|
||||
ARG XDEBUG_ENABLED=false
|
||||
RUN if [ "$XDEBUG_ENABLED" = "true" ]; then \
|
||||
pecl install xdebug && docker-php-ext-enable xdebug && \
|
||||
echo "xdebug.mode=debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
|
||||
echo "xdebug.start_with_request=yes" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
|
||||
echo "xdebug.client_host=host.docker.internal" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
|
||||
echo "xdebug.client_port=9003" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
|
||||
echo "xdebug.discover_client_host=true" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
|
||||
echo "xdebug.log=/var/log/xdebug.log" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"; \
|
||||
fi
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
|
|
|||
|
|
@ -63,7 +63,14 @@
|
|||
"docker-up": "docker compose up -d",
|
||||
"docker-down": "docker compose down",
|
||||
"docker-restart": "docker compose down && docker compose up -d",
|
||||
"docker-rebuild": "PHP_VERSION=8.4 docker compose up -d --no-deps --build",
|
||||
"docker-rebuild": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"PHP_VERSION=8.4 docker compose up -d --no-deps --build"
|
||||
],
|
||||
"docker-rebuild-with-xdebug": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"PHP_VERSION=8.4 XDEBUG_ENABLED=true docker compose up -d --no-deps --build"
|
||||
],
|
||||
"docker-m1": "ln -s docker-compose-m1.override.yml docker-compose.override.yml",
|
||||
"testbench-unlink": "rm ./vendor/orchestra/testbench-core/laravel/vendor",
|
||||
"testbench-link": "ln -s /var/www/html/vendor ./vendor/orchestra/testbench-core/laravel/vendor",
|
||||
|
|
@ -72,10 +79,22 @@
|
|||
"phpstan": "vendor/bin/phpstan --memory-limit=256M",
|
||||
"phpstan-pro": "vendor/bin/phpstan --memory-limit=256M --pro",
|
||||
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config=.php-cs-fixer.php",
|
||||
"test": "./test --no-coverage",
|
||||
"test-full": "./test",
|
||||
"act": "act -j tests --matrix 'laravel:^11.0'",
|
||||
"act-input": "act -j tests --matrix 'laravel:^11.0' --input"
|
||||
"test": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"./test --no-coverage"
|
||||
],
|
||||
"test-full": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"./test"
|
||||
],
|
||||
"act": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"act -j tests --matrix 'laravel:^11.0'"
|
||||
],
|
||||
"act-input": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"act -j tests --matrix 'laravel:^11.0' --input"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ services:
|
|||
test:
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
XDEBUG_ENABLED: ${XDEBUG_ENABLED:-false}
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
|
|
@ -18,7 +20,8 @@ services:
|
|||
dynamodb:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- .:/var/www/html:cached
|
||||
- .:$PWD:cached
|
||||
working_dir: $PWD
|
||||
environment:
|
||||
DOCKER: 1
|
||||
DB_PASSWORD: password
|
||||
|
|
@ -30,6 +33,8 @@ services:
|
|||
TENANCY_TEST_SQLSRV_HOST: mssql
|
||||
TENANCY_TEST_SQLSRV_USERNAME: sa
|
||||
TENANCY_TEST_SQLSRV_PASSWORD: P@ssword
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
stdin_open: true
|
||||
tty: true
|
||||
mysql:
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Bootstrappers;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Illuminate\Config\Repository;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
|
|
@ -39,6 +40,10 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper
|
|||
|
||||
public function bootstrap(Tenant $tenant): void
|
||||
{
|
||||
if (! config('database.connections.tenant')) {
|
||||
throw new Exception('DatabaseCacheBootstrapper must run after DatabaseTenancyBootstrapper.');
|
||||
}
|
||||
|
||||
$stores = $this->getDatabaseCacheStores();
|
||||
|
||||
foreach ($stores as $storeName) {
|
||||
|
|
|
|||
|
|
@ -2,21 +2,42 @@
|
|||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
use Stancl\JobPipeline\JobPipeline;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||
use Stancl\Tenancy\Events\TenantCreated;
|
||||
use Stancl\Tenancy\Jobs\MigrateDatabase;
|
||||
|
||||
uses(TestCase::class)->in(__DIR__);
|
||||
|
||||
function withTenantDatabases()
|
||||
function withTenantDatabases(bool $migrate = false)
|
||||
{
|
||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
||||
Event::listen(TenantCreated::class, JobPipeline::make($migrate
|
||||
? [CreateDatabase::class]
|
||||
: [CreateDatabase::class, MigrateDatabase::class]
|
||||
)->send(function (TenantCreated $event) {
|
||||
return $event->tenant;
|
||||
})->toListener());
|
||||
}
|
||||
|
||||
function withCacheTables()
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
function pest(): TestCase
|
||||
{
|
||||
return \Pest\TestSuite::getInstance()->test;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue