Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Postgresql column precision declaration fix #29873

Merged
merged 2 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ protected function typeDateTimeTz(Fluent $column)
*/
protected function typeTime(Fluent $column)
{
return "time($column->precision) without time zone";
return 'time'.(is_null($column->precision) ? '' : "($column->precision)").' without time zone';
}

/**
Expand All @@ -696,7 +696,7 @@ protected function typeTime(Fluent $column)
*/
protected function typeTimeTz(Fluent $column)
{
return "time($column->precision) with time zone";
return 'time'.(is_null($column->precision) ? '' : "($column->precision)").' with time zone';
}

/**
Expand All @@ -707,7 +707,7 @@ protected function typeTimeTz(Fluent $column)
*/
protected function typeTimestamp(Fluent $column)
{
$columnType = "timestamp($column->precision) without time zone";
$columnType = 'timestamp'.(is_null($column->precision) ? '' : "($column->precision)").' without time zone';

return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
Expand All @@ -720,7 +720,7 @@ protected function typeTimestamp(Fluent $column)
*/
protected function typeTimestampTz(Fluent $column)
{
$columnType = "timestamp($column->precision) with time zone";
$columnType = 'timestamp'.(is_null($column->precision) ? '' : "($column->precision)").' with time zone';

return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
Expand Down
54 changes: 54 additions & 0 deletions tests/Database/DatabasePostgresSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,15 @@ public function testAddingDateTimeWithPrecision()
$this->assertSame('alter table "users" add column "created_at" timestamp(1) without time zone not null', $statements[0]);
}

public function testAddingDateTimeWithNullPrecision()
{
$blueprint = new Blueprint('users');
$blueprint->dateTime('created_at', null);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add column "created_at" timestamp without time zone not null', $statements[0]);
}

public function testAddingDateTimeTz()
{
$blueprint = new Blueprint('users');
Expand All @@ -551,6 +560,15 @@ public function testAddingDateTimeTzWithPrecision()
$this->assertSame('alter table "users" add column "created_at" timestamp(1) with time zone not null', $statements[0]);
}

public function testAddingDateTimeTzWithNullPrecision()
{
$blueprint = new Blueprint('users');
$blueprint->dateTimeTz('created_at', null);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add column "created_at" timestamp with time zone not null', $statements[0]);
}

public function testAddingTime()
{
$blueprint = new Blueprint('users');
Expand All @@ -569,6 +587,15 @@ public function testAddingTimeWithPrecision()
$this->assertSame('alter table "users" add column "created_at" time(1) without time zone not null', $statements[0]);
}

public function testAddingTimeWithNullPrecision()
{
$blueprint = new Blueprint('users');
$blueprint->time('created_at', null);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add column "created_at" time without time zone not null', $statements[0]);
}

public function testAddingTimeTz()
{
$blueprint = new Blueprint('users');
Expand All @@ -587,6 +614,15 @@ public function testAddingTimeTzWithPrecision()
$this->assertSame('alter table "users" add column "created_at" time(1) with time zone not null', $statements[0]);
}

public function testAddingTimeTzWithNullPrecision()
{
$blueprint = new Blueprint('users');
$blueprint->timeTz('created_at', null);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add column "created_at" time with time zone not null', $statements[0]);
}

public function testAddingTimestamp()
{
$blueprint = new Blueprint('users');
Expand All @@ -605,6 +641,15 @@ public function testAddingTimestampWithPrecision()
$this->assertSame('alter table "users" add column "created_at" timestamp(1) without time zone not null', $statements[0]);
}

public function testAddingTimestampWithNullPrecision()
{
$blueprint = new Blueprint('users');
$blueprint->timestamp('created_at', null);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add column "created_at" timestamp without time zone not null', $statements[0]);
}

public function testAddingTimestampTz()
{
$blueprint = new Blueprint('users');
Expand All @@ -623,6 +668,15 @@ public function testAddingTimestampTzWithPrecision()
$this->assertSame('alter table "users" add column "created_at" timestamp(1) with time zone not null', $statements[0]);
}

public function testAddingTimestampTzWithNullPrecision()
{
$blueprint = new Blueprint('users');
$blueprint->timestampTz('created_at', null);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add column "created_at" timestamp with time zone not null', $statements[0]);
}

public function testAddingTimestamps()
{
$blueprint = new Blueprint('users');
Expand Down