Merge remote-tracking branch 'origin/postgres'

This commit is contained in:
GitLab Bot 2022-06-27 16:10:01 +12:00
commit ba3e35cb86
47 changed files with 473 additions and 360 deletions

View file

@ -40,6 +40,7 @@
- Split frontend/backend code into separate repos (https://gitlab.com/goscrobble/goscrobble-web)
- Added new ENV VARS to support unique configurations: DATA_DIRECTORY, FRONTEND_DIRECTORY, API_DOCS_DIRECTORY
- Started API documentation @ /docs (https://goscrobble.com/docs/)
- Added docker-compose file for local development!
# 0.0.33
- Add mod permission

View file

@ -1,5 +1,5 @@
## Timezones
GoScrobble runs as UTC and connects to MySQL as UTC. All timezone handling is done in the frontend.
GoScrobble runs as UTC and connects to postgres as UTC. All timezone handling is done in the frontend.
## FRONTEND VARS
These are stored in `web/.env.production` and `web/.env.development`
@ -8,10 +8,10 @@ These are stored in `web/.env.production` and `web/.env.development`
## BACKEND VARS
MYSQL_HOST= // MySQL Server
MYSQL_USER= // MySQL User
MYSQL_PASS= // MySQL Password
MYSQL_DB= // MySQL Database
POSTGRES_HOST= // postgres Server
POSTGRES_USER= // postgres User
POSTGRES_PASS= // postgres Password
POSTGRES_DB= // postgres Database
REDIS_HOST=127.0.0.1 // Redis host
REDIS_PORT= // Redis port (defaults 6379)

95
docs/migrate.php Normal file
View file

@ -0,0 +1,95 @@
<?php
// Temp script to migrate old data from MySQL to PostgreSQL
// PLEASE RUN ALL MIGRATIONS ON POSTGRES BEFORE RUNNING THIS.
echo PHP_EOL . "Loading connections...";
global $mysqli;
$mysqli = new mysqli('172.27.138.37', 'goscrobble', 'X9u7jdfy', 'goscrobble');
if ($mysqli->connect_errno) {
die("Failed to connect to MySQL");
}
global $postgres;
$postgres = new PDO("pgsql:host=127.0.0.1;port=5432;dbname=goscrobble;user=goscrobble;password=supersecretdatabasepassword1");
function getArray($query): array
{
global $mysqli;
if (!$result = $mysqli->query($query)) {
die($mysqli->error);
}
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
return $data;
}
echo PHP_EOL . "Skipping schema_migrations (Already exists)";
echo PHP_EOL . "Migrating config";
// $config = getArray("SELECT * FROM config");
// $update = $postgres->prepare("UPDATE config SET value = ? WHERE key = ?");
// foreach ($config as $row) {
// $update->execute([
// $row['value'],
// $row['key'],
// ]);
// }
echo PHP_EOL . "Migrating users";
$users = getArray("SELECT
BIN_TO_UUID(uuid, true) as uuid,
created_at,
inet_ntoa(conv(created_ip, 16, 10)) as created_ip,
modified_at,
inet_ntoa(modified_ip) as modified_ip,
username,
password,
email,
verified,
active,
admin,
`mod`,
token,
private,
timezone
FROM users;");
$update = $postgres->prepare("INSERT INTO users (uuid, created_at, created_ip, modified_at, modified_ip, username, password, email, verified, active, admin, mod, token, private, timezone) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
foreach ($users as $row) {
echo PHP_EOL . $row['username'];
$update->execute([
$row['uuid'],
$row['created_at'],
$row['created_ip'],
$row['modified_at'],
$row['modified_ip'],
$row['username'],
$row['password'],
$row['email'],
$row['verified'],
$row['active'],
$row['admin'],
$row['mod'],
$row['token'],
$row['private'],
$row['timezone'],
]);
}
// echo PHP_EOL . "Migrating albums";
// echo PHP_EOL . "Migrating artists";
// echo PHP_EOL . "Migrating tracks";
// echo PHP_EOL . "Migrating genres";
// echo PHP_EOL . "Migrating links";
// echo PHP_EOL . "Migrating oauth_tokens";
// echo PHP_EOL . "Migrating refresh_tokens";
// echo PHP_EOL . "Migrating resettoken";
// echo PHP_EOL . "Migrating album_artist";
// echo PHP_EOL . "Migrating track_album";
// echo PHP_EOL . "Migrating track_artist";
// echo PHP_EOL . "Migrating scrobbles";