Skip to content

Commit 6bb0021

Browse files
authored
Merge pull request #751 from OpenKnowledgeMaps/database-migration-cleanup
Database migration cleanup
2 parents 7f6973a + 831acde commit 6bb0021

10 files changed

Lines changed: 18 additions & 112 deletions

File tree

local_dev/config_local_headstart.ini

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ services_path = "server/services/"
1717
api_url = "http://proxy-proxy-1/"
1818
# flavor of API, default: stable
1919
api_flavor = "dev"
20-
# The value that is used to determine which db to use: SQLite - 0 or PostgreSQL - 1
21-
shift_read_percentage = 1
2220

2321
[snapshot]
2422
# Set to 1 to enable snapshot feature, 0 to disable
@@ -36,25 +34,6 @@ snapshot_php = "server/services/snapshot/headstart_snapshot.php"
3634
# snapshot_local_protocol fallback for non-server environments
3735
snapshot_local_protocol = "http://"
3836

39-
[output]
40-
# Relative paths for offline calculation
41-
output_dir = "other-scripts/"
42-
cooc = "cooc.csv";
43-
metadata = "metadata.csv"
44-
output_scaling_clustering = "output_scaling_clustering.csv"
45-
output_naming = "output_naming.csv"
46-
unique_id = "vis_id2"
47-
title = "Visualization"
48-
4937
[connection]
50-
# Full path to the sqlite datatabase file. Make sure that your webserver has write access to this file. For development purposes, duplicate headstart.sqlite in server/storage/ and rename it to a filename of your choice. Enter the path to this file here.
51-
sqlite_db = "/var/www/localstorage/local.sqlite"
5238
# PostgreSQL database
53-
database = "dev"
54-
55-
[calculation]
56-
# Path to the RScript binary
57-
binary = "/usr/bin/Rscript"
58-
# Relative path from preprocessing_dir to the R script
59-
script = "other-scripts/text_similarity.R"
60-
mode = "bookmarks"
39+
database = "dev"
-8.95 MB
Binary file not shown.

