{"id":19133982,"url":"https://github.com/umbrellio/laravel-pg-extensions","last_synced_at":"2025-05-16T00:06:28.358Z","repository":{"id":43678501,"uuid":"188449743","full_name":"umbrellio/laravel-pg-extensions","owner":"umbrellio","description":"Laravel extensions for Postgres ","archived":false,"fork":false,"pushed_at":"2025-03-05T10:18:19.000Z","size":386,"stargazers_count":96,"open_issues_count":5,"forks_count":20,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-19T03:07:39.236Z","etag":null,"topics":["database","extensions","laravel","postgresql"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/umbrellio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-24T15:52:24.000Z","updated_at":"2025-04-18T16:37:57.000Z","dependencies_parsed_at":"2024-05-01T23:53:18.009Z","dependency_job_id":"f0cb0c68-799d-4740-904b-495c83bac929","html_url":"https://github.com/umbrellio/laravel-pg-extensions","commit_stats":{"total_commits":83,"total_committers":13,"mean_commits":6.384615384615385,"dds":0.3975903614457831,"last_synced_commit":"d96bf4bfb982ec7b237b6abd4300cc9bdee68553"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Flaravel-pg-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Flaravel-pg-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Flaravel-pg-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Flaravel-pg-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umbrellio","download_url":"https://codeload.github.com/umbrellio/laravel-pg-extensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442854,"owners_count":22071878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","extensions","laravel","postgresql"],"created_at":"2024-11-09T06:24:37.807Z","updated_at":"2025-05-16T00:06:28.332Z","avatar_url":"https://github.com/umbrellio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel PG extensions\n\n[![Github Status](https://github.com/umbrellio/laravel-pg-extensions/workflows/CI/badge.svg)](https://github.com/umbrellio/laravel-pg-extensions/actions)\n[![Coverage Status](https://coveralls.io/repos/github/umbrellio/laravel-pg-extensions/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/laravel-pg-extensions?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/umbrellio/laravel-pg-extensions/v/stable.png)](https://packagist.org/packages/umbrellio/laravel-pg-extensions)\n[![Total Downloads](https://poser.pugx.org/umbrellio/laravel-pg-extensions/downloads.png)](https://packagist.org/packages/umbrellio/laravel-pg-extensions)\n[![Code Intelligence Status](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)\n[![Build Status](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/badges/build.png?b=master)](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/build-status/master)\n[![Code Coverage](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/?branch=master)\n\nThis project extends Laravel's database layer to allow use specific Postgres features without raw queries. \n\n## Installation\n\nRun this command to install:\n```bash\ncomposer require umbrellio/laravel-pg-extensions\n```\n\n## Features\n\n - [Extended `Schema::create()`](#extended-table-creation)\n - [Added Support NUMERIC Type](#numeric-column-type)\n - [Extended `Schema` with USING](#extended-schema-using)\n - [Extended `Schema` for views](#create-views)\n - [Working with UNIQUE indexes](#extended-unique-indexes-creation)\n - [Working with EXCLUDE constraints](#exclude-constraints-creation)\n - [Working with CHECK constraints](#check-constraints-creation)\n - [Working with partitions](#partitions)\n - [Check existing index before manipulation](#check-existing-index)\n - [Getting foreign keys for table](#get-foreign-keys)\n\n### Extended table creation\n\nExample:\n```php\nSchema::create('table', function (Blueprint $table) {\n    $table-\u003elike('other_table')-\u003eincludingAll(); \n    $table-\u003eifNotExists();\n});\n```\n\n### Extended Schema USING\n\nExample:\n```php\nSchema::create('table', function (Blueprint $table) {\n    $table-\u003einteger('number');\n});\n\n//modifications with data...\n\nSchema::table('table', function (Blueprint $table) {\n    $table\n        -\u003estring('number')\n        -\u003eusing(\"('[' || number || ']')::character varying\")\n        -\u003echange();\n});\n```\n\n### Create views\n\nExample:\n```php\n// Facade methods:\nSchema::createView('active_users', \"SELECT * FROM users WHERE active = 1\");\nSchema::dropView('active_users')\n\n// Schema methods:\nSchema::create('users', function (Blueprint $table) {\n    $table\n        -\u003ecreateView('active_users', \"SELECT * FROM users WHERE active = 1\")\n        -\u003ematerialize();\n});\n```\n\n### Get foreign keys\n\nExample:\n```php\n// Facade methods:\n/** @var ForeignKeyDefinition[] $fks */\n$fks = Schema::getForeignKeys('some_table');\n\nforeach ($fks as $fk) {\n    // $fk-\u003esource_column_name\n    // $fk-\u003etarget_table_name\n    // $fk-\u003etarget_column_name\n}\n```\n\n### Extended unique indexes creation\n\nExample:\n```php\nSchema::create('table', function (Blueprint $table) {\n    $table-\u003estring('code'); \n    $table-\u003esoftDeletes();\n    $table-\u003euniquePartial('code')-\u003ewhereNull('deleted_at');\n});\n```\n\nIf you want to delete partial unique index, use this method:\n```php\nSchema::create('table', function (Blueprint $table) {\n    $table-\u003edropUniquePartial(['code']);\n});\n```\n\n`$table-\u003edropUnique()` doesn't work for Partial Unique Indexes, because PostgreSQL doesn't\ndefine a partial (ie conditional) UNIQUE constraint. If you try to delete such a Partial Unique\nIndex you will get an error.\n\n```SQL\nCREATE UNIQUE INDEX CONCURRENTLY examples_new_col_idx ON examples (new_col);\nALTER TABLE examples\n    ADD CONSTRAINT examples_unique_constraint USING INDEX examples_new_col_idx;\n```\n\nWhen you create a unique index without conditions, PostgresSQL will create Unique Constraint\nautomatically for you, and when you try to delete such an index, Constraint will be deleted \nfirst, then Unique Index. \n\n### Exclude constraints creation\n\nUsing the example below:\n```php\nSchema::create('table', function (Blueprint $table) {\n    $table-\u003einteger('type_id'); \n    $table-\u003edate('date_start'); \n    $table-\u003edate('date_end'); \n    $table-\u003esoftDeletes();\n    $table\n        -\u003eexclude(['date_start', 'date_end'])\n        -\u003eusing('type_id', '=')\n        -\u003eusing('daterange(date_start, date_end)', '\u0026\u0026')\n        -\u003emethod('gist')\n        -\u003ewith('some_arg', 1)\n        -\u003ewith('any_arg', 'some_value')\n        -\u003ewhereNull('deleted_at');\n});\n```\n\nAn Exclude Constraint will be generated for your table:\n```SQL\nALTER TABLE test_table\n    ADD CONSTRAINT test_table_date_start_date_end_excl\n        EXCLUDE USING gist (type_id WITH =, daterange(date_start, date_end) WITH \u0026\u0026)\n        WITH (some_arg = 1, any_arg = 'some_value')\n        WHERE (\"deleted_at\" is null)\n```\n\n### Check constraints creation\n\nUsing the example below:\n```php\nSchema::create('table', function (Blueprint $table) {\n    $table-\u003einteger('type_id'); \n    $table-\u003edate('date_start'); \n    $table-\u003edate('date_end'); \n    $table\n        -\u003echeck(['date_start', 'date_end'])\n        -\u003ewhereColumn('date_end', '\u003e', 'date_start')\n        -\u003ewhereIn('type_id', [1, 2, 3]);\n});\n```\n\nAn Check Constraint will be generated for your table:\n```SQL\nALTER TABLE test_table\n    ADD CONSTRAINT test_table_date_start_date_end_chk\n        CHECK (\"date_end\" \u003e \"date_start\" AND \"type_id\" IN [1, 2, 3])\n```\n\n### Partitions\n\nSupport for attaching and detaching partitions.\n\nExample:\n```php\nSchema::table('table', function (Blueprint $table) {\n    $table-\u003eattachPartition('partition')-\u003erange([\n        'from' =\u003e now()-\u003estartOfDay(), // Carbon will be converted to date time string\n        'to' =\u003e now()-\u003etomorrow(),\n    ]);\n});\n```\n\n### Check existing index\n\n```php\nSchema::table('some_table', function (Blueprint $table) {\n   // check unique index exists on column\n   if ($table-\u003ehasIndex(['column'], true)) {\n      $table-\u003edropUnique(['column']);\n   }\n   $table-\u003euniquePartial('column')-\u003ewhereNull('deleted_at');\n});\n```\n\n### Numeric column type\nUnlike standard laravel `decimal` type, this type can be with [variable precision](https://www.postgresql.org/docs/current/datatype-numeric.html) \n```php\nSchema::table('some_table', function (Blueprint $table) {\n   $table-\u003enumeric('column_with_variable_precision');\n   $table-\u003enumeric('column_with_defined_precision', 8);\n   $table-\u003enumeric('column_with_defined_precision_and_scale', 8, 2);\n});\n```\n\n## Custom Extensions\n\n1). Create a repository for your extension.\n\n2). Add this package as a dependency in composer.\n\n3). Inherit the classes you intend to extend from abstract classes with namespace: `namespace Umbrellio\\Postgres\\Extensions`\n\n4). Implement extension methods in closures, example:\n\n```php\nuse Umbrellio\\Postgres\\Extensions\\Schema\\AbstractBlueprint;\nclass SomeBlueprint extends AbstractBlueprint\n{\n   public function someMethod()\n   {\n       return function (string $column): Fluent {\n           return $this-\u003eaddColumn('someColumn', $column);\n       };\n   }\n}\n```\n\n5). Create Extension class and mix these methods using the following syntax, ex:\n\n```php\nuse Umbrellio\\Postgres\\PostgresConnection;\nuse Umbrellio\\Postgres\\Schema\\Blueprint;\nuse Umbrellio\\Postgres\\Schema\\Grammars\\PostgresGrammar;\nuse Umbrellio\\Postgres\\Extensions\\AbstractExtension;\n\nclass SomeExtension extends AbstractExtension\n{\n    public static function getMixins(): array\n    {\n        return [\n            SomeBlueprint::class =\u003e Blueprint::class,\n            SomeConnection::class =\u003e PostgresConnection::class,\n            SomeSchemaGrammar::class =\u003e PostgresGrammar::class,\n            ...\n        ];\n    }\n    \n    public static function getTypes(): string\n    {\n        // where SomeType extends Doctrine\\DBAL\\Types\\Type\n        return [\n            'some' =\u003e SomeType::class,\n        ];\n    }\n\n    public static function getName(): string\n    {\n        return 'some';\n    }\n}\n```\n\n6). Register your Extension in ServiceProvider and put in config/app.php, ex:\n\n```php\nuse Illuminate\\Support\\ServiceProvider;\nuse Umbrellio\\Postgres\\PostgresConnection;\n\nclass SomeServiceProvider extends ServiceProvider\n{\n    public function register(): void\n    {\n        PostgresConnection::registerExtension(SomeExtension::class);\n    }\n}\n```\n\n## TODO features\n\n - Extend `CreateCommand` with `inherits` and `partition by`\n - Extend working with partitions\n - COPY support\n - DISTINCT on specific columns\n - INSERT ON CONFLICT support\n - ...\n \n## License\n\nReleased under MIT License.\n\n## Authors\n\nCreated by Vitaliy Lazeev \u0026 Korben Dallas.\n\n## Contributing\n\n- Fork it ( https://github.com/umbrellio/laravel-pg-extensions )\n- Create your feature branch (`git checkout -b feature/my-new-feature`)\n- Commit your changes (`git commit -am 'Add some feature'`)\n- Push to the branch (`git push origin feature/my-new-feature`)\n- Create new Pull Request\n\n\u003ca href=\"https://github.com/umbrellio/\"\u003e\n\u003cimg style=\"float: left;\" src=\"https://umbrellio.github.io/Umbrellio/supported_by_umbrellio.svg\" alt=\"Supported by Umbrellio\" width=\"439\" height=\"72\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumbrellio%2Flaravel-pg-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumbrellio%2Flaravel-pg-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumbrellio%2Flaravel-pg-extensions/lists"}