From 212127f16c86875d92a553694a66b222a506485c Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 01:58:28 +0330 Subject: [PATCH 01/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/Integration/Database/SchemaBuilderSchemaNameTest.php diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php new file mode 100644 index 000000000000..79478dc2ca81 --- /dev/null +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -0,0 +1,56 @@ +driver, ['pgsql', 'sqlsrv'])) { + $this->markTestSkipped('Test requires a PostgreSQL or SQL Server connection.'); + } + + DB::statement('create schema my_schema'); + } + + protected function destroyDatabaseMigrations() + { + DB::statement('drop schema my_schema'); + } + + protected function defineEnvironment($app) + { + $this->app['config']->set( + 'database.connections.without-prefix', $this->app['config']->get('database.connections.'.$this->driver) + ); + $this->app['config']->set('database.connections.with-prefix', $this->app['config']->get('database.connections.without-prefix')); + $this->app['config']->set('database.connections.with-prefix.prefix', 'example_'); + } + + #[DataProvider('schemaProvider')] + public function testCreate(Builder $schema) + { + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + }); + + var_dump($schema->getTables()); + + $this->assertTrue($schema->hasTable('my_schema.table')); + $this->assertFalse($schema->hasTable('table')); + } + + public static function schemaProvider(): array + { + return [ + 'without prefix' => [Schema::connection('without-prefix')], + 'with prefix' => [Schema::connection('with-prefix')] + ]; + } +} From b01993abcfd89c54eb84d81de2d10279fe863711 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 02:16:56 +0330 Subject: [PATCH 02/37] wip --- .github/workflows/queues.yml | 160 ----------------- .github/workflows/tests.yml | 169 ------------------ .../Database/SchemaBuilderSchemaNameTest.php | 12 +- 3 files changed, 7 insertions(+), 334 deletions(-) delete mode 100644 .github/workflows/queues.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/queues.yml b/.github/workflows/queues.yml deleted file mode 100644 index fd583e6c3f8f..000000000000 --- a/.github/workflows/queues.yml +++ /dev/null @@ -1,160 +0,0 @@ -name: queues - -on: - push: - branches: - - master - - '*.x' - pull_request: - -jobs: - sync: - runs-on: ubuntu-22.04 - - strategy: - fail-fast: true - - name: Sync Driver - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr - tools: composer:v2 - coverage: none - - - name: Install dependencies - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Queue - env: - QUEUE_CONNECTION: sync - - database: - runs-on: ubuntu-22.04 - - strategy: - fail-fast: true - - name: Database Driver - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr - tools: composer:v2 - coverage: none - - - name: Install dependencies - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Queue - env: - DB_CONNECTION: testing - QUEUE_CONNECTION: database - - redis: - runs-on: ubuntu-22.04 - - services: - redis: - image: redis:7.0 - ports: - - 6379:6379 - options: --entrypoint redis-server - - strategy: - fail-fast: true - - name: Redis Driver - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr - tools: composer:v2 - coverage: none - - - name: Install dependencies - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Queue - env: - QUEUE_CONNECTION: redis - - beanstalkd: - runs-on: ubuntu-22.04 - - name: Beanstalkd Driver - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Download & Extract beanstalkd - run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz - - - name: Make beanstalkd - run: make - working-directory: beanstalkd-1.13 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr - tools: composer:v2 - coverage: none - - - name: Install dependencies - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - - name: Daemonize beanstalkd - run: ./beanstalkd-1.13/beanstalkd & - - - name: Execute tests - run: vendor/bin/phpunit tests/Integration/Queue - env: - QUEUE_CONNECTION: beanstalkd diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 093ad63b7954..000000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,169 +0,0 @@ -name: tests - -on: - push: - branches: - - master - - '*.x' - pull_request: - schedule: - - cron: '0 0 * * *' - -jobs: - linux_tests: - runs-on: ubuntu-22.04 - - services: - memcached: - image: memcached:1.6-alpine - ports: - - 11211:11211 - mysql: - image: mysql:5.7 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: forge - ports: - - 33306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - redis: - image: redis:7.0 - ports: - - 6379:6379 - options: --entrypoint redis-server - dynamodb: - image: amazon/dynamodb-local:2.0.0 - ports: - - 8888:8000 - - strategy: - fail-fast: true - matrix: - php: [8.2, 8.3] - phpunit: ['10.5', '11.0.1'] - stability: [prefer-lowest, prefer-stable] - - name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis-phpredis/phpredis@5.3.7, igbinary, msgpack, lzf, zstd, lz4, memcached, gmp, :php-psr - ini-values: error_reporting=E_ALL - tools: composer:v2 - coverage: none - env: - REDIS_CONFIGURE_OPTS: --enable-redis --enable-redis-igbinary --enable-redis-msgpack --enable-redis-lzf --with-liblzf --enable-redis-zstd --with-libzstd --enable-redis-lz4 --with-liblz4 - REDIS_LIBS: liblz4-dev, liblzf-dev, libzstd-dev - - - name: Set minimum PHP 8.2 versions - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require guzzlehttp/psr7:^2.4 --no-interaction --no-update - - - name: Set PHPUnit - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update - - - name: Install dependencies - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - - - name: Execute tests - run: vendor/bin/phpunit --display-deprecation - env: - DB_PORT: ${{ job.services.mysql.ports[3306] }} - DB_USERNAME: root - DYNAMODB_CACHE_TABLE: laravel_dynamodb_test - DYNAMODB_ENDPOINT: "http://localhost:8888" - AWS_ACCESS_KEY_ID: randomKey - AWS_SECRET_ACCESS_KEY: randomSecret - - - name: Store artifacts - uses: actions/upload-artifact@v3 - with: - name: logs - path: | - vendor/orchestra/testbench-core/laravel/storage/logs - !vendor/**/.gitignore - - windows_tests: - runs-on: windows-2019 - - strategy: - fail-fast: true - matrix: - php: [8.2, 8.3] - phpunit: ['10.5', '11.0.1'] - stability: [prefer-lowest, prefer-stable] - - name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows - - steps: - - name: Set git to use LF - run: | - git config --global core.autocrlf false - git config --global core.eol lf - - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, pdo_mysql, fileinfo, ftp, redis, memcached, gmp, intl, :php-psr - tools: composer:v2 - coverage: none - - - name: Set Minimum PHP 8.2 Versions - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require guzzlehttp/psr7:~2.4 --no-interaction --no-update - - - name: Set PHPUnit - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update - - - name: Install dependencies - uses: nick-fields/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - - - name: Execute tests - run: vendor/bin/phpunit - env: - AWS_ACCESS_KEY_ID: random_key - AWS_SECRET_ACCESS_KEY: random_secret - - - name: Store artifacts - uses: actions/upload-artifact@v3 - with: - name: logs - path: | - vendor/orchestra/testbench-core/laravel/storage/logs - !vendor/**/.gitignore diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 79478dc2ca81..cda41b2ecad6 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -33,9 +33,11 @@ protected function defineEnvironment($app) $this->app['config']->set('database.connections.with-prefix.prefix', 'example_'); } - #[DataProvider('schemaProvider')] - public function testCreate(Builder $schema) + #[DataProvider('connectionProvider')] + public function testCreate($connection) { + $schema = Schema::connection($connection); + $schema->create('my_schema.table', function (Blueprint $table) { $table->id(); }); @@ -46,11 +48,11 @@ public function testCreate(Builder $schema) $this->assertFalse($schema->hasTable('table')); } - public static function schemaProvider(): array + public static function connectionProvider(): array { return [ - 'without prefix' => [Schema::connection('without-prefix')], - 'with prefix' => [Schema::connection('with-prefix')] + 'without prefix' => ['without-prefix'], + 'with prefix' => ['with-prefix'], ]; } } From 50588603b8e75f268e1afc8cebb13f9085de5db0 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 02:36:55 +0330 Subject: [PATCH 03/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index cda41b2ecad6..f174e92b7dc0 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -3,7 +3,6 @@ namespace Illuminate\Tests\Integration\Database; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use PHPUnit\Framework\Attributes\DataProvider; @@ -26,11 +25,13 @@ protected function destroyDatabaseMigrations() protected function defineEnvironment($app) { - $this->app['config']->set( - 'database.connections.without-prefix', $this->app['config']->get('database.connections.'.$this->driver) + parent::defineEnvironment($app); + + $app['config']->set( + 'database.connections.without-prefix', $app['config']->get('database.connections.'.$this->driver) ); - $this->app['config']->set('database.connections.with-prefix', $this->app['config']->get('database.connections.without-prefix')); - $this->app['config']->set('database.connections.with-prefix.prefix', 'example_'); + $app['config']->set('database.connections.with-prefix', $app['config']->get('database.connections.without-prefix')); + $app['config']->set('database.connections.with-prefix.prefix', 'example_'); } #[DataProvider('connectionProvider')] From 9ac3fb36b5066255d4101b62d36552b6cee134a6 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 03:31:25 +0330 Subject: [PATCH 04/37] wip --- .../Schema/Grammars/SqlServerGrammar.php | 1 + .../Database/SchemaBuilderSchemaNameTest.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index b55ca11c394f..b3de9fe8ddae 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -77,6 +77,7 @@ public function compileTables() .'from sys.tables as t ' .'join sys.partitions as p on p.object_id = t.object_id ' .'join sys.allocation_units as u on u.container_id = p.hobt_id ' + ."where t.type = 'U' " .'group by t.name, t.schema_id ' .'order by t.name'; } diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index f174e92b7dc0..a3d7b8a717e8 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -15,21 +15,21 @@ protected function defineDatabaseMigrations() $this->markTestSkipped('Test requires a PostgreSQL or SQL Server connection.'); } - DB::statement('create schema my_schema'); - } + if ($this->driver === 'pgsql') { + DB::connection('without-prefix')->statement('create schema if not exists my_schema'); + DB::connection('with-prefix')->statement('create schema if not exists my_schema'); + } else if ($this->driver === 'sqlsrv') { + DB::connection('without-prefix')->statement("if schema_id('my_schema') is null create schema my_schema"); + DB::connection('with-prefix')->statement("if schema_id('my_schema') is null create schema my_schema"); + } - protected function destroyDatabaseMigrations() - { - DB::statement('drop schema my_schema'); } protected function defineEnvironment($app) { parent::defineEnvironment($app); - $app['config']->set( - 'database.connections.without-prefix', $app['config']->get('database.connections.'.$this->driver) - ); + $app['config']->set('database.connections.without-prefix', $app['config']->get('database.connections.'.$this->driver)); $app['config']->set('database.connections.with-prefix', $app['config']->get('database.connections.without-prefix')); $app['config']->set('database.connections.with-prefix.prefix', 'example_'); } From 776b1ae4e88c6dc0e63d7ec862ca9f6bcf5f3066 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 03:48:17 +0330 Subject: [PATCH 05/37] wip --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index a3d7b8a717e8..28c27b25d80f 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -19,10 +19,9 @@ protected function defineDatabaseMigrations() DB::connection('without-prefix')->statement('create schema if not exists my_schema'); DB::connection('with-prefix')->statement('create schema if not exists my_schema'); } else if ($this->driver === 'sqlsrv') { - DB::connection('without-prefix')->statement("if schema_id('my_schema') is null create schema my_schema"); - DB::connection('with-prefix')->statement("if schema_id('my_schema') is null create schema my_schema"); + DB::connection('without-prefix')->statement("if schema_id('my_schema') is null begin exec('create schema my_schema') end"); + DB::connection('with-prefix')->statement("if schema_id('my_schema') is null begin exec('create schema my_schema') end"); } - } protected function defineEnvironment($app) From 286b99acf72eac4de6becc90a6f60a08b4c5d992 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 04:11:39 +0330 Subject: [PATCH 06/37] wip --- .../Schema/Grammars/SqlServerGrammar.php | 1 - .../Database/SchemaBuilderSchemaNameTest.php | 43 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index b3de9fe8ddae..b55ca11c394f 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -77,7 +77,6 @@ public function compileTables() .'from sys.tables as t ' .'join sys.partitions as p on p.object_id = t.object_id ' .'join sys.allocation_units as u on u.container_id = p.hobt_id ' - ."where t.type = 'U' " .'group by t.name, t.schema_id ' .'order by t.name'; } diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 28c27b25d80f..5aa2f83c0faa 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -48,6 +48,49 @@ public function testCreate($connection) $this->assertFalse($schema->hasTable('table')); } + #[DataProvider('connectionProvider')] + public function testDrop($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + }); + $schema->create('table', function (Blueprint $table) { + $table->id(); + }); + + $this->assertTrue($schema->hasTable('my_schema.table')); + $this->assertTrue($schema->hasTable('table')); + + $schema->drop('my_schema.table'); + + $this->assertFalse($schema->hasTable('my_schema.table')); + $this->assertTrue($schema->hasTable('table')); + } + + #[DataProvider('connectionProvider')] + public function testDropIfExists($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + }); + $schema->create('table', function (Blueprint $table) { + $table->id(); + }); + + $this->assertTrue($schema->hasTable('my_schema.table')); + $this->assertTrue($schema->hasTable('table')); + + $schema->dropIfExists('my_schema.table'); + $schema->dropIfExists('my_schema.fake_table'); + + $this->assertFalse($schema->hasTable('my_schema.table')); + $this->assertTrue($schema->hasTable('table')); + } + public static function connectionProvider(): array { return [ From e8f6093dbffcf60572f3c07352d019e6e5014168 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 04:26:56 +0330 Subject: [PATCH 07/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 5aa2f83c0faa..de7f5489ce8e 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -18,12 +18,18 @@ protected function defineDatabaseMigrations() if ($this->driver === 'pgsql') { DB::connection('without-prefix')->statement('create schema if not exists my_schema'); DB::connection('with-prefix')->statement('create schema if not exists my_schema'); - } else if ($this->driver === 'sqlsrv') { + } elseif ($this->driver === 'sqlsrv') { DB::connection('without-prefix')->statement("if schema_id('my_schema') is null begin exec('create schema my_schema') end"); DB::connection('with-prefix')->statement("if schema_id('my_schema') is null begin exec('create schema my_schema') end"); } } + protected function destroyDatabaseMigrations() + { + $this->artisan('db:wipe', ['--database' => 'without-prefix']); + $this->artisan('db:wipe', ['--database' => 'with-prefix']); + } + protected function defineEnvironment($app) { parent::defineEnvironment($app); @@ -95,7 +101,7 @@ public static function connectionProvider(): array { return [ 'without prefix' => ['without-prefix'], - 'with prefix' => ['with-prefix'], + // 'with prefix' => ['with-prefix'], ]; } } From e7ce3de28f6d601904ee48c14617ec12b8e2c26b Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 04:33:35 +0330 Subject: [PATCH 08/37] wip --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index de7f5489ce8e..95916585bb47 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -24,16 +24,11 @@ protected function defineDatabaseMigrations() } } - protected function destroyDatabaseMigrations() - { - $this->artisan('db:wipe', ['--database' => 'without-prefix']); - $this->artisan('db:wipe', ['--database' => 'with-prefix']); - } - protected function defineEnvironment($app) { parent::defineEnvironment($app); + $app['config']->set('database.connections.pgsql.search_path', 'public,my_schema'); $app['config']->set('database.connections.without-prefix', $app['config']->get('database.connections.'.$this->driver)); $app['config']->set('database.connections.with-prefix', $app['config']->get('database.connections.without-prefix')); $app['config']->set('database.connections.with-prefix.prefix', 'example_'); From 64ea7a57ecc381bc846ca918d642be45798c086c Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 16:10:33 +0330 Subject: [PATCH 09/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 95916585bb47..2a99b8a7f4a3 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -49,6 +49,31 @@ public function testCreate($connection) $this->assertFalse($schema->hasTable('table')); } + public function testRename($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + }); + $schema->create('table', function (Blueprint $table) { + $table->id(); + }); + + $this->assertTrue($schema->hasTable('my_schema.table')); + $this->assertFalse($schema->hasTable('my_schema.new_table')); + $this->assertTrue($schema->hasTable('table')); + $this->assertFalse($schema->hasTable('my_table')); + + $schema->rename('my_schema.table', 'my_schema.new_table'); + $schema->rename('table', 'my_table'); + + $this->assertTrue($schema->hasTable('my_schema.new_table')); + $this->assertFalse($schema->hasTable('my_schema.table')); + $this->assertTrue($schema->hasTable('my_table')); + $this->assertFalse($schema->hasTable('table')); + } + #[DataProvider('connectionProvider')] public function testDrop($connection) { @@ -87,11 +112,79 @@ public function testDropIfExists($connection) $schema->dropIfExists('my_schema.table'); $schema->dropIfExists('my_schema.fake_table'); + $schema->dropIfExists('fake_schema.table'); $this->assertFalse($schema->hasTable('my_schema.table')); $this->assertTrue($schema->hasTable('table')); } + public function testAddColumns($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + $table->string('title')->default('default schema title'); + }); + $schema->create('my_table', function (Blueprint $table) { + $table->id(); + $table->string('name')->default('default name'); + }); + + $this->assertEquals(['id', 'title'], $schema->getColumnListing('my_schema.table')); + $this->assertEquals(['id', 'name'], $schema->getColumnListing('my_table')); + + $schema->table('my_schema.table', function (Blueprint $table) { + $table->string('name')->default('default schema name'); + $table->integer('count'); + }); + $schema->table('my_table', function (Blueprint $table) { + $table->integer('count'); + $table->string('title')->default('default title'); + }); + + $this->assertEquals(['id', 'title', 'name', 'count'], $schema->getColumnListing('my_schema.table')); + $this->assertEquals(['id', 'name', 'count', 'title'], $schema->getColumnListing('my_table')); + $this->assertStringContainsString('default schema name', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'name')['default']); + $this->assertStringContainsString('default schema title', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'title')['default']); + $this->assertStringContainsString('default name', collect($schema->getColumns('my_table'))->firstWhere('name', 'name')['default']); + $this->assertStringContainsString('default title', collect($schema->getColumns('my_table'))->firstWhere('name', 'title')['default']); + } + + #[DataProvider('connectionProvider')] + public function testDropColumns($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + $table->string('name')->default('default schema name'); + $table->integer('count')->default(20); + $table->string('title')->default('default schema title'); + }); + $schema->create('table', function (Blueprint $table) { + $table->id(); + $table->string('name')->default('default name'); + $table->integer('count')->default(10); + $table->string('title')->default('default title'); + }); + + $this->assertTrue($schema->hasColumns('my_schema.table', ['id', 'name', 'count', 'title'])); + $this->assertTrue($schema->hasColumns('table', ['id', 'name', 'count', 'title'])); + + $schema->dropColumns('my_schema.table', ['name', 'count']); + $schema->dropColumns('table', ['name', 'title']); + + $this->assertTrue($schema->hasColumns('my_schema.table', ['id', 'title'])); + $this->assertFalse($schema->hasColumn('my_schema.table', 'name')); + $this->assertFalse($schema->hasColumn('my_schema.table', 'count')); + $this->assertTrue($schema->hasColumns('table', ['id', 'count'])); + $this->assertFalse($schema->hasColumn('table', 'name')); + $this->assertFalse($schema->hasColumn('table', 'title')); + $this->assertStringContainsString('default schema title', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'title')['default']); + $this->assertStringContainsString('10', collect($schema->getColumns('table'))->firstWhere('name', 'count')['default']); + } + public static function connectionProvider(): array { return [ From a5e219311327f12598735eb4297c861704362370 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 16:14:14 +0330 Subject: [PATCH 10/37] wip --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 2a99b8a7f4a3..8e05d9d7b8cb 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -49,6 +49,7 @@ public function testCreate($connection) $this->assertFalse($schema->hasTable('table')); } + #[DataProvider('connectionProvider')] public function testRename($connection) { $schema = Schema::connection($connection); @@ -118,6 +119,7 @@ public function testDropIfExists($connection) $this->assertTrue($schema->hasTable('table')); } + #[DataProvider('connectionProvider')] public function testAddColumns($connection) { $schema = Schema::connection($connection); From 8c7601941778a414af56884aa1227fe2e64e02b6 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 16:19:44 +0330 Subject: [PATCH 11/37] wip --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 8e05d9d7b8cb..a791baeea785 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -66,7 +66,7 @@ public function testRename($connection) $this->assertTrue($schema->hasTable('table')); $this->assertFalse($schema->hasTable('my_table')); - $schema->rename('my_schema.table', 'my_schema.new_table'); + $schema->rename('my_schema.table', 'new_table'); $schema->rename('table', 'my_table'); $this->assertTrue($schema->hasTable('my_schema.new_table')); From 66aa5084d4874372a9429c7c8b1c59ff24219eec Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 17:01:51 +0330 Subject: [PATCH 12/37] fix rename table on sqlsrv --- .../Database/Schema/Grammars/SqlServerGrammar.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index b55ca11c394f..2a60cb207941 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -491,9 +491,10 @@ public function compileDropForeign(Blueprint $blueprint, Fluent $command) */ public function compileRename(Blueprint $blueprint, Fluent $command) { - $from = $this->wrapTable($blueprint); - - return "sp_rename {$from}, ".$this->wrapTable($command->to); + return sprintf('sp_rename %s, %s', + $this->quoteString($this->wrapTable($blueprint)), + $this->wrapTable($command->to) + ); } /** From 8c9e0f69da942b4e9ce18c8c434f34b500fcd18b Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 17:28:05 +0330 Subject: [PATCH 13/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index a791baeea785..00b729aa53b4 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -153,6 +153,38 @@ public function testAddColumns($connection) $this->assertStringContainsString('default title', collect($schema->getColumns('my_table'))->firstWhere('name', 'title')['default']); } + #[DataProvider('connectionProvider')] + public function testRenameColumns($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + $table->string('title')->default('default schema title'); + }); + $schema->create('table', function (Blueprint $table) { + $table->id(); + $table->string('name')->default('default name'); + }); + + $this->assertTrue($schema->hasColumn('my_schema.table', 'title')); + $this->assertTrue($schema->hasColumn('table', 'name')); + + $schema->table('my_schema.table', function (Blueprint $table) { + $table->renameColumn('title', 'new_title'); + }); + $schema->table('my_table', function (Blueprint $table) { + $table->renameColumn('name', 'new_name'); + }); + + $this->assertFalse($schema->hasColumn('my_schema.table', 'title')); + $this->assertTrue($schema->hasColumn('my_schema.table', 'new_title')); + $this->assertFalse($schema->hasColumn('table', 'name')); + $this->assertTrue($schema->hasColumn('table', 'new_name')); + $this->assertStringContainsString('default schema title', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'new_title')['default']); + $this->assertStringContainsString('default name', collect($schema->getColumns('my_table'))->firstWhere('name', 'new_name')['default']); + } + #[DataProvider('connectionProvider')] public function testDropColumns($connection) { @@ -187,6 +219,47 @@ public function testDropColumns($connection) $this->assertStringContainsString('10', collect($schema->getColumns('table'))->firstWhere('name', 'count')['default']); } + #[DataProvider('connectionProvider')] + public function testAddAndRenameAndDropIndexes($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->string('schema_code')->primary(); + $table->string('schema_email')->unique(); + $table->integer('schema_name')->index(); + }); + $schema->create('my_table', function (Blueprint $table) { + $table->string('code')->primary(); + $table->string('email')->unique(); + $table->integer('name')->index(); + }); + + var_dump($schema->getIndexListing('my_schema.table')); + var_dump($schema->getIndexListing('my_table')); + + $this->assertTrue($schema->hasIndex('my_schema.table', ['schema_code'], 'primary')); + $this->assertTrue($schema->hasIndex('my_schema.table', ['schema_email'], 'unique')); + $this->assertTrue($schema->hasIndex('my_schema.table', ['schema_name'])); + $this->assertTrue($schema->hasIndex('my_table', ['code'], 'primary')); + $this->assertTrue($schema->hasIndex('my_table', ['email'], 'unique')); + $this->assertTrue($schema->hasIndex('my_table', ['name'])); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->dropPrimary(['schema_code']); + $table->dropUnique(['schema_email']); + $table->dropIndex(['schema_name']); + }); + $schema->create('my_table', function (Blueprint $table) { + $table->dropPrimary(['code']); + $table->dropUnique(['email']); + $table->dropIndex(['name']); + }); + + $this->assertEmpty($schema->getIndexListing('my_schema.table')); + $this->assertEmpty($schema->getIndexListing('my_table')); + } + public static function connectionProvider(): array { return [ From 81cd4549c18c65b3e7a3f9d5f4e6f65e4717b31e Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 17:36:37 +0330 Subject: [PATCH 14/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 00b729aa53b4..8888c07ffd45 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -43,8 +43,6 @@ public function testCreate($connection) $table->id(); }); - var_dump($schema->getTables()); - $this->assertTrue($schema->hasTable('my_schema.table')); $this->assertFalse($schema->hasTable('table')); } @@ -173,7 +171,7 @@ public function testRenameColumns($connection) $schema->table('my_schema.table', function (Blueprint $table) { $table->renameColumn('title', 'new_title'); }); - $schema->table('my_table', function (Blueprint $table) { + $schema->table('table', function (Blueprint $table) { $table->renameColumn('name', 'new_name'); }); @@ -182,7 +180,7 @@ public function testRenameColumns($connection) $this->assertFalse($schema->hasColumn('table', 'name')); $this->assertTrue($schema->hasColumn('table', 'new_name')); $this->assertStringContainsString('default schema title', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'new_title')['default']); - $this->assertStringContainsString('default name', collect($schema->getColumns('my_table'))->firstWhere('name', 'new_name')['default']); + $this->assertStringContainsString('default name', collect($schema->getColumns('table'))->firstWhere('name', 'new_name')['default']); } #[DataProvider('connectionProvider')] @@ -245,12 +243,12 @@ public function testAddAndRenameAndDropIndexes($connection) $this->assertTrue($schema->hasIndex('my_table', ['email'], 'unique')); $this->assertTrue($schema->hasIndex('my_table', ['name'])); - $schema->create('my_schema.table', function (Blueprint $table) { + $schema->table('my_schema.table', function (Blueprint $table) { $table->dropPrimary(['schema_code']); $table->dropUnique(['schema_email']); $table->dropIndex(['schema_name']); }); - $schema->create('my_table', function (Blueprint $table) { + $schema->table('my_table', function (Blueprint $table) { $table->dropPrimary(['code']); $table->dropUnique(['email']); $table->dropIndex(['name']); From b77c040a5e797caa6920c0b81be610fc2f9b95e5 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 18:21:05 +0330 Subject: [PATCH 15/37] fix rename column and rename index on sqlsrv --- .../Schema/Grammars/SqlServerGrammar.php | 8 ++--- .../Database/SchemaBuilderSchemaNameTest.php | 34 ++++++++++++++----- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index 2a60cb207941..e6b095f5817d 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -215,8 +215,8 @@ public function compileAdd(Blueprint $blueprint, Fluent $command) */ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection) { - return sprintf("sp_rename '%s', %s, 'COLUMN'", - $this->wrap($blueprint->getTable().'.'.$command->from), + return sprintf("sp_rename %s, %s, N'COLUMN'", + $this->quoteString($this->wrapTable($blueprint).'.'.$command->from), $this->wrap($command->to) ); } @@ -506,8 +506,8 @@ public function compileRename(Blueprint $blueprint, Fluent $command) */ public function compileRenameIndex(Blueprint $blueprint, Fluent $command) { - return sprintf("sp_rename N'%s', %s, N'INDEX'", - $this->wrap($blueprint->getTable().'.'.$command->from), + return sprintf("sp_rename %s, %s, N'INDEX'", + $this->quoteString($this->wrapTable($blueprint).'.'.$command->from), $this->wrap($command->to) ); } diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 8888c07ffd45..1f798b1c51dc 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -223,35 +223,51 @@ public function testAddAndRenameAndDropIndexes($connection) $schema = Schema::connection($connection); $schema->create('my_schema.table', function (Blueprint $table) { - $table->string('schema_code')->primary(); - $table->string('schema_email')->unique(); - $table->integer('schema_name')->index(); + $table->id('code');//->primary(); + $table->string('email')->unique(); + $table->integer('name')->index(); + $table->integer('title')->index(); }); $schema->create('my_table', function (Blueprint $table) { $table->string('code')->primary(); $table->string('email')->unique(); $table->integer('name')->index(); + $table->integer('title')->index(); }); var_dump($schema->getIndexListing('my_schema.table')); var_dump($schema->getIndexListing('my_table')); - $this->assertTrue($schema->hasIndex('my_schema.table', ['schema_code'], 'primary')); - $this->assertTrue($schema->hasIndex('my_schema.table', ['schema_email'], 'unique')); - $this->assertTrue($schema->hasIndex('my_schema.table', ['schema_name'])); + $this->assertTrue($schema->hasIndex('my_schema.table', ['code'], 'primary')); + $this->assertTrue($schema->hasIndex('my_schema.table', ['email'], 'unique')); + $this->assertTrue($schema->hasIndex('my_schema.table', ['name'])); $this->assertTrue($schema->hasIndex('my_table', ['code'], 'primary')); $this->assertTrue($schema->hasIndex('my_table', ['email'], 'unique')); $this->assertTrue($schema->hasIndex('my_table', ['name'])); $schema->table('my_schema.table', function (Blueprint $table) { - $table->dropPrimary(['schema_code']); - $table->dropUnique(['schema_email']); - $table->dropIndex(['schema_name']); + $table->renameIndex('my_schema_table_title_index', 'my_schema_table_new_title_index'); + }); + $schema->table('my_table', function (Blueprint $table) { + $table->renameIndex('my_table_title_index', 'my_table_new_title_index'); + }); + + $this->assertTrue($schema->hasIndex('my_schema.table', 'my_schema_table_new_title_index')); + $this->assertFalse($schema->hasIndex('my_schema.table', 'my_schema_table_title_index')); + $this->assertTrue($schema->hasIndex('my_table', 'my_table_new_title_index')); + $this->assertFalse($schema->hasIndex('my_table', 'my_table_title_index')); + + $schema->table('my_schema.table', function (Blueprint $table) { + $table->dropPrimary(['code']); + $table->dropUnique(['email']); + $table->dropIndex(['name']); + $table->dropIndex('my_schema_table_new_title_index'); }); $schema->table('my_table', function (Blueprint $table) { $table->dropPrimary(['code']); $table->dropUnique(['email']); $table->dropIndex(['name']); + $table->dropIndex('my_table_new_title_index'); }); $this->assertEmpty($schema->getIndexListing('my_schema.table')); From 09e176c1b4b2dc330d1f0ed4e14703b927565e0c Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 18:48:54 +0330 Subject: [PATCH 16/37] fix drop primary on pgsql --- src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php | 3 ++- src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php | 4 ++-- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index c71e266230e5..6fb699fb8f34 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -483,7 +483,8 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command) */ public function compileDropPrimary(Blueprint $blueprint, Fluent $command) { - $index = $this->wrap("{$blueprint->getPrefix()}{$blueprint->getTable()}_pkey"); + $table = last(explode('.', $blueprint->getTable())); + $index = $this->wrap("{$blueprint->getPrefix()}{$table}_pkey"); return 'alter table '.$this->wrapTable($blueprint)." drop constraint {$index}"; } diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index e6b095f5817d..f5e811db7334 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -216,7 +216,7 @@ public function compileAdd(Blueprint $blueprint, Fluent $command) public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection) { return sprintf("sp_rename %s, %s, N'COLUMN'", - $this->quoteString($this->wrapTable($blueprint).'.'.$command->from), + $this->quoteString($this->wrapTable($blueprint).'.'.$this->wrap($command->from)), $this->wrap($command->to) ); } @@ -507,7 +507,7 @@ public function compileRename(Blueprint $blueprint, Fluent $command) public function compileRenameIndex(Blueprint $blueprint, Fluent $command) { return sprintf("sp_rename %s, %s, N'INDEX'", - $this->quoteString($this->wrapTable($blueprint).'.'.$command->from), + $this->quoteString($this->wrapTable($blueprint).'.'.$this->wrap($command->from)), $this->wrap($command->to) ); } diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 1f798b1c51dc..437a77e4b6fe 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -223,7 +223,7 @@ public function testAddAndRenameAndDropIndexes($connection) $schema = Schema::connection($connection); $schema->create('my_schema.table', function (Blueprint $table) { - $table->id('code');//->primary(); + $table->string('code')->primary(); $table->string('email')->unique(); $table->integer('name')->index(); $table->integer('title')->index(); From c69042c71e759d353a83ab167e970ac335e44d77 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 19:08:07 +0330 Subject: [PATCH 17/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 437a77e4b6fe..c0cd62db1020 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -218,7 +218,7 @@ public function testDropColumns($connection) } #[DataProvider('connectionProvider')] - public function testAddAndRenameAndDropIndexes($connection) + public function testIndexes($connection) { $schema = Schema::connection($connection); @@ -235,9 +235,6 @@ public function testAddAndRenameAndDropIndexes($connection) $table->integer('title')->index(); }); - var_dump($schema->getIndexListing('my_schema.table')); - var_dump($schema->getIndexListing('my_table')); - $this->assertTrue($schema->hasIndex('my_schema.table', ['code'], 'primary')); $this->assertTrue($schema->hasIndex('my_schema.table', ['email'], 'unique')); $this->assertTrue($schema->hasIndex('my_schema.table', ['name'])); @@ -274,6 +271,57 @@ public function testAddAndRenameAndDropIndexes($connection) $this->assertEmpty($schema->getIndexListing('my_table')); } + #[DataProvider('connectionProvider')] + public function testComment($connection) + { + if ($this->driver !== 'pgsql') { + $this->markTestSkipped('Test requires a PostgreSQL connection.'); + } + + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->comment('comment on schema table'); + $table->string('name')->comment('comment on schema column'); + }); + $schema->create('table', function (Blueprint $table) { + $table->comment('comment on table'); + $table->string('name')->comment('comment on column'); + }); + + $this->assertEquals('comment on schema table', + collect($schema->getTables())->first(fn ($table) => $table['name'] === 'table' && $table['schema'] === 'my_schema')['comment'] + ); + $this->assertEquals('comment on schema column', + collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'name')['comment'] + ); + $this->assertEquals('comment on table', + collect($schema->getTables())->first(fn ($table) => $table['name'] === 'table' && $table['schema'] === 'public')['comment'] + ); + $this->assertEquals('comment on column', + collect($schema->getColumns('table'))->firstWhere('name', 'name')['comment'] + ); + } + + #[DataProvider('connectionProvider')] + public function testAutoIncrementStartingValue($connection) + { + if ($this->driver !== 'pgsql') { + $this->markTestSkipped('Test requires a PostgreSQL connection.'); + } + + $this->expectNotToPerformAssertions(); + + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->increments('code')->from(25); + }); + $schema->create('table', function (Blueprint $table) { + $table->increments('code')->from(15); + }); + } + public static function connectionProvider(): array { return [ From 2a1936fe0191df7be6006e6fc2ba8bc2e3c59311 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 19:32:55 +0330 Subject: [PATCH 18/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index c0cd62db1020..71dfd95dccc3 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -271,6 +271,49 @@ public function testIndexes($connection) $this->assertEmpty($schema->getIndexListing('my_table')); } + #[DataProvider('connectionProvider')] + public function testForeignKeys($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_table', function (Blueprint $table) { + $table->id(); + }); + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + $table->foreignId('my_table_id')->constrained(); + }); + $schema->create('table', function (Blueprint $table) { + $table->unsignedBigInteger('table_id'); + $table->foreign('table_id')->references('id')->on('my_schema.table'); + }); + + $this->assertTrue(collect($schema->getForeignKeys('my_schema.table'))->contains( + fn ($foreign) => $foreign['columns'] === ['my_table_id'] + && $foreign['foreign_table'] === 'my_table' && in_array($foreign['foreign_schema'], ['public', 'dbo']) + && $foreign['foreign_columns'] === ['id'] + )); + + $fk = $schema->getForeignKeys('table'); + var_dump($fk); + + $this->assertTrue(collect($fk)->contains( + fn ($foreign) => $foreign['columns'] === ['table_id'] + && $foreign['foreign_table'] === 'table' && $foreign['foreign_schema'] === 'my_schema' + && $foreign['foreign_columns'] === ['id'] + )); + + $schema->table('my_schema.table', function (Blueprint $table) { + $table->dropForeign(['my_table_id']); + }); + $schema->create('table', function (Blueprint $table) { + $table->dropForeign(['table_id']); + }); + + $this->assertEmpty($schema->getForeignKeys('my_schema.table')); + $this->assertEmpty($schema->getForeignKeys('table')); + } + #[DataProvider('connectionProvider')] public function testComment($connection) { From 63d2c790436dc9776522edea47fabbbb23306d34 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 19:36:47 +0330 Subject: [PATCH 19/37] wip --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 71dfd95dccc3..12273ea4a14c 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -276,7 +276,7 @@ public function testForeignKeys($connection) { $schema = Schema::connection($connection); - $schema->create('my_table', function (Blueprint $table) { + $schema->create('my_tables', function (Blueprint $table) { $table->id(); }); $schema->create('my_schema.table', function (Blueprint $table) { @@ -290,7 +290,7 @@ public function testForeignKeys($connection) $this->assertTrue(collect($schema->getForeignKeys('my_schema.table'))->contains( fn ($foreign) => $foreign['columns'] === ['my_table_id'] - && $foreign['foreign_table'] === 'my_table' && in_array($foreign['foreign_schema'], ['public', 'dbo']) + && $foreign['foreign_table'] === 'my_tables' && in_array($foreign['foreign_schema'], ['public', 'dbo']) && $foreign['foreign_columns'] === ['id'] )); From 5b0707720f6617c72ba3e0d6c46455684c758faa Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 19:39:54 +0330 Subject: [PATCH 20/37] wip --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 12273ea4a14c..e70adc915acc 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -306,7 +306,7 @@ public function testForeignKeys($connection) $schema->table('my_schema.table', function (Blueprint $table) { $table->dropForeign(['my_table_id']); }); - $schema->create('table', function (Blueprint $table) { + $schema->table('table', function (Blueprint $table) { $table->dropForeign(['table_id']); }); From b0722d6fd9414e8ab3f93793834132403eaf87d1 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 20:23:23 +0330 Subject: [PATCH 21/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index e70adc915acc..67f7f4550ac9 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -183,6 +183,37 @@ public function testRenameColumns($connection) $this->assertStringContainsString('default name', collect($schema->getColumns('table'))->firstWhere('name', 'new_name')['default']); } + #[DataProvider('connectionProvider')] + public function testModifyColumns($connection) + { + $schema = Schema::connection($connection); + + $schema->create('my_schema.table', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->integer('count'); + }); + $schema->create('my_table', function (Blueprint $table) { + $table->id(); + $table->string('title'); + $table->integer('count'); + }); + + $schema->table('my_schema.table', function (Blueprint $table) { + $table->string('name')->default('default schema name')->change(); + $table->bigInteger('count')->change(); + }); + $schema->table('my_table', function (Blueprint $table) { + $table->string('title')->default('default title')->change(); + $table->bigInteger('count')->change(); + }); + + $this->assertStringContainsString('default schema name', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'name')['default']); + $this->assertStringContainsString('default title', collect($schema->getColumns('my_table'))->firstWhere('name', 'title')['default']); + $this->assertEquals('bigint', $schema->getColumnType('my_schema.table', 'count')); + $this->assertEquals('bigint', $schema->getColumnType('my_table', 'count')); + } + #[DataProvider('connectionProvider')] public function testDropColumns($connection) { @@ -294,10 +325,7 @@ public function testForeignKeys($connection) && $foreign['foreign_columns'] === ['id'] )); - $fk = $schema->getForeignKeys('table'); - var_dump($fk); - - $this->assertTrue(collect($fk)->contains( + $this->assertTrue(collect($schema->getForeignKeys('table'))->contains( fn ($foreign) => $foreign['columns'] === ['table_id'] && $foreign['foreign_table'] === 'table' && $foreign['foreign_schema'] === 'my_schema' && $foreign['foreign_columns'] === ['id'] From 94bdf84fe1b5bc83802aa990ddecbee4cc1d2c06 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 20:27:59 +0330 Subject: [PATCH 22/37] wip --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 67f7f4550ac9..ed833431cc82 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -210,8 +210,10 @@ public function testModifyColumns($connection) $this->assertStringContainsString('default schema name', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'name')['default']); $this->assertStringContainsString('default title', collect($schema->getColumns('my_table'))->firstWhere('name', 'title')['default']); - $this->assertEquals('bigint', $schema->getColumnType('my_schema.table', 'count')); - $this->assertEquals('bigint', $schema->getColumnType('my_table', 'count')); + $this->assertEquals($this->driver === 'sqlsrv' ? 'nvarchar' : 'varchar', $schema->getColumnType('my_schema.table', 'name')); + $this->assertEquals($this->driver === 'sqlsrv' ? 'nvarchar' : 'varchar', $schema->getColumnType('my_table', 'title')); + $this->assertEquals($this->driver === 'pgsql' ? 'int8' : 'bigint', $schema->getColumnType('my_schema.table', 'count')); + $this->assertEquals($this->driver === 'pgsql' ? 'int8' : 'bigint', $schema->getColumnType('my_table', 'count')); } #[DataProvider('connectionProvider')] From 5111fb6cedb2e56c5b3457df12621ddfc84ec2f1 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 20:31:37 +0330 Subject: [PATCH 23/37] enable prefix tests --- tests/Integration/Database/SchemaBuilderSchemaNameTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index ed833431cc82..462d52ce0542 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -399,7 +399,7 @@ public static function connectionProvider(): array { return [ 'without prefix' => ['without-prefix'], - // 'with prefix' => ['with-prefix'], + 'with prefix' => ['with-prefix'], ]; } } From 69530dfb0adeb16da51631df16a6f0ba6fffd6a0 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 20:48:13 +0330 Subject: [PATCH 24/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 462d52ce0542..c676deb4ec04 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -344,6 +344,21 @@ public function testForeignKeys($connection) $this->assertEmpty($schema->getForeignKeys('table')); } + #[DataProvider('connectionProvider')] + public function testHasView($connection) + { + $connection = DB::connection($connection); + $schema = $connection->getSchemaBuilder(); + + $connection->statement('create view my_schema.view (name) as select 1'); + $connection->statement('create view my_view (name) as select 1'); + + $this->assertTrue($schema->hasView('my_schema.view')); + $this->assertTrue($schema->hasView('my_view')); + $this->assertTrue($schema->hasColumn('my_schema.view', 'name')); + $this->assertTrue($schema->hasColumn('my_view', 'name')); + } + #[DataProvider('connectionProvider')] public function testComment($connection) { From 824912bf86d2b3be1605b89a6d249f38114f2972 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 20:59:14 +0330 Subject: [PATCH 25/37] wip --- .../Integration/Database/SchemaBuilderSchemaNameTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index c676deb4ec04..607601796831 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -350,13 +350,19 @@ public function testHasView($connection) $connection = DB::connection($connection); $schema = $connection->getSchemaBuilder(); - $connection->statement('create view my_schema.view (name) as select 1'); + $connection->statement('create view "my_schema"."view" (name) as select 1'); $connection->statement('create view my_view (name) as select 1'); $this->assertTrue($schema->hasView('my_schema.view')); $this->assertTrue($schema->hasView('my_view')); $this->assertTrue($schema->hasColumn('my_schema.view', 'name')); $this->assertTrue($schema->hasColumn('my_view', 'name')); + + $connection->statement('drop view "my_schema"."view"'); + $connection->statement('drop view my_view'); + + $this->assertFalse($schema->hasView('my_schema.view')); + $this->assertFalse($schema->hasView('my_view')); } #[DataProvider('connectionProvider')] From e3fe0353853fe874e4ce7dd980e96d9f1e6f5257 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 22:52:16 +0330 Subject: [PATCH 26/37] fix prefix auto-increment starting value on pgsql --- src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index 6fb699fb8f34..ca8e477643e5 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -230,7 +230,7 @@ public function compileAutoIncrementStartingValues(Blueprint $blueprint, Fluent { if ($command->column->autoIncrement && $value = $command->column->get('startingValue', $command->column->get('from'))) { - return 'alter sequence '.$blueprint->getTable().'_'.$command->column->name.'_seq restart with '.$value; + return 'alter sequence '.$blueprint->getPrefix().$blueprint->getTable().'_'.$command->column->name.'_seq restart with '.$value; } } From 91943748f0523754a7d75a41fd314f0998a8caf9 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 22:52:37 +0330 Subject: [PATCH 27/37] use blueprint prefix on sqlite --- src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php index 54ef73ef2a4f..5d969c3eaf93 100644 --- a/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php @@ -295,8 +295,8 @@ public function compileChange(Blueprint $blueprint, Fluent $command, Connection fn ($index) => $this->{'compile'.ucfirst($index->name)}($blueprint, $index) )->all(); - $tempTable = $this->wrap('__temp__'.$this->getTablePrefix().$table); - $table = $this->wrap($this->getTablePrefix().$table); + $tempTable = $this->wrap('__temp__'.$blueprint->getPrefix().$table); + $table = $this->wrapTable($blueprint); $columnNames = implode(', ', $columnNames); $foreignKeyConstraintsEnabled = $connection->scalar('pragma foreign_keys'); From 3a60b92c66309e77363647568e0fe5723563c3fd Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 22:53:45 +0330 Subject: [PATCH 28/37] use wrapTable where ever possible --- src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php index f5e811db7334..b719f127f3dc 100755 --- a/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php @@ -358,7 +358,7 @@ public function compileDrop(Blueprint $blueprint, Fluent $command) public function compileDropIfExists(Blueprint $blueprint, Fluent $command) { return sprintf('if object_id(%s, \'U\') is not null drop table %s', - $this->quoteString($this->getTablePrefix().$blueprint->getTable()), + $this->quoteString($this->wrapTable($blueprint)), $this->wrapTable($blueprint) ); } @@ -403,7 +403,7 @@ public function compileDropDefaultConstraint(Blueprint $blueprint, Fluent $comma : "'".implode("','", $command->columns)."'"; $table = $this->wrapTable($blueprint); - $tableName = $this->quoteString($this->getTablePrefix().$blueprint->getTable()); + $tableName = $this->quoteString($this->wrapTable($blueprint)); $sql = "DECLARE @sql NVARCHAR(MAX) = '';"; $sql .= "SELECT @sql += 'ALTER TABLE $table DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' "; From 364c6ffb7cfebb2311a443dcb8859fb067d60877 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 22:54:05 +0330 Subject: [PATCH 29/37] wip --- tests/Database/DatabaseSchemaBlueprintTest.php | 2 +- tests/Database/DatabaseSqlServerSchemaGrammarTest.php | 10 +++++----- .../Database/DatabaseSchemaBlueprintTest.php | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Database/DatabaseSchemaBlueprintTest.php b/tests/Database/DatabaseSchemaBlueprintTest.php index b8a6973f6cbc..a9bb895ec0d1 100755 --- a/tests/Database/DatabaseSchemaBlueprintTest.php +++ b/tests/Database/DatabaseSchemaBlueprintTest.php @@ -181,7 +181,7 @@ public function testRenameColumn() $this->assertEquals(['alter table "users" rename column "foo" to "bar"'], $blueprint->toSql($connection, new SQLiteGrammar)); $blueprint = clone $base; - $this->assertEquals(['sp_rename \'"users"."foo"\', "bar", \'COLUMN\''], $blueprint->toSql($connection, new SqlServerGrammar)); + $this->assertEquals(['sp_rename N\'"users"."foo"\', "bar", N\'COLUMN\''], $blueprint->toSql($connection, new SqlServerGrammar)); } public function testNativeRenameColumnOnMysql57() diff --git a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php index 5b2d4123e8fa..7fb9a89f08fc 100755 --- a/tests/Database/DatabaseSqlServerSchemaGrammarTest.php +++ b/tests/Database/DatabaseSqlServerSchemaGrammarTest.php @@ -83,14 +83,14 @@ public function testDropTableIfExists() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('if object_id(N\'users\', \'U\') is not null drop table "users"', $statements[0]); + $this->assertSame('if object_id(N\'"users"\', \'U\') is not null drop table "users"', $statements[0]); $blueprint = new Blueprint('users'); $blueprint->dropIfExists(); $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()->setTablePrefix('prefix_')); $this->assertCount(1, $statements); - $this->assertSame('if object_id(N\'prefix_users\', \'U\') is not null drop table "prefix_users"', $statements[0]); + $this->assertSame('if object_id(N\'"prefix_users"\', \'U\') is not null drop table "prefix_users"', $statements[0]); } public function testDropColumn() @@ -124,7 +124,7 @@ public function testDropColumnDropsCreatesSqlToDropDefaultConstraints() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame("DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"foo\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'foo') AND [name] in ('bar') AND [default_object_id] <> 0;EXEC(@sql);alter table \"foo\" drop column \"bar\"", $statements[0]); + $this->assertSame("DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"foo\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'\"foo\"') AND [name] in ('bar') AND [default_object_id] <> 0;EXEC(@sql);alter table \"foo\" drop column \"bar\"", $statements[0]); } public function testDropPrimary() @@ -185,7 +185,7 @@ public function testDropConstrainedForeignId() $this->assertCount(2, $statements); $this->assertSame('alter table "users" drop constraint "users_foo_foreign"', $statements[0]); - $this->assertSame('DECLARE @sql NVARCHAR(MAX) = \'\';SELECT @sql += \'ALTER TABLE "users" DROP CONSTRAINT \' + OBJECT_NAME([default_object_id]) + \';\' FROM sys.columns WHERE [object_id] = OBJECT_ID(N\'users\') AND [name] in (\'foo\') AND [default_object_id] <> 0;EXEC(@sql);alter table "users" drop column "foo"', $statements[1]); + $this->assertSame('DECLARE @sql NVARCHAR(MAX) = \'\';SELECT @sql += \'ALTER TABLE "users" DROP CONSTRAINT \' + OBJECT_NAME([default_object_id]) + \';\' FROM sys.columns WHERE [object_id] = OBJECT_ID(N\'"users"\') AND [name] in (\'foo\') AND [default_object_id] <> 0;EXEC(@sql);alter table "users" drop column "foo"', $statements[1]); } public function testDropTimestamps() @@ -226,7 +226,7 @@ public function testRenameTable() $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); $this->assertCount(1, $statements); - $this->assertSame('sp_rename "users", "foo"', $statements[0]); + $this->assertSame('sp_rename N\'"users"\', "foo"', $statements[0]); } public function testRenameIndex() diff --git a/tests/Integration/Database/DatabaseSchemaBlueprintTest.php b/tests/Integration/Database/DatabaseSchemaBlueprintTest.php index 4e88e12aecdf..42fe4de937d7 100644 --- a/tests/Integration/Database/DatabaseSchemaBlueprintTest.php +++ b/tests/Integration/Database/DatabaseSchemaBlueprintTest.php @@ -190,7 +190,7 @@ public function testNativeColumnModifyingOnSqlServer() }); $this->assertEquals([ - "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'users') AND [name] in ('added_at') AND [default_object_id] <> 0;EXEC(@sql)", + "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'\"users\"') AND [name] in ('added_at') AND [default_object_id] <> 0;EXEC(@sql)", 'alter table "users" alter column "added_at" datetime2(4) not null', 'alter table "users" add default CURRENT_TIMESTAMP for "added_at"', ], $blueprint->toSql($connection, new SqlServerGrammar)); @@ -200,7 +200,7 @@ public function testNativeColumnModifyingOnSqlServer() }); $this->assertEquals([ - "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'users') AND [name] in ('name') AND [default_object_id] <> 0;EXEC(@sql)", + "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'\"users\"') AND [name] in ('name') AND [default_object_id] <> 0;EXEC(@sql)", 'alter table "users" alter column "name" nchar(40) collate unicode null', 'alter table "users" add default \'easy\' for "name"', ], $blueprint->toSql($connection, new SqlServerGrammar)); @@ -210,7 +210,7 @@ public function testNativeColumnModifyingOnSqlServer() }); $this->assertEquals([ - "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'users') AND [name] in ('foo') AND [default_object_id] <> 0;EXEC(@sql)", + "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'\"users\"') AND [name] in ('foo') AND [default_object_id] <> 0;EXEC(@sql)", 'alter table "users" alter column "foo" int not null', ], $blueprint->toSql($connection, new SqlServerGrammar)); } @@ -448,7 +448,7 @@ public function testAddUniqueIndexWithoutNameWorks() $queries = $blueprintSqlServer->toSql(DB::connection(), new SqlServerGrammar); $expected = [ - "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'users') AND [name] in ('name') AND [default_object_id] <> 0;EXEC(@sql)", + "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'\"users\"') AND [name] in ('name') AND [default_object_id] <> 0;EXEC(@sql)", 'alter table "users" alter column "name" nvarchar(255) null', 'create unique index "users_name_unique" on "users" ("name")', ]; @@ -512,7 +512,7 @@ public function testAddUniqueIndexWithNameWorks() $queries = $blueprintSqlServer->toSql(DB::connection(), new SqlServerGrammar); $expected = [ - "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'users') AND [name] in ('name') AND [default_object_id] <> 0;EXEC(@sql)", + "DECLARE @sql NVARCHAR(MAX) = '';SELECT @sql += 'ALTER TABLE \"users\" DROP CONSTRAINT ' + OBJECT_NAME([default_object_id]) + ';' FROM sys.columns WHERE [object_id] = OBJECT_ID(N'\"users\"') AND [name] in ('name') AND [default_object_id] <> 0;EXEC(@sql)", 'alter table "users" alter column "name" int null', 'create unique index "index1" on "users" ("name")', ]; From 9e528e07bf374ec2741fbd70e642d958e0cda0a1 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 23:37:11 +0330 Subject: [PATCH 30/37] wip --- .../Integration/Database/SchemaBuilderSchemaNameTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index 607601796831..e361bfea8c4c 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -350,16 +350,16 @@ public function testHasView($connection) $connection = DB::connection($connection); $schema = $connection->getSchemaBuilder(); - $connection->statement('create view "my_schema"."view" (name) as select 1'); - $connection->statement('create view my_view (name) as select 1'); + $connection->statement('create view '.$connection->getSchemaGrammar()->wrapTable('my_schema.view').' (name) as select 1'); + $connection->statement('create view '.$connection->getSchemaGrammar()->wrapTable('my_view').' (name) as select 1'); $this->assertTrue($schema->hasView('my_schema.view')); $this->assertTrue($schema->hasView('my_view')); $this->assertTrue($schema->hasColumn('my_schema.view', 'name')); $this->assertTrue($schema->hasColumn('my_view', 'name')); - $connection->statement('drop view "my_schema"."view"'); - $connection->statement('drop view my_view'); + $connection->statement('drop view '.$connection->getSchemaGrammar()->wrapTable('my_schema.view')); + $connection->statement('drop view '.$connection->getSchemaGrammar()->wrapTable('my_view')); $this->assertFalse($schema->hasView('my_schema.view')); $this->assertFalse($schema->hasView('my_view')); From 441c4a0f3d9e2ec8c614428c7034314a4bbf9ba3 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 9 Feb 2024 23:59:47 +0330 Subject: [PATCH 31/37] fix index name with schema name+prefix --- src/Illuminate/Database/Schema/Blueprint.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php index d2c03f501e04..cd254b71b3f2 100755 --- a/src/Illuminate/Database/Schema/Blueprint.php +++ b/src/Illuminate/Database/Schema/Blueprint.php @@ -1599,7 +1599,11 @@ protected function dropIndexCommand($command, $type, $index) */ protected function createIndexName($type, array $columns) { - $index = strtolower($this->prefix.$this->table.'_'.implode('_', $columns).'_'.$type); + $table = str_contains($this->table, '.') + ? substr_replace($this->table, '.'.$this->prefix, strrpos($this->table, '.'), 1) + : $this->prefix.$this->table; + + $index = strtolower($table.'_'.implode('_', $columns).'_'.$type); return str_replace(['-', '.'], '_', $index); } From 4b6e567647e46597272585ed6d563e93f1e79d59 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 10 Feb 2024 00:02:28 +0330 Subject: [PATCH 32/37] fix schema name+prefix --- src/Illuminate/Database/Grammar.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Grammar.php b/src/Illuminate/Database/Grammar.php index 9ce0ec352595..84196daeb9a1 100755 --- a/src/Illuminate/Database/Grammar.php +++ b/src/Illuminate/Database/Grammar.php @@ -44,7 +44,11 @@ public function wrapArray(array $values) public function wrapTable($table) { if (! $this->isExpression($table)) { - return $this->wrap($this->tablePrefix.$table, true); + $table = str_contains($table, '.') + ? substr_replace($table, '.'.$this->tablePrefix, strrpos($table, '.'), 1) + : $this->tablePrefix.$table; + + return $this->wrap($table, true); } return $this->getValue($table); From 1304592f63ecb9c194def740e069e8170d8058c9 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 10 Feb 2024 00:04:33 +0330 Subject: [PATCH 33/37] wip --- .github/workflows/queues.yml | 160 +++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 169 +++++++++++++++++++++++++++++++++++ 2 files changed, 329 insertions(+) create mode 100644 .github/workflows/queues.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/queues.yml b/.github/workflows/queues.yml new file mode 100644 index 000000000000..fd583e6c3f8f --- /dev/null +++ b/.github/workflows/queues.yml @@ -0,0 +1,160 @@ +name: queues + +on: + push: + branches: + - master + - '*.x' + pull_request: + +jobs: + sync: + runs-on: ubuntu-22.04 + + strategy: + fail-fast: true + + name: Sync Driver + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit tests/Integration/Queue + env: + QUEUE_CONNECTION: sync + + database: + runs-on: ubuntu-22.04 + + strategy: + fail-fast: true + + name: Database Driver + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit tests/Integration/Queue + env: + DB_CONNECTION: testing + QUEUE_CONNECTION: database + + redis: + runs-on: ubuntu-22.04 + + services: + redis: + image: redis:7.0 + ports: + - 6379:6379 + options: --entrypoint redis-server + + strategy: + fail-fast: true + + name: Redis Driver + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit tests/Integration/Queue + env: + QUEUE_CONNECTION: redis + + beanstalkd: + runs-on: ubuntu-22.04 + + name: Beanstalkd Driver + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download & Extract beanstalkd + run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz + + - name: Make beanstalkd + run: make + working-directory: beanstalkd-1.13 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + + - name: Daemonize beanstalkd + run: ./beanstalkd-1.13/beanstalkd & + + - name: Execute tests + run: vendor/bin/phpunit tests/Integration/Queue + env: + QUEUE_CONNECTION: beanstalkd diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000000..093ad63b7954 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,169 @@ +name: tests + +on: + push: + branches: + - master + - '*.x' + pull_request: + schedule: + - cron: '0 0 * * *' + +jobs: + linux_tests: + runs-on: ubuntu-22.04 + + services: + memcached: + image: memcached:1.6-alpine + ports: + - 11211:11211 + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: forge + ports: + - 33306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + redis: + image: redis:7.0 + ports: + - 6379:6379 + options: --entrypoint redis-server + dynamodb: + image: amazon/dynamodb-local:2.0.0 + ports: + - 8888:8000 + + strategy: + fail-fast: true + matrix: + php: [8.2, 8.3] + phpunit: ['10.5', '11.0.1'] + stability: [prefer-lowest, prefer-stable] + + name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis-phpredis/phpredis@5.3.7, igbinary, msgpack, lzf, zstd, lz4, memcached, gmp, :php-psr + ini-values: error_reporting=E_ALL + tools: composer:v2 + coverage: none + env: + REDIS_CONFIGURE_OPTS: --enable-redis --enable-redis-igbinary --enable-redis-msgpack --enable-redis-lzf --with-liblzf --enable-redis-zstd --with-libzstd --enable-redis-lz4 --with-liblz4 + REDIS_LIBS: liblz4-dev, liblzf-dev, libzstd-dev + + - name: Set minimum PHP 8.2 versions + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require guzzlehttp/psr7:^2.4 --no-interaction --no-update + + - name: Set PHPUnit + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update + + - name: Install dependencies + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit --display-deprecation + env: + DB_PORT: ${{ job.services.mysql.ports[3306] }} + DB_USERNAME: root + DYNAMODB_CACHE_TABLE: laravel_dynamodb_test + DYNAMODB_ENDPOINT: "http://localhost:8888" + AWS_ACCESS_KEY_ID: randomKey + AWS_SECRET_ACCESS_KEY: randomSecret + + - name: Store artifacts + uses: actions/upload-artifact@v3 + with: + name: logs + path: | + vendor/orchestra/testbench-core/laravel/storage/logs + !vendor/**/.gitignore + + windows_tests: + runs-on: windows-2019 + + strategy: + fail-fast: true + matrix: + php: [8.2, 8.3] + phpunit: ['10.5', '11.0.1'] + stability: [prefer-lowest, prefer-stable] + + name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows + + steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, pdo_mysql, fileinfo, ftp, redis, memcached, gmp, intl, :php-psr + tools: composer:v2 + coverage: none + + - name: Set Minimum PHP 8.2 Versions + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require guzzlehttp/psr7:~2.4 --no-interaction --no-update + + - name: Set PHPUnit + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require phpunit/phpunit:~${{ matrix.phpunit }} --dev --no-interaction --no-update + + - name: Install dependencies + uses: nick-fields/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit + env: + AWS_ACCESS_KEY_ID: random_key + AWS_SECRET_ACCESS_KEY: random_secret + + - name: Store artifacts + uses: actions/upload-artifact@v3 + with: + name: logs + path: | + vendor/orchestra/testbench-core/laravel/storage/logs + !vendor/**/.gitignore From b60cb3cf1833dfaaef5e76a97ed3eab2e8959eb2 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 10 Feb 2024 17:08:31 +0330 Subject: [PATCH 34/37] fix wrapping table --- src/Illuminate/Database/Grammar.php | 54 +++++++++++++++++++---------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/Illuminate/Database/Grammar.php b/src/Illuminate/Database/Grammar.php index 84196daeb9a1..79da1724ccb4 100755 --- a/src/Illuminate/Database/Grammar.php +++ b/src/Illuminate/Database/Grammar.php @@ -43,25 +43,38 @@ public function wrapArray(array $values) */ public function wrapTable($table) { - if (! $this->isExpression($table)) { - $table = str_contains($table, '.') - ? substr_replace($table, '.'.$this->tablePrefix, strrpos($table, '.'), 1) - : $this->tablePrefix.$table; + if ($this->isExpression($table)) { + return $this->getValue($table); + } + + // If the table being wrapped has an alias we'll need to separate the pieces + // so we can prefix the table and then wrap each of the segments on their + // own and then join these both back together using the "as" connector. + if (stripos($table, ' as ') !== false) { + return $this->wrapAliasedTable($table); + } + + // If the table being wrapped has a custom schema name specified, we need to + // prefix the last segment as the table name then wrap each segment alone + // and eventually join them both back together using the dot connector. + if (str_contains($table, '.')) { + $table = substr_replace($table, '.'.$this->tablePrefix, strrpos($table, '.'), 1); - return $this->wrap($table, true); + return collect(explode('.', $table)) + ->map($this->wrapValue(...)) + ->implode('.'); } - return $this->getValue($table); + return $this->wrapValue($this->tablePrefix.$table); } /** * Wrap a value in keyword identifiers. * * @param \Illuminate\Contracts\Database\Query\Expression|string $value - * @param bool $prefixAlias * @return string */ - public function wrap($value, $prefixAlias = false) + public function wrap($value) { if ($this->isExpression($value)) { return $this->getValue($value); @@ -71,7 +84,7 @@ public function wrap($value, $prefixAlias = false) // the pieces so we can wrap each of the segments of the expression on its // own, and then join these both back together using the "as" connector. if (stripos($value, ' as ') !== false) { - return $this->wrapAliasedValue($value, $prefixAlias); + return $this->wrapAliasedValue($value); } // If the given value is a JSON selector we will wrap it differently than a @@ -88,23 +101,28 @@ public function wrap($value, $prefixAlias = false) * Wrap a value that has an alias. * * @param string $value - * @param bool $prefixAlias * @return string */ - protected function wrapAliasedValue($value, $prefixAlias = false) + protected function wrapAliasedValue($value) { $segments = preg_split('/\s+as\s+/i', $value); - // If we are wrapping a table we need to prefix the alias with the table prefix - // as well in order to generate proper syntax. If this is a column of course - // no prefix is necessary. The condition will be true when from wrapTable. - if ($prefixAlias) { - $segments[1] = $this->tablePrefix.$segments[1]; - } - return $this->wrap($segments[0]).' as '.$this->wrapValue($segments[1]); } + /** + * Wrap a table that has an alias. + * + * @param string $value + * @return string + */ + protected function wrapAliasedTable($value) + { + $segments = preg_split('/\s+as\s+/i', $value); + + return $this->wrapTable($segments[0]).' as '.$this->wrapValue($this->tablePrefix.$segments[1]); + } + /** * Wrap the given value segments. * From 5154f04dcfce5e83d9e79f85968c7017595887fa Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 10 Feb 2024 17:31:18 +0330 Subject: [PATCH 35/37] fix auto-increment starting value on pgsql --- src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index ca8e477643e5..aad87542d552 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -230,7 +230,9 @@ public function compileAutoIncrementStartingValues(Blueprint $blueprint, Fluent { if ($command->column->autoIncrement && $value = $command->column->get('startingValue', $command->column->get('from'))) { - return 'alter sequence '.$blueprint->getPrefix().$blueprint->getTable().'_'.$command->column->name.'_seq restart with '.$value; + $table = last(explode('.', $blueprint->getTable())); + + return 'alter sequence '.$blueprint->getPrefix().$table.'_'.$command->column->name.'_seq restart with '.$value; } } From fc6f9819adea276c77fe9e8302be9edb228293fe Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 10 Feb 2024 17:31:33 +0330 Subject: [PATCH 36/37] wip --- .../Database/SchemaBuilderSchemaNameTest.php | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index e361bfea8c4c..c9f5d5306e6b 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -275,29 +275,32 @@ public function testIndexes($connection) $this->assertTrue($schema->hasIndex('my_table', ['email'], 'unique')); $this->assertTrue($schema->hasIndex('my_table', ['name'])); - $schema->table('my_schema.table', function (Blueprint $table) { - $table->renameIndex('my_schema_table_title_index', 'my_schema_table_new_title_index'); + $schemaIndexName = $connection === 'with-prefix' ? 'my_schema_example_table_title_index' : 'my_schema_table_title_index'; + $indexName = $connection === 'with-prefix' ? 'example_my_table_title_index' : 'my_table_title_index'; + + $schema->table('my_schema.table', function (Blueprint $table) use ($schemaIndexName) { + $table->renameIndex($schemaIndexName, 'schema_new_index_name'); }); - $schema->table('my_table', function (Blueprint $table) { - $table->renameIndex('my_table_title_index', 'my_table_new_title_index'); + $schema->table('my_table', function (Blueprint $table) use ($indexName) { + $table->renameIndex($indexName, 'new_index_name'); }); - $this->assertTrue($schema->hasIndex('my_schema.table', 'my_schema_table_new_title_index')); - $this->assertFalse($schema->hasIndex('my_schema.table', 'my_schema_table_title_index')); - $this->assertTrue($schema->hasIndex('my_table', 'my_table_new_title_index')); - $this->assertFalse($schema->hasIndex('my_table', 'my_table_title_index')); + $this->assertTrue($schema->hasIndex('my_schema.table', 'schema_new_index_name')); + $this->assertFalse($schema->hasIndex('my_schema.table', $schemaIndexName)); + $this->assertTrue($schema->hasIndex('my_table', 'new_index_name')); + $this->assertFalse($schema->hasIndex('my_table', $indexName)); $schema->table('my_schema.table', function (Blueprint $table) { $table->dropPrimary(['code']); $table->dropUnique(['email']); $table->dropIndex(['name']); - $table->dropIndex('my_schema_table_new_title_index'); + $table->dropIndex('schema_new_index_name'); }); $schema->table('my_table', function (Blueprint $table) { $table->dropPrimary(['code']); $table->dropUnique(['email']); $table->dropIndex(['name']); - $table->dropIndex('my_table_new_title_index'); + $table->dropIndex('new_index_name'); }); $this->assertEmpty($schema->getIndexListing('my_schema.table')); @@ -321,6 +324,8 @@ public function testForeignKeys($connection) $table->foreign('table_id')->references('id')->on('my_schema.table'); }); + var_dump($schema->getForeignKeys('my_schema.table')); + $this->assertTrue(collect($schema->getForeignKeys('my_schema.table'))->contains( fn ($foreign) => $foreign['columns'] === ['my_table_id'] && $foreign['foreign_table'] === 'my_tables' && in_array($foreign['foreign_schema'], ['public', 'dbo']) @@ -383,6 +388,8 @@ public function testComment($connection) $table->string('name')->comment('comment on column'); }); + var_dump($schema->getTables()); + $this->assertEquals('comment on schema table', collect($schema->getTables())->first(fn ($table) => $table['name'] === 'table' && $table['schema'] === 'my_schema')['comment'] ); From 81d1be54e99503f9fa45cba04915c8afbeaf5c7f Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 10 Feb 2024 17:43:31 +0330 Subject: [PATCH 37/37] fix tests --- .../Database/SchemaBuilderSchemaNameTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php index c9f5d5306e6b..2d6d9512ed87 100644 --- a/tests/Integration/Database/SchemaBuilderSchemaNameTest.php +++ b/tests/Integration/Database/SchemaBuilderSchemaNameTest.php @@ -324,17 +324,18 @@ public function testForeignKeys($connection) $table->foreign('table_id')->references('id')->on('my_schema.table'); }); - var_dump($schema->getForeignKeys('my_schema.table')); + $schemaTableName = $connection === 'with-prefix' ? 'example_table' : 'table'; + $tableName = $connection === 'with-prefix' ? 'example_my_tables' : 'my_tables'; $this->assertTrue(collect($schema->getForeignKeys('my_schema.table'))->contains( fn ($foreign) => $foreign['columns'] === ['my_table_id'] - && $foreign['foreign_table'] === 'my_tables' && in_array($foreign['foreign_schema'], ['public', 'dbo']) + && $foreign['foreign_table'] === $tableName && in_array($foreign['foreign_schema'], ['public', 'dbo']) && $foreign['foreign_columns'] === ['id'] )); $this->assertTrue(collect($schema->getForeignKeys('table'))->contains( fn ($foreign) => $foreign['columns'] === ['table_id'] - && $foreign['foreign_table'] === 'table' && $foreign['foreign_schema'] === 'my_schema' + && $foreign['foreign_table'] === $schemaTableName && $foreign['foreign_schema'] === 'my_schema' && $foreign['foreign_columns'] === ['id'] )); @@ -388,17 +389,18 @@ public function testComment($connection) $table->string('name')->comment('comment on column'); }); - var_dump($schema->getTables()); + $tables = collect($schema->getTables()); + $tableName = $connection === 'with-prefix' ? 'example_table' : 'table'; $this->assertEquals('comment on schema table', - collect($schema->getTables())->first(fn ($table) => $table['name'] === 'table' && $table['schema'] === 'my_schema')['comment'] + $tables->first(fn ($table) => $table['name'] === $tableName && $table['schema'] === 'my_schema')['comment'] + ); + $this->assertEquals('comment on table', + $tables->first(fn ($table) => $table['name'] === $tableName && $table['schema'] === 'public')['comment'] ); $this->assertEquals('comment on schema column', collect($schema->getColumns('my_schema.table'))->firstWhere('name', 'name')['comment'] ); - $this->assertEquals('comment on table', - collect($schema->getTables())->first(fn ($table) => $table['name'] === 'table' && $table['schema'] === 'public')['comment'] - ); $this->assertEquals('comment on column', collect($schema->getColumns('table'))->firstWhere('name', 'name')['comment'] );