server/classes/headstart/library/APIClient.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public function load_configs($ini_array) {
1414
$this->ini_array = $ini_array;
1515
$this->settings = $this->ini_array["general"];
1616
$this->database = $this->ini_array["connection"]["database"];
17-
$this->WORKING_DIR = $this->ini_array["general"]["preprocessing_dir"] . $this->ini_array["output"]["output_dir"];
1817
$api_url = $this->ini_array["general"]["api_url"];
1918
$api_flavor = isset($this->ini_array["general"]["api_flavor"])
2019
? ($this->ini_array["general"]["api_flavor"])

server/classes/headstart/persistence/DispatchingPersistence.php

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,118 +2,55 @@
22

33
namespace headstart\persistence;
44

5-
65
/**
76
* This class implements the PersistenceInterface and provides methods to interact with the database.
87
*/
98
class DispatchingPersistence implements Persistence
109
{
11-
private Persistence $oldPersistence;
1210
private Persistence $newPersistence;
13-
private int|float $shiftReadPercentage;
14-
1511

16-
public function __construct(Persistence $oldPersistence, Persistence $newPersistence, $shiftReadPercentage)
12+
public function __construct(Persistence $newPersistence)
1713
{
18-
$this->shiftReadPercentage = $shiftReadPercentage;
19-
$this->oldPersistence = $oldPersistence;
2014
$this->newPersistence = $newPersistence;
2115
}
2216

2317
public function createVisualization($vis_id, $vis_title, $input_json, $query, $dirty_query, $params_json): void
2418
{
25-
$this->oldPersistence->createVisualization($vis_id, $vis_title, $input_json, $query, $dirty_query, $params_json);
2619
$this->newPersistence->createVisualization($vis_id, $vis_title, $input_json, $query, $dirty_query, $params_json);
2720
}
2821

2922
public function getRevision($vis_id, $rev_id): array|bool
3023
{
31-
$randomFloat = getRandomFloat();
32-
33-
if (($randomFloat * 100) > ($this->shiftReadPercentage * 100)) {
34-
$result = $this->oldPersistence->getRevision($vis_id, $rev_id);
35-
} else {
36-
$result = $this->newPersistence->getRevision($vis_id, $rev_id);
37-
}
38-
39-
return $result;
24+
return $this->newPersistence->getRevision($vis_id, $rev_id);
4025
}
4126

4227
public function writeRevision($vis_id, $data): void
4328
{
44-
$this->oldPersistence->writeRevision($vis_id, $data);
4529
$this->newPersistence->writeRevision($vis_id, $data);
4630
}
4731

4832
public function existsVisualization($vis_id): array|bool
4933
{
50-
$randomFloat = getRandomFloat();
51-
52-
if ($randomFloat * 100 > $this->shiftReadPercentage * 100) {
53-
$result = $this->oldPersistence->existsVisualization($vis_id);
54-
} else {
55-
$result = $this->newPersistence->existsVisualization($vis_id);
56-
}
57-
58-
return $result;
34+
return $this->newPersistence->existsVisualization($vis_id);
5935
}
6036

6137
public function getLastVersion($vis_id, $details, $context): array|bool
6238
{
63-
$randomFloat = getRandomFloat();
64-
65-
if ($randomFloat * 100 > $this->shiftReadPercentage * 100) {
66-
$result = $this->oldPersistence->getLastVersion($vis_id, $details, $context);
67-
} else {
68-
$result = $this->newPersistence->getLastVersion($vis_id, $details, $context);
69-
}
70-
71-
return $result;
39+
return $this->newPersistence->getLastVersion($vis_id, $details, $context);
7240
}
7341

7442
public function getLatestRevisions(): array|bool
7543
{
76-
$randomFloat = getRandomFloat();
77-
78-
if ($randomFloat * 100 > $this->shiftReadPercentage * 100) {
79-
$result = $this->oldPersistence->getLatestRevisions();
80-
} else {
81-
$result = $this->newPersistence->getLatestRevisions();
82-
}
83-
84-
return $result;
44+
return $this->newPersistence->getLatestRevisions();
8545
}
8646

8747
public function getContext($vis_id): array|bool
8848
{
89-
$randomFloat = getRandomFloat();
90-
91-
if ($randomFloat * 100 > $this->shiftReadPercentage * 100) {
92-
$result = $this->oldPersistence->getContext($vis_id);
93-
} else {
94-
$result = $this->newPersistence->getContext($vis_id);
95-
}
96-
97-
return $result;
49+
return $this->newPersistence->getContext($vis_id);
9850
}
9951

10052
public function createID($string_array, $payload): string
10153
{
102-
$randomFloat = getRandomFloat();
103-
104-
if ($randomFloat * 100 > $this->shiftReadPercentage * 100) {
105-
$result = $this->oldPersistence->createID($string_array, $payload);
106-
} else {
107-
$result = $this->newPersistence->createID($string_array, $payload);
108-
}
109-
110-
return $result;
54+
return $this->newPersistence->createID($string_array, $payload);
11155
}
11256
}
113-
114-
115-
// function for random float number generation from 0 to 1
116-
function getRandomFloat(): float
117-
{
118-
return mt_rand() / mt_getrandmax();
119-
}

server/classes/headstart/persistence/PostgresPersistence.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace headstart\persistence;
44
use headstart\library\APIClient;
55

6+
require_once 'Persistence.php';
7+
68
/**
79
* This class implements the PersistenceInterface and provides methods to interact with the database.
810
*/
11+
912
class PostgresPersistence implements Persistence
1013
{
1114

@@ -99,4 +102,4 @@ public function createID($string_array, $payload): string
99102

100103
throw new \Exception("Could not create ID, response code was : " . $res["httpcode"]);
101104
}
102-
}
105+
}

server/classes/headstart/persistence/SQLitePersistence.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace headstart\persistence;
44

