Skip to content

Commit 8e4c2f2

Browse files
authored
Merge pull request #13 from envor/main
add pgsql
2 parents 9a151d6 + 1189399 commit 8e4c2f2

8 files changed

+77
-8
lines changed

.github/workflows/dependabot-auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- name: Dependabot metadata
1616
id: metadata
17-
uses: dependabot/fetch-metadata@v1.6.0
17+
uses: dependabot/fetch-metadata@v2.1.0
1818
with:
1919
github-token: "${{ secrets.GITHUB_TOKEN }}"
2020

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
ref: ${{ github.head_ref }}
2121

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

2525
- name: Commit changes
2626
uses: stefanzweifel/git-auto-commit-action@v5

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
## v1.1.4 - 2024-03-14
6+
7+
### What's Changed
8+
9+
* Bump ramsey/composer-install from 2 to 3 by @dependabot in https://github.com/envor/laravel-schema-macros/pull/8
10+
* Support Mariadb Builder by @inmanturbo in https://github.com/envor/laravel-schema-macros/pull/9
11+
12+
### New Contributors
13+
14+
* @dependabot made their first contribution in https://github.com/envor/laravel-schema-macros/pull/8
15+
16+
**Full Changelog**: https://github.com/envor/laravel-schema-macros/compare/v1.1.3...v1.1.4
17+
518
## v1.1.3 - 2024-02-15
619

720
**Full Changelog**: https://github.com/envor/laravel-schema-macros/compare/v1.1.1...v1.1.3
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Envor\SchemaMacros\PgSql;
4+
5+
use Stringable;
6+
7+
/**
8+
* Create the database if it does not exist
9+
*
10+
* @param string|Stringable $database
11+
*
12+
* @mixin \Illuminate\Database\Schema\MariaDbBuilder
13+
*
14+
* @return bool
15+
*/
16+
class PgSqlCreateDatabaseIfNotExists
17+
{
18+
public function __invoke(): callable
19+
{
20+
return function (string|Stringable $database): bool {
21+
$database = (string) $database;
22+
23+
/** @var \Illuminate\Database\Schema\PostgresBuilder $this */
24+
if ($this->databaseExists($database)) {
25+
return false;
26+
}
27+
28+
return $this->createDatabase($database);
29+
};
30+
}
31+
}

src/PgSql/PgSqlDatabaseExists.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Envor\SchemaMacros\PgSql;
4+
5+
use Stringable;
6+
7+
/**
8+
* determine if the database exists
9+
*
10+
* @param string|Stringable $database
11+
*
12+
* @mixin \Illuminate\Database\Schema\MariaDbBuilder
13+
*
14+
* @return bool
15+
*/
16+
class PgSqlDatabaseExists
17+
{
18+
public function __invoke(): callable
19+
{
20+
return function (string|Stringable $database): bool {
21+
$database = (string) $database;
22+
23+
/** @var \Illuminate\Database\Schema\PostgresBuilder $this */
24+
return (bool) $this->getConnection()->select("SELECT datname FROM pg_database WHERE datname = '{$database}'");
25+
};
26+
}
27+
}

src/SchemaMacrosCollection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
use Illuminate\Support\Collection;
66

7-
class SchemaMacrosCollection extends Collection
8-
{
9-
}
7+
class SchemaMacrosCollection extends Collection {}

src/SchemaMacrosServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ private function macros(): array
3434
'sqlite' => \Envor\SchemaMacros\SQLite\SQLiteDatabaseExists::class,
3535
'mysql' => \Envor\SchemaMacros\MySql\MySqlDatabaseExists::class,
3636
'mariadb' => \Envor\SchemaMacros\MariaDb\MariaDbDatabaseExists::class,
37+
'pgsql' => \Envor\SchemaMacros\PgSql\PgSqlDatabaseExists::class,
3738
],
3839
'createDatabaseIfNotExists' => [
3940
'sqlite' => \Envor\SchemaMacros\SQLite\SQLiteCreateDatabaseIfNotExists::class,
4041
'mysql' => \Envor\SchemaMacros\MySql\MySqlCreateDatabaseIfNotExists::class,
4142
'mariadb' => \Envor\SchemaMacros\MariaDb\MariaDbCreateDatabaseIfNotExists::class,
43+
'pgsql' => \Envor\SchemaMacros\PgSql\PgSqlCreateDatabaseIfNotExists::class,
4244
],
4345
'trashDatabase' => [
4446
'sqlite' => \Envor\SchemaMacros\SQLite\SQLiteTrashDatabase::class,

src/UnsupportedDriver.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
use Exception;
66

7-
class UnsupportedDriver extends Exception
8-
{
9-
}
7+
class UnsupportedDriver extends Exception {}

0 commit comments

Comments
 (0)