diff --git a/.gitignore b/.gitignore index 65c3736..58075ac 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.debug /config/config.ini /public/robots.txt +/vendor diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 525bff2..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "lib/index"] - path = lib/index - url = https://git.flash.moe/flash/index.git diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..5d3b9b5 --- /dev/null +++ b/composer.json @@ -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 + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..f430525 --- /dev/null +++ b/composer.lock @@ -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" +} diff --git a/database/2023_08_16_161818_existing_structure.php b/database/2023_08_16_161818_existing_structure.php new file mode 100644 index 0000000..2ca7acd --- /dev/null +++ b/database/2023_08_16_161818_existing_structure.php @@ -0,0 +1,46 @@ +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"; + '); + } +} diff --git a/lib/index b/lib/index deleted file mode 160000 index bce5ba7..0000000 --- a/lib/index +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bce5ba77a268ecd6338d0e3520e41ff4c40cbeda diff --git a/mince.php b/mince.php index 90138f0..6c1e9a7 100644 --- a/mince.php +++ b/mince.php @@ -1,7 +1,6 @@ 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'); +} diff --git a/tools/new-migration b/tools/new-migration new file mode 100755 index 0000000..81bc030 --- /dev/null +++ b/tools/new-migration @@ -0,0 +1,21 @@ +#!/usr/bin/env php +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;