Use Composer for Index package.
This commit is contained in:
parent
b8437791d6
commit
e5f3ee9d99
9 changed files with 196 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@
|
|||
/.debug
|
||||
/config/config.ini
|
||||
/public/robots.txt
|
||||
/vendor
|
||||
|
|
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "lib/index"]
|
||||
path = lib/index
|
||||
url = https://git.flash.moe/flash/index.git
|
26
composer.json
Normal file
26
composer.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"flashwave/index": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"database"
|
||||
],
|
||||
"psr-4": {
|
||||
"Mince\\": "src"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-install-cmd": [
|
||||
"./tools/migrate"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist",
|
||||
"allow-plugins": {
|
||||
"composer/installers": true
|
||||
}
|
||||
}
|
||||
}
|
65
composer.lock
generated
Normal file
65
composer.lock
generated
Normal file
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "11f8c90aff3c23a448844cee09bcd23c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "flashwave/index",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.flash.moe/flash/index.git",
|
||||
"reference": "553b7c4a14aa7f2403c87ce474933986ac17d040"
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpunit/phpunit": "^10.2"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mysqli": "Support for the Index\\Data\\MariaDB namespace (both mysqlnd and libmysql are supported).",
|
||||
"ext-sqlite3": "Support for the Index\\Data\\SQLite namespace."
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"index.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Index\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"bsd-3-clause-clear"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "flashwave",
|
||||
"email": "packagist@flash.moe",
|
||||
"homepage": "https://flash.moe",
|
||||
"role": "mom"
|
||||
}
|
||||
],
|
||||
"description": "Composer package for the common library for my projects.",
|
||||
"homepage": "https://railgun.sh/index",
|
||||
"time": "2023-08-03T01:29:57+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
46
database/2023_08_16_161818_existing_structure.php
Normal file
46
database/2023_08_16_161818_existing_structure.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
use Index\Data\IDbConnection;
|
||||
use Index\Data\Migration\IDbMigration;
|
||||
|
||||
final class ExistingStructure_20230816_161818 implements IDbMigration {
|
||||
public function migrate(IDbConnection $conn): void {
|
||||
$hasWhiteList2020 = false;
|
||||
$hasWhiteList2022 = false;
|
||||
|
||||
// check if the old tables exist
|
||||
$tables = $conn->query('SHOW TABLES');
|
||||
while($tables->next()) {
|
||||
$tableName = $tables->getString(0);
|
||||
if($tableName === 'whitelist')
|
||||
$hasWhiteList2020 = true;
|
||||
elseif($tableName === 'whitelist_2022')
|
||||
$hasWhiteList2022 = true;
|
||||
if($hasWhiteList2020 && $hasWhiteList2022)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!$hasWhiteList2020)
|
||||
$conn->execute('
|
||||
CREATE TABLE whitelist (
|
||||
flashii_id INT(10) UNSIGNED NOT NULL,
|
||||
minecraft_username VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_ci",
|
||||
whitelist_added TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
||||
UNIQUE KEY whitelist_unique (flashii_id, minecraft_username),
|
||||
KEY whitelist_flashii_key (flashii_id),
|
||||
KEY whitelist_minecraft_key (minecraft_username)
|
||||
) ENGINE=InnoDB COLLATE="latin1_swedish_ci";
|
||||
');
|
||||
|
||||
if(!$hasWhiteList2022)
|
||||
$conn->execute('
|
||||
CREATE TABLE whitelist_2022 (
|
||||
flashii_id INT(10) UNSIGNED NOT NULL,
|
||||
minecraft_username VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_ci",
|
||||
whitelist_added TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
||||
UNIQUE KEY whitelist_2022_unique (flashii_id, minecraft_username),
|
||||
KEY whitelist_2022_flashii_key (flashii_id),
|
||||
KEY whitelist_2022_minecraft_key (minecraft_username)
|
||||
) ENGINE=InnoDB COLLATE="latin1_swedish_ci";
|
||||
');
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
Subproject commit bce5ba77a268ecd6338d0e3520e41ff4c40cbeda
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
namespace Mince;
|
||||
|
||||
use Index\Autoloader;
|
||||
use Index\Environment;
|
||||
use Index\XString;
|
||||
use Index\Data\ConnectionFailedException;
|
||||
|
@ -11,14 +10,13 @@ define('MCR_STARTUP', microtime(true));
|
|||
define('MCR_ROOT', __DIR__);
|
||||
define('MCR_DEBUG', is_file(MCR_ROOT . '/.debug'));
|
||||
define('MCR_DIR_SRC', MCR_ROOT . '/src');
|
||||
define('MCR_DIR_LIB', MCR_ROOT . '/lib');
|
||||
define('MCR_DIR_PUB', MCR_ROOT . '/public');
|
||||
define('MCR_DIR_PRV', MCR_ROOT . '/private');
|
||||
define('MCR_DIR_CFG', MCR_ROOT . '/config');
|
||||
define('MCR_DIR_MIG', MCR_ROOT . '/database');
|
||||
|
||||
require_once MCR_DIR_LIB . '/index/index.php';
|
||||
require_once MCR_ROOT . '/vendor/autoload.php';
|
||||
|
||||
Autoloader::addNamespace(__NAMESPACE__, MCR_DIR_SRC);
|
||||
Environment::setDebug(MCR_DEBUG);
|
||||
|
||||
$config = parse_ini_file(MCR_DIR_CFG . '/config.ini');
|
||||
|
|
35
tools/migrate
Executable file
35
tools/migrate
Executable file
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
use Index\Data\Migration\DbMigrationManager;
|
||||
use Index\Data\Migration\FsDbMigrationRepo;
|
||||
|
||||
require_once __DIR__ . '/../mince.php';
|
||||
|
||||
try {
|
||||
touch(MCR_ROOT . '/.migrating');
|
||||
chmod(MCR_ROOT . '/.migrating', 0777);
|
||||
|
||||
echo 'Creating migration manager...' . PHP_EOL;
|
||||
$manager = new DbMigrationManager($db);
|
||||
|
||||
echo 'Preparing to run migrations...' . PHP_EOL;
|
||||
$manager->init();
|
||||
|
||||
echo 'Creating migration repository...' . PHP_EOL;
|
||||
$repo = new FsDbMigrationRepo(MCR_DIR_MIG);
|
||||
|
||||
echo 'Running migrations...' . PHP_EOL;
|
||||
$completed = $manager->processMigrations($repo);
|
||||
|
||||
if(empty($completed)) {
|
||||
echo 'There were no migrations to run!' . PHP_EOL;
|
||||
} else {
|
||||
echo 'The following migrations have been completed:' . PHP_EOL;
|
||||
foreach($completed as $migration)
|
||||
echo ' - ' . $migration . PHP_EOL;
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
} finally {
|
||||
unlink(MCR_ROOT . '/.migrating');
|
||||
}
|
21
tools/new-migration
Executable file
21
tools/new-migration
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
use Index\Data\Migration\DbMigrationManager;
|
||||
use Index\Data\Migration\FsDbMigrationRepo;
|
||||
|
||||
require_once __DIR__ . '/../mince.php';
|
||||
|
||||
$repo = new FsDbMigrationRepo(MCR_DIR_MIG);
|
||||
$baseName = implode(' ', array_slice($argv, 1));
|
||||
$manager = new DbMigrationManager($db);
|
||||
|
||||
try {
|
||||
$names = $manager->createNames($baseName);
|
||||
} catch(InvalidArgumentException $ex) {
|
||||
echo $ex->getMessage() . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
$repo->saveMigrationTemplate($names->name, $manager->template($names->className));
|
||||
|
||||
echo "Template for '{$names->className}' has been saved to {$names->name}.php." . PHP_EOL;
|
Loading…
Reference in a new issue