Improved DB + PostgreSQL support

This commit is contained in:
Dmitry Khomutov 2017-01-29 09:49:43 +07:00
commit c90c292629
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
26 changed files with 186 additions and 147 deletions

View file

@ -38,8 +38,8 @@ class BuildErrorStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `build_error` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build_error}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
if ($stmt->execute()) {
@ -62,8 +62,8 @@ class BuildErrorStoreBase extends Store
}
$query = 'SELECT * FROM `build_error` WHERE `build_id` = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':build_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);

View file

@ -38,8 +38,8 @@ class BuildMetaStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `build_meta` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build_meta}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
if ($stmt->execute()) {
@ -62,8 +62,8 @@ class BuildMetaStoreBase extends Store
}
$query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build_meta}} WHERE {{project_id}} = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
@ -94,8 +94,8 @@ class BuildMetaStoreBase extends Store
}
$query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build_meta}} WHERE {{build_id}} = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':build_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);

View file

@ -38,8 +38,8 @@ class BuildStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `build` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
if ($stmt->execute()) {
@ -62,8 +62,8 @@ class BuildStoreBase extends Store
}
$query = 'SELECT * FROM `build` WHERE `project_id` = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build}} WHERE {{project_id}} = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
@ -94,8 +94,8 @@ class BuildStoreBase extends Store
}
$query = 'SELECT * FROM `build` WHERE `status` = :status LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{build}} WHERE {{status}} = :status LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':status', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);

View file

@ -38,8 +38,8 @@ class ProjectGroupStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `project_group` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{project_group}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
if ($stmt->execute()) {

View file

@ -38,8 +38,8 @@ class ProjectStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `project` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{project}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
if ($stmt->execute()) {
@ -62,8 +62,8 @@ class ProjectStoreBase extends Store
}
$query = 'SELECT * FROM `project` WHERE `title` = :title LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{project}} WHERE {{title}} = :title LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':title', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
@ -94,8 +94,8 @@ class ProjectStoreBase extends Store
}
$query = 'SELECT * FROM `project` WHERE `group_id` = :group_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{project}} WHERE {{group_id}} = :group_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':group_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);

View file

