umbrellio / laravel-pg-extensions

Laravel extensions for Postgres
MIT License
92 stars 19 forks source link

Feature/unique wheres #5

Closed pvsaintpe closed 5 years ago

pvsaintpe commented 5 years ago

3

Extending creating unique indexes with conditions on where, example:

Schema::create('cities', static function (Blueprint $table) {
       ... 
       $table->uniquePartial(['name', 'author_id'])
            ->where('editor_id', 1)
            ->whereRaw('field1 = ? and field2 <= ?', ['field1', 'field2'])
            ->whereNotNull('deleted_at')
            ->whereBetween('author_id', [1, 2, 3]);
      ...

PS. If you will use $table->uniquePartial() without extend methods after call uniquePartial(), it works as $table->unique().