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

Make timestamp column names easy to change #90

Merged
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
26 changes: 20 additions & 6 deletions src/Drivers/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class DatabaseDriver implements Driver
*/
protected $unknownFeatureValue;

/**
* The name of the "created at" column.
*
* @var string|null
*/
const CREATED_AT = 'created_at';

/**
* The name of the "updated at" column.
*
* @var string|null
*/
const UPDATED_AT = 'updated_at';

/**
* Create a new driver instance.
*
Expand Down Expand Up @@ -142,8 +156,8 @@ public function getAll($features): array

$this->newQuery()->insert($inserts->map(fn ($insert) => [
...$insert,
'created_at' => $now,
'updated_at' => $now,
static::CREATED_AT => $now,
static::UPDATED_AT => $now,
])->all());
}

Expand Down Expand Up @@ -232,7 +246,7 @@ public function setForAllScopes($feature, $value): void
->where('name', $feature)
->update([
'value' => json_encode($value, flags: JSON_THROW_ON_ERROR),
'updated_at' => Carbon::now(),
static::UPDATED_AT => Carbon::now(),
]);
}

Expand Down Expand Up @@ -260,7 +274,7 @@ protected function update($feature, $scope, $value)
->where('scope', $serialized)
->update([
'value' => json_encode($value, flags: JSON_THROW_ON_ERROR),
'updated_at' => Carbon::now(),
static::UPDATED_AT => Carbon::now(),
]);

return true;
Expand All @@ -280,8 +294,8 @@ protected function insert($feature, $scope, $value)
'name' => $feature,
'scope' => Feature::serializeScope($scope),
'value' => json_encode($value, flags: JSON_THROW_ON_ERROR),
'created_at' => $now = Carbon::now(),
'updated_at' => $now,
static::CREATED_AT => $now = Carbon::now(),
static::UPDATED_AT => $now,
]);
}

Expand Down