├── .editorconfig ├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── composer.json └── src ├── Providers └── LaravelOptimizedPostgresService.php ├── Schema.php └── SchemaGrammar.php /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | 17 | [.blackfire.yaml] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: mikebronner # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | node_modules/ 3 | npm-debug.log 4 | composer.lock 5 | 6 | # Laravel 4 specific 7 | bootstrap/compiled.php 8 | app/storage/ 9 | 10 | # Laravel 5 & Lumen specific 11 | public/storage 12 | public/hot 13 | storage/*.key 14 | .env.*.php 15 | .env.php 16 | .env 17 | Homestead.yaml 18 | Homestead.json 19 | 20 | # Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer 21 | .rocketeer/ 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 GeneaLabs, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Optimized Postgres for Laravel 2 | 3 | ![Optimized Postgres for Laravel](https://repository-images.githubusercontent.com/94943563/38eea380-f344-11e9-95f0-1cd990116866) 4 | 5 | [![Join the chat at https://gitter.im/GeneaLabs/laravel-optimized-postgres](https://badges.gitter.im/GeneaLabs/laravel-optimized-postgres.svg)](https://gitter.im/GeneaLabs/laravel-optimized-postgres?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6 | 7 | ## Impetus 8 | By default I like my Postgres database to use `text` type for all textual fields. 9 | When you run your migrations with this package installed, it will convert the 10 | following migration types to `text`: `char`, and `string`. 11 | 12 | ## Installation 13 | ### Requirements 14 | - PHP >=7.0 15 | - Laravel >=5.4 16 | 17 | ### Composer Command 18 | ```sh 19 | composer require genealabs/laravel-optimized-postgres 20 | ``` 21 | 22 | ### Service Provider 23 | If you are on Laravel 5.5, the service provider will auto-register once the 24 | package is installed. You can skip this step. If you haven't upgraded to 25 | Laravel 5.5 yet, add the following to the `providers` array in your 26 | `\config\app.php` file: 27 | ```php 28 | GeneaLabs\LaravelOptimizedPostgres\Providers\LaravelOptimizedPostgresService::class, 29 | ``` 30 | 31 | ## Usage 32 | When writing migrations, be sure to remove the following use statement from the 33 | top of the file: 34 | ```php 35 | use Illuminate\Support\Facades\Schema; 36 | ``` 37 | 38 | This is included in the two default migrations provided with Laravel projects, 39 | but I don't believe is added when you `make` a new migration. 40 | 41 | ## Future Updates 42 | - possibly expand to normalize numbers, more research needed. 43 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genealabs/laravel-optimized-postgres", 3 | "description": "optimizes field types for Postgres.", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Mike Bronner", 8 | "email": "mike@genealabs.com" 9 | } 10 | ], 11 | "require": { 12 | "php": "^8.2", 13 | "illuminate/database": "^10.0|^11.0|^12.0", 14 | "illuminate/support": "^10.0|^11.0|^12.0" 15 | }, 16 | "autoload": { 17 | "psr-4": { 18 | "GeneaLabs\\LaravelOptimizedPostgres\\": "src/", 19 | "GeneaLabs\\LaravelOptimizedPostgres\\Tests\\": "tests/" 20 | } 21 | }, 22 | "minimum-stability": "stable", 23 | "extra": { 24 | "laravel": { 25 | "providers": [ 26 | "GeneaLabs\\LaravelOptimizedPostgres\\Providers\\LaravelOptimizedPostgresService" 27 | ] 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Providers/LaravelOptimizedPostgresService.php: -------------------------------------------------------------------------------- 1 | alias('Schema', Schema::class); 21 | $this->registerSchemaMacros(); 22 | } 23 | 24 | public function provides() : array 25 | { 26 | return ['genealabs-laravel-optimized-postgres']; 27 | } 28 | 29 | protected function registerSchemaMacros() 30 | { 31 | Blueprint::macro('dropIndexIfExists', function (string $index): Fluent { 32 | if ($this->hasIndex($index)) { 33 | return $this->dropIndex($index); 34 | } 35 | 36 | return new Fluent(); 37 | }); 38 | 39 | Blueprint::macro('hasIndex', function (string $index): bool { 40 | return Schema::getConnection() 41 | ->getDoctrineSchemaManager() 42 | ->listTableDetails($this->getTable()) 43 | ->hasIndex($index); 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Schema.php: -------------------------------------------------------------------------------- 1 | connection($name)); 11 | } 12 | 13 | protected static function getFacadeAccessor() 14 | { 15 | self::setCustomGrammar(static::$app["db"]->connection()); 16 | 17 | return "db.schema"; 18 | } 19 | 20 | protected static function setCustomGrammar($connection) 21 | { 22 | if (get_class($connection) === 'Illuminate\Database\PostgresConnection') { 23 | $connection->setSchemaGrammar(app(SchemaGrammar::class)); 24 | } 25 | 26 | return $connection->getSchemaBuilder(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/SchemaGrammar.php: -------------------------------------------------------------------------------- 1 |