5+
// ToDo: Remove this file after cleaning all references to it
6+
57
/**
68
* Description of SQLitePersistence
79
*

server/services/getContext.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
header('Content-type: application/json');
44

5-
require dirname(__FILE__) . '/../classes/headstart/persistence/SQLitePersistence.php';
65
require_once dirname(__FILE__) . '/../classes/headstart/persistence/PostgresPersistence.php';
76
require_once dirname(__FILE__) . '/../classes/headstart/persistence/DispatchingPersistence.php';
87
require_once dirname(__FILE__) . '/../classes/headstart/library/CommUtils.php';
@@ -19,10 +18,8 @@
1918
$revision_context = isset($_GET["revision_context"]) ? library\CommUtils::getParameter($_GET, "revision_context") : false;
2019

2120
$apiclient = new headstart\library\APIClient($ini_array);
22-
$sqlitePersistence = new \headstart\persistence\SQLitePersistence($ini_array["connection"]["sqlite_db"]);
2321
$postgresPersistence = new \headstart\persistence\PostgresPersistence($apiclient);
24-
$shiftReadPercentage = $ini_array["general"]["shift_read_percentage"];
25-
$persistence = new \headstart\persistence\DispatchingPersistence($sqlitePersistence, $postgresPersistence, $shiftReadPercentage);
22+
$persistence = new \headstart\persistence\DispatchingPersistence($postgresPersistence);
2623

2724

2825
$data = $persistence->getContext($vis_id)[0];

server/services/getLastVersion.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// connection was interrupted during waiting, and a vis already created
44
header('Content-type: application/json');
55

6-
require dirname(__FILE__) . '/../classes/headstart/persistence/SQLitePersistence.php';
76
require_once dirname(__FILE__) . '/../classes/headstart/persistence/PostgresPersistence.php';
87
require_once dirname(__FILE__) . '/../classes/headstart/persistence/DispatchingPersistence.php';
98
require_once dirname(__FILE__) . '/../classes/headstart/library/CommUtils.php';
@@ -16,10 +15,8 @@
1615

1716
$ini_array = library\Toolkit::loadIni($INI_DIR);
1817
$apiclient = new \headstart\library\APIClient($ini_array);
19-
$sqlitePersistence = new \headstart\persistence\SQLitePersistence($ini_array["connection"]["sqlite_db"]);
2018
$postgresPersistence = new \headstart\persistence\PostgresPersistence($apiclient);
21-
$shiftReadPercentage = $ini_array["general"]["shift_read_percentage"];
22-
$persistence = new \headstart\persistence\DispatchingPersistence($sqlitePersistence, $postgresPersistence, $shiftReadPercentage);
19+
$persistence = new \headstart\persistence\DispatchingPersistence($postgresPersistence);
2320

2421
$vis_id = library\CommUtils::getParameter($_GET, "vis_id");
2522

server/services/getLatestRevision.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
header('Content-type: application/json');
44

55
require dirname(__FILE__) . '/../classes/headstart/preprocessing/calculation/RCalculation.php';
6-
require dirname(__FILE__) . '/../classes/headstart/persistence/SQLitePersistence.php';
76
require dirname(__FILE__) . '/../classes/headstart/persistence/PostgresPersistence.php';
87
require dirname(__FILE__) . '/../classes/headstart/persistence/DispatchingPersistence.php';
98
require_once dirname(__FILE__) . '/../classes/headstart/library/CommUtils.php';
@@ -15,11 +14,8 @@
1514
$INI_DIR = dirname(__FILE__) . "/../preprocessing/conf/";
1615
$ini_array = library\Toolkit::loadIni($INI_DIR);
1716
$apiclient = new \headstart\library\APIClient($ini_array);
18-
//$persistence = new headstart\persistence\SQLitePersistence($ini_array["connection"]["sqlite_db"]);
19-
$sqlitePersistence = new \headstart\persistence\SQLitePersistence($ini_array["connection"]["sqlite_db"]);
2017
$postgresPersistence = new \headstart\persistence\PostgresPersistence($apiclient);
21-
$shiftReadPercentage = $ini_array["general"]["shift_read_percentage"];
22-
$persistence = new \headstart\persistence\DispatchingPersistence($sqlitePersistence, $postgresPersistence, $shiftReadPercentage);
18+
$persistence = new \headstart\persistence\DispatchingPersistence($postgresPersistence);
2319

2420

2521
$vis_id = library\CommUtils::getParameter($_GET, "vis_id");

server/services/search.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
require dirname(__FILE__) . '/../classes/headstart/preprocessing/calculation/RCalculation.php';
4-
require dirname(__FILE__) . '/../classes/headstart/persistence/SQLitePersistence.php';
54
require_once dirname(__FILE__) . '/../classes/headstart/persistence/PostgresPersistence.php';
65
require_once dirname(__FILE__) . '/../classes/headstart/persistence/DispatchingPersistence.php';
76
require_once dirname(__FILE__) . '/../classes/headstart/preprocessing/Snapshot.php';
@@ -74,11 +73,8 @@ function search($service, $dirty_query
7473
? (cleanQuery($dirty_query, $transform_query_tolowercase, $add_slashes))
7574
: ($dirty_query);
7675

77-
// $persistence = new \headstart\persistence\SQLitePersistence($ini_array["connection"]["sqlite_db"]);
78-
$sqlitePersistence = new \headstart\persistence\SQLitePersistence($ini_array["connection"]["sqlite_db"]);
7976
$postgresPersistence = new \headstart\persistence\PostgresPersistence($apiclient);
80-
$shiftReadPercentage = $ini_array["general"]["shift_read_percentage"];
81-
$persistence = new \headstart\persistence\DispatchingPersistence($sqlitePersistence, $postgresPersistence, $shiftReadPercentage);
77+
$persistence = new \headstart\persistence\DispatchingPersistence($postgresPersistence);
8278

8379
// todo: move back into own function once error handling is refactored
8480
if ($service == "openaire") {

0 commit comments

Comments
 (0)