Skip to content

Commit

Permalink
Merge pull request #155 from vs0uz4/dev
Browse files Browse the repository at this point in the history
feature: [wip] implementation of the rescue functionality of the database server version used
  • Loading branch information
luanfreitasdev authored Nov 26, 2021
2 parents 77c87f7 + e89a5b1 commit 1f8cf04
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@
"test:sqlite": "./vendor/bin/pest --configuration phpunit.sqlite.xml",
"test:mysql": "./vendor/bin/pest --configuration phpunit.mysql.xml",
"test:pgsql": "./vendor/bin/pest --configuration phpunit.pgsql.xml",
"test:sqlsrv": "./vendor/bin/pest --configuration phpunit.sqlsrv.xml",
"test:types": "./vendor/bin/phpstan analyse --ansi --memory-limit=-1",
"test:dbs": [
"@test:sqlite",
"@test:mysql",
"@test:pgsql"
"@test:pgsql",
"@test:sqlsrv"
],
"check": [
"@cs-fixer",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.mysql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<server name="APP_ENV" value="testing"/>
<server name="DB_DRIVER" value="mysql"/>
<server name="DB_HOST" value="127.0.0.1"/>
<server name="DB_PORT" value="3308"/>
<server name="DB_PORT" value="3307"/>
<server name="DB_USERNAME" value="root"/>
<server name="DB_PASSWORD" value="password"/>
<server name="DB_DATABASE" value="powergridtest"/>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.pgsql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<server name="DB_HOST" value="127.0.0.1"/>
<server name="DB_PORT" value="5433"/>
<server name="DB_USERNAME" value="postgres"/>
<server name="DB_PASSWORD" value="postgres"/>
<server name="DB_PASSWORD" value="password"/>
<server name="DB_DATABASE" value="powergridtest"/>
</php>
</phpunit>
8 changes: 4 additions & 4 deletions phpunit.sqlsrv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<server name="APP_ENV" value="testing"/>
<server name="DB_DRIVER" value="sqlsrv"/>
<server name="DB_HOST" value="127.0.0.1"/>
<server name="DB_PORT" value="3308"/>
<server name="DB_USERNAME" value="root"/>
<server name="DB_PASSWORD" value="password"/>
<server name="DB_DATABASE" value="powergridtest"/>
<server name="DB_PORT" value="1434"/>
<server name="DB_USERNAME" value="sa"/>
<server name="DB_PASSWORD" value="yourStrong(!)Password"/>
<server name="DB_DATABASE" value="tempdb"/>
</php>
</phpunit>
18 changes: 14 additions & 4 deletions src/Helpers/SqlSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace PowerComponents\LivewirePowerGrid\Helpers;

use Illuminate\Support\Facades\{DB, Log, Schema};
use Exception;
use Illuminate\Support\Facades\{DB, Schema};

class SqlSupport
{
Expand Down Expand Up @@ -63,7 +64,7 @@ private static function getSortSqlByDriver(string $sortField, string $driverName
}

/**
* @param string $sortFieldType
* @param string|null $sortFieldType
* @return bool
*/
public static function isValidSortFieldType(?string $sortFieldType): bool
Expand All @@ -78,7 +79,7 @@ public static function isValidSortFieldType(?string $sortFieldType): bool
/**
* @param string $sortField
* @return string
* @throws \Exception
* @throws Exception
*/
public static function getSortFieldType(string $sortField): ?string
{
Expand All @@ -88,12 +89,21 @@ public static function getSortFieldType(string $sortField): ?string
}

if (!Schema::hasColumn($data[0], $data[1])) {
throw new \Exception("There is no column with name '$data[1]' on table '$data[0]'. Please see: https://livewire-powergrid.docsforge.com/main/include-columns/#fieldstring-field-string-datafield");
throw new Exception("There is no column with name '$data[1]' on table '$data[0]'. Please see: https://livewire-powergrid.docsforge.com/main/include-columns/#fieldstring-field-string-datafield");
}

return Schema::getConnection()
->getDoctrineColumn($data[0], $data[1])
->getType()
->getName();
}

/**
* @return string
*/
public static function getServerVersion(): string
{
return DB::getPdo()
->getAttribute(constant('PDO::ATTR_SERVER_VERSION'));
}
}

0 comments on commit 1f8cf04

Please sign in to comment.