Skip to content

Commit

Permalink
Refactored the code and Updated the README
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi-ramawat committed Mar 3, 2017
1 parent 9e27a06 commit 1731f5e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,36 @@ PostgresqlSchema
Add inheritance in postgresql tables

## Installation
[PHP](https://php.net) 5.4+ and [Laravel](http://laravel.com) 5.2+ are required.
[PHP](https://php.net) 5.4+ and [Laravel](https://laravel.com) 5.2+ are required.

To get the latest version of PostgreSQL Schema, simply require `"jumper423/laravel-postgresql-inherit": "2.*"` in your `composer.json` file. You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated.
To get the latest version of PostgreSQL Schema, simply run this command
```shell
composer require "rishi-ramawat/laravel-postgresql-inherit ~2.1"
```

Once PostgreSQL Schema is installed, you need to register the service provider. Open up `app/config/app.php` and add the following to the `providers` key.

* `'ThibaudDauce\PostgresqlSchema\PostgresqlSchemaServiceProvider'`
```php
RishiRamawat\PostgresSchema\PostgresqlSchemaServiceProvider::class
```

## Usage

In migration file when using a postgresql database, you can use the new method `addInheritedTable`:
In migration file when using a postgresql database, you can use the new method `inherits()`:

```php
<?php

Schema::create('test', function(Blueprint $table) {

Schema::create('cities', function(Blueprint $table) {
$table->increments('id');
$table->addInheritedTable('users');
$table->string('name');
$table->double('population');
$table->integer('altitude')->comment('In Feet');
});

Schema::create('capitals', function(Blueprint $table) {
$table->string('state');
// Make capitals table inherits all the columns of its parent table, cities
$table->inherits('cities');
});

```
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jumper423/laravel-postgresql-inherit",
"name": "rishi-ramawat/laravel-postgresql-inherit",
"description": "Add inheritance in postgresql tables",
"license": "MIT",
"keywords": ["laravel", "postgres", "postresql", "database", "migrations", "inheritance"],
Expand All @@ -15,16 +15,16 @@
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.2.*",
"illuminate/database": "5.2.*"
"illuminate/support": "~5.2",
"illuminate/database": "~5.2"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "^5.7"
},
"autoload": {
"psr-4": {
"jumper423\\LaravelDataBase\\": "src/"
"RishiRamawat\\PostgresSchema\\": "src/"
}
},
"minimum-stability": "stable"
Expand Down
4 changes: 2 additions & 2 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace jumper423\LaravelDataBase;
namespace RishiRamawat\PostgresSchema;

use Illuminate\Database\Schema\Blueprint as BaseBlueprint;

Expand Down Expand Up @@ -28,7 +28,7 @@ public function getInheritedTables()
*
* @param string $name
*/
public function addInheritedTable($name)
public function inherits($name)
{
$this->inheritedTables[] = $name;
}
Expand Down
3 changes: 2 additions & 1 deletion src/PostgresConnection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace jumper423\LaravelDataBase;
namespace RishiRamawat\PostgresSchema;

use Illuminate\Database\PostgresConnection as BasePostgresConnection;

Expand All @@ -27,6 +27,7 @@ public function getSchemaBuilder()
$builder->blueprintResolver(function ($table, $callback) {
return new Blueprint($table, $callback);
});

return $builder;
}
}
13 changes: 8 additions & 5 deletions src/PostgresGrammar.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace jumper423\LaravelDataBase;
namespace RishiRamawat\PostgresSchema;

use Illuminate\Database\Schema\Grammars\PostgresGrammar as BasePostgresGrammar;
use Illuminate\Support\Fluent;
Expand All @@ -19,11 +19,12 @@ public function compileCreate(BaseBlueprint $blueprint, Fluent $command)
{
$inheritedTables = implode(', ', $this->getInheritedTables($blueprint));
$sql = parent::compileCreate($blueprint, $command);
if (empty($inheritedTables)) {
return $sql;
} else {
return $sql . " inherits ($inheritedTables)";

if (!empty($inheritedTables)) {
return $sql . " inherits ({$inheritedTables})";
}

return $sql;
}

/**
Expand All @@ -35,10 +36,12 @@ public function compileCreate(BaseBlueprint $blueprint, Fluent $command)
protected function getInheritedTables(BaseBlueprint $blueprint)
{
$tables = [];

foreach ($blueprint->getInheritedTables() as $table) {
//$sql = $this->wrapTable($table);
$tables[] = $table;
}

return $tables;
}
}
12 changes: 1 addition & 11 deletions src/PostgresqlSchemaServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace jumper423\LaravelDataBase;
namespace RishiRamawat\PostgresSchema;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application as App;
Expand All @@ -14,16 +14,6 @@ class PostgresqlSchemaServiceProvider extends ServiceProvider
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
//$this->package('thibaud-dauce/postgresql-schema');
}

/**
* Register the service provider.
*
Expand Down

0 comments on commit 1731f5e

Please sign in to comment.