Skip to content

Commit

Permalink
Merge pull request #13 from envor/main
Browse files Browse the repository at this point in the history
add pgsql
  • Loading branch information
inmanturbo authored Jul 3, 2024
2 parents 9a151d6 + 1189399 commit 8e4c2f2
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.3.1
uses: aglipanci/laravel-pint-action@2.4

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to `laravel-schema-macros` will be documented in this file.

## v1.1.4 - 2024-03-14

### What's Changed

* Bump ramsey/composer-install from 2 to 3 by @dependabot in https://github.com/envor/laravel-schema-macros/pull/8
* Support Mariadb Builder by @inmanturbo in https://github.com/envor/laravel-schema-macros/pull/9

### New Contributors

* @dependabot made their first contribution in https://github.com/envor/laravel-schema-macros/pull/8

**Full Changelog**: https://github.com/envor/laravel-schema-macros/compare/v1.1.3...v1.1.4

## v1.1.3 - 2024-02-15

**Full Changelog**: https://github.com/envor/laravel-schema-macros/compare/v1.1.1...v1.1.3
Expand Down
31 changes: 31 additions & 0 deletions src/PgSql/PgSqlCreateDatabaseIfNotExists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Envor\SchemaMacros\PgSql;

use Stringable;

/**
* Create the database if it does not exist
*
* @param string|Stringable $database
*
* @mixin \Illuminate\Database\Schema\MariaDbBuilder
*
* @return bool
*/
class PgSqlCreateDatabaseIfNotExists
{
public function __invoke(): callable
{
return function (string|Stringable $database): bool {
$database = (string) $database;

/** @var \Illuminate\Database\Schema\PostgresBuilder $this */
if ($this->databaseExists($database)) {
return false;
}

return $this->createDatabase($database);
};
}
}
27 changes: 27 additions & 0 deletions src/PgSql/PgSqlDatabaseExists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Envor\SchemaMacros\PgSql;

use Stringable;

/**
* determine if the database exists
*
* @param string|Stringable $database
*
* @mixin \Illuminate\Database\Schema\MariaDbBuilder
*
* @return bool
*/
class PgSqlDatabaseExists
{
public function __invoke(): callable
{
return function (string|Stringable $database): bool {
$database = (string) $database;

/** @var \Illuminate\Database\Schema\PostgresBuilder $this */
return (bool) $this->getConnection()->select("SELECT datname FROM pg_database WHERE datname = '{$database}'");
};
}
}
4 changes: 1 addition & 3 deletions src/SchemaMacrosCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Illuminate\Support\Collection;

class SchemaMacrosCollection extends Collection
{
}
class SchemaMacrosCollection extends Collection {}
2 changes: 2 additions & 0 deletions src/SchemaMacrosServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ private function macros(): array
'sqlite' => \Envor\SchemaMacros\SQLite\SQLiteDatabaseExists::class,
'mysql' => \Envor\SchemaMacros\MySql\MySqlDatabaseExists::class,
'mariadb' => \Envor\SchemaMacros\MariaDb\MariaDbDatabaseExists::class,
'pgsql' => \Envor\SchemaMacros\PgSql\PgSqlDatabaseExists::class,
],
'createDatabaseIfNotExists' => [
'sqlite' => \Envor\SchemaMacros\SQLite\SQLiteCreateDatabaseIfNotExists::class,
'mysql' => \Envor\SchemaMacros\MySql\MySqlCreateDatabaseIfNotExists::class,
'mariadb' => \Envor\SchemaMacros\MariaDb\MariaDbCreateDatabaseIfNotExists::class,
'pgsql' => \Envor\SchemaMacros\PgSql\PgSqlCreateDatabaseIfNotExists::class,
],
'trashDatabase' => [
'sqlite' => \Envor\SchemaMacros\SQLite\SQLiteTrashDatabase::class,
Expand Down
4 changes: 1 addition & 3 deletions src/UnsupportedDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Exception;

class UnsupportedDriver extends Exception
{
}
class UnsupportedDriver extends Exception {}

0 comments on commit 8e4c2f2

Please sign in to comment.