@ -38,8 +38,8 @@ class UserStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `user` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{user}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':id', $value);
if ($stmt->execute()) {
@ -67,8 +67,8 @@ class UserStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `user` WHERE `email` = :email LIMIT 1';
$stmt = Database::getConnection()->prepare($query);
$query = 'SELECT * FROM {{user}} WHERE {{email}} = :email LIMIT 1';
$stmt = Database::getConnection()->prepareCommon($query);
$stmt->bindValue(':email', $value);
if ($stmt->execute()) {
@ -96,8 +96,8 @@ class UserStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `user` WHERE `email` = :value OR `name` = :value LIMIT 1';
$stmt = Database::getConnection()->prepare($query);
$query = 'SELECT * FROM {{user}} WHERE {{email}} = :value OR {{name}} = :value LIMIT 1';
$stmt = Database::getConnection()->prepareCommon($query);
$stmt->bindValue(':value', $value);
if ($stmt->execute()) {
@ -119,9 +119,8 @@ class UserStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `user` WHERE `name` = :name LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{user}} WHERE {{name}} = :name LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':name', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);

View file

@ -24,8 +24,7 @@ class BuildErrorStore extends BuildErrorStoreBase
*/
public function getErrorsForBuild($buildId, $since = null)
{
$query = 'SELECT * FROM build_error
WHERE build_id = :build';
$query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build';
if (!is_null($since)) {
$query .= ' AND created_date > :since';
@ -33,7 +32,7 @@ class BuildErrorStore extends BuildErrorStoreBase
$query .= ' LIMIT 15000';
$stmt = Database::getConnection('read')->prepare($query);
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId, \PDO::PARAM_INT);
@ -63,10 +62,10 @@ class BuildErrorStore extends BuildErrorStoreBase
*/
public function getErrorTotalForBuild($buildId)
{
$query = 'SELECT COUNT(*) AS total FROM build_error
WHERE build_id = :build';
$query = 'SELECT COUNT(*) AS {{total}} FROM {{build_error}}
WHERE {{build_id}} = :build';
$stmt = Database::getConnection('read')->prepare($query);
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId, \PDO::PARAM_INT);

View file

@ -28,11 +28,11 @@ class BuildMetaStore extends BuildMetaStoreBase
*/
public function getErrorsForUpgrade($limit)
{
$query = 'SELECT * FROM build_meta
WHERE meta_key IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\', \'technical_debt - data\')
ORDER BY id ASC LIMIT :limit';
$query = 'SELECT * FROM {{build_meta}}
WHERE {{meta_key}} IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\', \'technical_debt - data\')
ORDER BY {{id}} ASC LIMIT :limit';
$stmt = Database::getConnection('read')->prepare($query);
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);

View file

@ -30,12 +30,12 @@ class BuildStore extends BuildStoreBase
public function getLatestBuilds($projectId = null, $limit = 5)
{
if (!is_null($projectId)) {
$query = 'SELECT * FROM build WHERE `project_id` = :pid ORDER BY id DESC LIMIT :limit';
$query = 'SELECT * FROM {{build}} WHERE {{project_id}} = :pid ORDER BY {{id}} DESC LIMIT :limit';
} else {
$query = 'SELECT * FROM build ORDER BY id DESC LIMIT :limit';
$query = 'SELECT * FROM {{build}} ORDER BY {{id}} DESC LIMIT :limit';
}
$stmt = Database::getConnection('read')->prepare($query);
$stmt = Database::getConnection('read')->prepareCommon($query);
if (!is_null($projectId)) {
$stmt->bindValue(':pid', $projectId);
@ -65,8 +65,8 @@ class BuildStore extends BuildStoreBase
*/
public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS)
{
$query = 'SELECT * FROM build WHERE project_id = :pid AND status = :status ORDER BY id DESC LIMIT 1';
$stmt = Database::getConnection('read')->prepare($query);
$query = 'SELECT * FROM {{build}} WHERE {{project_id}} = :pid AND {{status}} = :status ORDER BY {{id}} DESC LIMIT 1';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':pid', $projectId);
$stmt->bindValue(':status', $status);
@ -87,8 +87,8 @@ class BuildStore extends BuildStoreBase
*/
public function getByProjectAndCommit($projectId, $commitId)
{
$query = 'SELECT * FROM `build` WHERE `project_id` = :project_id AND `commit_id` = :commit_id';
$stmt = Database::getConnection('read')->prepare($query);
$query = 'SELECT * FROM {{build}} WHERE {{project_id}} = :project_id AND {{commit_id}} = :commit_id';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':project_id', $projectId);
$stmt->bindValue(':commit_id', $commitId);
@ -116,8 +116,8 @@ class BuildStore extends BuildStoreBase
*/
public function getBuildBranches($projectId)
{
$query = 'SELECT DISTINCT `branch` FROM `build` WHERE `project_id` = :project_id';
$stmt = Database::getConnection('read')->prepare($query);
$query = 'SELECT DISTINCT {{branch}} FROM {{build}} WHERE {{project_id}} = :project_id';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':project_id', $projectId);
if ($stmt->execute()) {
@ -140,8 +140,8 @@ class BuildStore extends BuildStoreBase
public function getMeta($key, $projectId, $buildId = null, $branch = null, $numResults = 1)
{
$query = 'SELECT bm.build_id, bm.meta_key, bm.meta_value
FROM build_meta AS bm
LEFT JOIN build b ON b.id = bm.build_id
FROM {{build_meta}} AS {{bm}}
LEFT JOIN {{build}} AS {{b}} ON b.id = bm.build_id
WHERE bm.meta_key = :key
AND bm.project_id = :projectId';
@ -160,7 +160,7 @@ class BuildStore extends BuildStoreBase
$query .= ' ORDER BY bm.id DESC LIMIT :numResults';
$stmt = Database::getConnection('read')->prepare($query);
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
$stmt->bindValue(':projectId', (int)$projectId, \PDO::PARAM_INT);
$stmt->bindValue(':buildId', (int)$buildId, \PDO::PARAM_INT);
@ -199,10 +199,10 @@ class BuildStore extends BuildStoreBase
*/
public function setMeta($projectId, $buildId, $key, $value)
{
$cols = '`project_id`, `build_id`, `meta_key`, `meta_value`';
$query = 'REPLACE INTO build_meta ('.$cols.') VALUES (:projectId, :buildId, :key, :value)';
$cols = '{{project_id}}, {{build_id}}, {{meta_key}}, {{meta_value}}';
$query = 'INSERT INTO {{build_meta}} ('.$cols.') VALUES (:projectId, :buildId, :key, :value)';
$stmt = Database::getConnection('read')->prepare($query);
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
$stmt->bindValue(':projectId', (int)$projectId, \PDO::PARAM_INT);
$stmt->bindValue(':buildId', (int)$buildId, \PDO::PARAM_INT);

View file

@ -28,8 +28,8 @@ class ProjectStore extends ProjectStoreBase
*/
public function getKnownBranches($projectId)
{
$query = 'SELECT DISTINCT branch from build WHERE project_id = :pid';
$stmt = Database::getConnection('read')->prepare($query);
$query = 'SELECT DISTINCT {{branch}} from {{build}} WHERE {{project_id}} = :pid';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':pid', $projectId);
if ($stmt->execute()) {
@ -57,8 +57,8 @@ class ProjectStore extends ProjectStoreBase
{
$archived = (integer)$archived;
$query = 'SELECT * FROM `project` WHERE `archived` = :archived ORDER BY `title` ASC';
$stmt = Database::getConnection('read')->prepare($query);
$query = 'SELECT * FROM {{project}} WHERE {{archived}} = :archived ORDER BY {{title}} ASC';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':archived', $archived);
@ -98,8 +98,8 @@ class ProjectStore extends ProjectStoreBase
}
$archived = (integer)$archived;
$query = 'SELECT * FROM `project` WHERE `group_id` = :group_id AND `archived` = :archived ORDER BY title LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM {{project}} WHERE {{group_id}} = :group_id AND {{archived}} = :archived ORDER BY {{title}} LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
$stmt->bindValue(':group_id', $value);
$stmt->bindValue(':archived', $archived);