Skip to content

Commit

Permalink
Merge pull request #9435 from EspadaV8/feature/timestampstz
Browse files Browse the repository at this point in the history
[5.1] Add timestampsTz function to schema blueprint
  • Loading branch information
taylorotwell committed Jun 29, 2015
2 parents 1b23623 + cc7ac2b commit 1afb3d1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ public function dropTimestamps()
$this->dropColumn('created_at', 'updated_at');
}

/**
* Indicate that the timestamp columns should be dropped.
*
* @return void
*/
public function dropTimestampsTz()
{
$this->dropTimestamps();
}

/**
* Indicate that the soft delete column should be dropped.
*
Expand Down Expand Up @@ -711,6 +721,18 @@ public function timestamps()
$this->timestamp('updated_at');
}

/**
* Add creation and update timestampTz columns to the table.
*
* @return void
*/
public function timestampsTz()
{
$this->timestampTz('created_at');

$this->timestampTz('updated_at');
}

/**
* Add a "deleted at" timestamp for the table.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ public function testDropTimestamps()
$this->assertEquals('alter table `users` drop `created_at`, drop `updated_at`', $statements[0]);
}

public function testDropTimestampsTz()
{
$blueprint = new Blueprint('users');
$blueprint->dropTimestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table `users` drop `created_at`, drop `updated_at`', $statements[0]);
}

public function testRenameTable()
{
$blueprint = new Blueprint('users');
Expand Down Expand Up @@ -558,6 +568,16 @@ public function testAddingTimeStamps()
$this->assertEquals('alter table `users` add `created_at` timestamp default 0 not null, add `updated_at` timestamp default 0 not null', $statements[0]);
}

public function testAddingTimeStampsTz()
{
$blueprint = new Blueprint('users');
$blueprint->timestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table `users` add `created_at` timestamp default 0 not null, add `updated_at` timestamp default 0 not null', $statements[0]);
}

public function testAddingRememberToken()
{
$blueprint = new Blueprint('users');
Expand Down
20 changes: 20 additions & 0 deletions tests/Database/DatabasePostgresSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ public function testDropTimestamps()
$this->assertEquals('alter table "users" drop column "created_at", drop column "updated_at"', $statements[0]);
}

public function testDropTimestampsTz()
{
$blueprint = new Blueprint('users');
$blueprint->dropTimestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "users" drop column "created_at", drop column "updated_at"', $statements[0]);
}

public function testRenameTable()
{
$blueprint = new Blueprint('users');
Expand Down Expand Up @@ -453,6 +463,16 @@ public function testAddingTimeStamps()
$this->assertEquals('alter table "users" add column "created_at" timestamp(0) without time zone not null, add column "updated_at" timestamp(0) without time zone not null', $statements[0]);
}

public function testAddingTimeStampsTz()
{
$blueprint = new Blueprint('users');
$blueprint->timestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "users" add column "created_at" timestamp(0) with time zone not null, add column "updated_at" timestamp(0) with time zone not null', $statements[0]);
}

public function testAddingBinary()
{
$blueprint = new Blueprint('users');
Expand Down
14 changes: 14 additions & 0 deletions tests/Database/DatabaseSQLiteSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ public function testAddingTimeStamps()
$this->assertEquals($expected, $statements);
}

public function testAddingTimeStampsTz()
{
$blueprint = new Blueprint('users');
$blueprint->timestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(2, count($statements));
$expected = [
'alter table "users" add column "created_at" datetime not null',
'alter table "users" add column "updated_at" datetime not null',
];
$this->assertEquals($expected, $statements);
}

public function testAddingRememberToken()
{
$blueprint = new Blueprint('users');
Expand Down
20 changes: 20 additions & 0 deletions tests/Database/DatabaseSqlServerSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ public function testDropTimestamps()
$this->assertEquals('alter table "users" drop column "created_at", "updated_at"', $statements[0]);
}

public function testDropTimestampsTz()
{
$blueprint = new Blueprint('users');
$blueprint->dropTimestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "users" drop column "created_at", "updated_at"', $statements[0]);
}

public function testRenameTable()
{
$blueprint = new Blueprint('users');
Expand Down Expand Up @@ -422,6 +432,16 @@ public function testAddingTimeStamps()
$this->assertEquals('alter table "users" add "created_at" datetime not null, "updated_at" datetime not null', $statements[0]);
}

public function testAddingTimeStampsTz()
{
$blueprint = new Blueprint('users');
$blueprint->timestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "users" add "created_at" datetimeoffset(0) not null, "updated_at" datetimeoffset(0) not null', $statements[0]);
}

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

0 comments on commit 1afb3d1

Please sign in to comment.