Browse Source

feat: skip all old migrations for new installation

M1Screw 1 năm trước cách đây
mục cha
commit
17b1f85da0

+ 15 - 15
composer.json

@@ -14,33 +14,33 @@
         "ext-xml": "*",
         "ext-yaml": "*",
         "ext-zip": "*",
-        "anankke/omnipay-alipay": "^3.1.3",
+        "anankke/omnipay-alipay": "^3",
         "aws/aws-sdk-php": "^3",
         "geoip2/geoip2": "^3",
-        "guzzlehttp/guzzle": "^7.8.1",
-        "guzzlehttp/psr7": "^2.6.2",
-        "illuminate/database": "^10.34.2",
-        "illuminate/pagination": "^10.34.2",
-        "irazasyed/telegram-bot-sdk": "^3.13",
-        "lcobucci/jwt": "^5.2",
-        "league/omnipay": "^3.2.1",
+        "guzzlehttp/guzzle": "^7",
+        "guzzlehttp/psr7": "^2",
+        "illuminate/database": "^10",
+        "illuminate/pagination": "^10",
+        "irazasyed/telegram-bot-sdk": "^3",
+        "lcobucci/jwt": "^5",
+        "league/omnipay": "^3",
         "mailgun/mailgun-php": "^4",
         "nikolaposa/rate-limit": "^3",
         "openai-php/client": "^0",
-        "ozdemir/datatables": "^2.3.7",
-        "phpmailer/phpmailer": "^6.9.1",
+        "ozdemir/datatables": "^2",
+        "phpmailer/phpmailer": "^6",
         "postal/postal": "^2",
-        "ramsey/uuid": "^4.7.5",
+        "ramsey/uuid": "^4",
         "sendgrid/sendgrid": "^8",
         "sentry/sdk": "^4",
-        "slim/http": "^1.3",
+        "slim/http": "^1",
         "slim/slim": "^4",
         "smarty/smarty": "^4",
         "srmklive/paypal": "^3",
         "stripe/stripe-php": "^13",
         "symfony/http-client": "^7",
-        "symfony/translation": "^6",
-        "tronovav/geoip2-update": "^2.3.1",
+        "symfony/translation": "^6|^7",
+        "tronovav/geoip2-update": "^2",
         "twig/twig": "^3",
         "vectorface/googleauthenticator": "^3",
         "voku/anti-xss": "^4"
@@ -60,7 +60,7 @@
     },
     "require-dev": {
         "nunomaduro/phpinsights": "*",
-        "phpunit/phpunit": "^10.5.1"
+        "phpunit/phpunit": "^10|^11"
     },
     "scripts": {
         "update-dev-windows": [

+ 26 - 22
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "dc235d13929ac6d5d47538b637435d7a",
+    "content-hash": "83bf52eacfb53b29ac9e01022e19a0bf",
     "packages": [
         {
             "name": "anankke/omnipay-alipay",
@@ -123,16 +123,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.298.6",
+            "version": "3.298.7",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "0afccba68a96c0cbc10f6fc5b08c5a0e09774220"
+                "reference": "b4d98bfc70df146774bf9b04f5ac5b39955fbad2"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/0afccba68a96c0cbc10f6fc5b08c5a0e09774220",
-                "reference": "0afccba68a96c0cbc10f6fc5b08c5a0e09774220",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/b4d98bfc70df146774bf9b04f5ac5b39955fbad2",
+                "reference": "b4d98bfc70df146774bf9b04f5ac5b39955fbad2",
                 "shasum": ""
             },
             "require": {
@@ -212,9 +212,9 @@
             "support": {
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.298.6"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.298.7"
             },
-            "time": "2024-02-08T19:03:23+00:00"
+            "time": "2024-02-09T19:07:04+00:00"
         },
         {
             "name": "bacon/bacon-qr-code",
@@ -394,26 +394,26 @@
         },
         {
             "name": "carbonphp/carbon-doctrine-types",
-            "version": "3.1.0",
+            "version": "2.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/CarbonPHP/carbon-doctrine-types.git",
-                "reference": "a31d3358a2a5d6ae947df1691d1f321418a5f3d5"
+                "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/a31d3358a2a5d6ae947df1691d1f321418a5f3d5",
-                "reference": "a31d3358a2a5d6ae947df1691d1f321418a5f3d5",
+                "url": "https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/99f76ffa36cce3b70a4a6abce41dba15ca2e84cb",
+                "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb",
                 "shasum": ""
             },
             "require": {
-                "php": "^8.1"
+                "php": "^7.4 || ^8.0"
             },
             "conflict": {
-                "doctrine/dbal": "<4.0.0 || >=5.0.0"
+                "doctrine/dbal": "<3.7.0 || >=4.0.0"
             },
             "require-dev": {
-                "doctrine/dbal": "^4.0.0",
+                "doctrine/dbal": "^3.7.0",
                 "nesbot/carbon": "^2.71.0 || ^3.0.0",
                 "phpunit/phpunit": "^10.3"
             },
@@ -443,7 +443,7 @@
             ],
             "support": {
                 "issues": "https://github.com/CarbonPHP/carbon-doctrine-types/issues",
-                "source": "https://github.com/CarbonPHP/carbon-doctrine-types/tree/3.1.0"
+                "source": "https://github.com/CarbonPHP/carbon-doctrine-types/tree/2.1.0"
             },
             "funding": [
                 {
@@ -459,7 +459,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2023-12-10T15:33:53+00:00"
+            "time": "2023-12-11T17:09:12+00:00"
         },
         {
             "name": "clue/stream-filter",
@@ -1400,20 +1400,20 @@
         },
         {
             "name": "illuminate/database",
-            "version": "v10.38.1",
+            "version": "v10.43.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/database.git",
-                "reference": "55b4633aff7c9fbf1e14bd579835344604fe4d31"
+                "reference": "a98f7b989bc11994e468bb65e3ace45671e5ebce"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/illuminate/database/zipball/55b4633aff7c9fbf1e14bd579835344604fe4d31",
-                "reference": "55b4633aff7c9fbf1e14bd579835344604fe4d31",
+                "url": "https://api.github.com/repos/illuminate/database/zipball/a98f7b989bc11994e468bb65e3ace45671e5ebce",
+                "reference": "a98f7b989bc11994e468bb65e3ace45671e5ebce",
                 "shasum": ""
             },
             "require": {
-                "brick/math": "^0.9.3|^0.10.2|^0.11",
+                "brick/math": "^0.9.3|^0.10.2|^0.11|^0.12",
                 "ext-pdo": "*",
                 "illuminate/collections": "^10.0",
                 "illuminate/container": "^10.0",
@@ -1422,6 +1422,10 @@
                 "illuminate/support": "^10.0",
                 "php": "^8.1"
             },
+            "conflict": {
+                "carbonphp/carbon-doctrine-types": ">=3.0",
+                "doctrine/dbal": ">=4.0"
+            },
             "suggest": {
                 "doctrine/dbal": "Required to rename columns and drop SQLite columns (^3.5.1).",
                 "ext-filter": "Required to use the Postgres database driver.",
@@ -1465,7 +1469,7 @@
                 "issues": "https://github.com/laravel/framework/issues",
                 "source": "https://github.com/laravel/framework"
             },
-            "time": "2023-12-20T14:23:33+00:00"
+            "time": "2024-01-30T15:46:52+00:00"
         },
         {
             "name": "illuminate/macroable",

+ 1 - 2
db/2022.12_to_2022.12.1.sql

@@ -7,5 +7,4 @@ ALTER TABLE detect_log DROP FOREIGN KEY detect_log_ibfk_5;
 ALTER TABLE link DROP FOREIGN KEY link_ibfk_1;
 ALTER TABLE login_ip DROP FOREIGN KEY login_ip_ibfk_1;
 ALTER TABLE paylist DROP FOREIGN KEY paylist_ibfk_1;
-ALTER TABLE user_hourly_usage DROP FOREIGN KEY user_hourly_usage_ibfk_1;
-ALTER TABLE user_invite_code DROP FOREIGN KEY user_invite_code_ibfk_1;
+ALTER TABLE user_invite_code DROP FOREIGN KEY user_invite_code_ibfk_1;

+ 1 - 1
db/migrations/2023020100-init.php

@@ -368,7 +368,7 @@ return new class() implements MigrationInterface {
 
     public function down(): int
     {
-        echo "No reverse operation for initial migration\n";
+        echo 'No reverse operation for initial migration' . PHP_EOL . PHP_EOL;
 
         return 2023020100;
     }

+ 0 - 5
db/migrations/2023061800-update_new_shop_data_type.php

@@ -153,11 +153,6 @@ return new class() implements MigrationInterface {
         ALTER TABLE user_coupon MODIFY COLUMN `use_count` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '累计使用次数';
         ALTER TABLE user_coupon MODIFY COLUMN `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间';
         ALTER TABLE user_coupon MODIFY COLUMN `expire_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '过期时间';
-        ALTER TABLE user_hourly_usage MODIFY COLUMN `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID';
-        ALTER TABLE user_hourly_usage MODIFY COLUMN `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID';
-        ALTER TABLE user_hourly_usage MODIFY COLUMN `traffic` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '当前总流量';
-        ALTER TABLE user_hourly_usage MODIFY COLUMN `hourly_usage` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '过去一小时流量';
-        ALTER TABLE user_hourly_usage MODIFY COLUMN `datetime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '记录时间';
         ALTER TABLE user_invite_code MODIFY COLUMN `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID';
         ALTER TABLE user_invite_code MODIFY COLUMN `code` varchar(255) NOT NULL DEFAULT '' COMMENT '邀请码';
         ALTER TABLE user_invite_code MODIFY COLUMN `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID';

+ 24 - 5
src/Command/Migration.php

@@ -29,13 +29,13 @@ END;
     public function boot(): void
     {
         $reverse = false;
+        $current = 0;
+        $latest = 0;
         $min_version = 0;
         $max_version = 0;
         $target = $this->argv[2] ?? 0;
 
-        if ($target === 'new') {
-            $current = 0;
-        } else {
+        if ($target !== 'new') {
             $current = Config::obtain('db_version');
         }
 
@@ -49,6 +49,7 @@ END;
                 $max_version = PHP_INT_MAX;
             } else {
                 echo 'Database is not empty, do not use "new" as version.' . PHP_EOL;
+
                 return;
             }
         } elseif (is_numeric($target)) {
@@ -64,6 +65,7 @@ END;
             }
         } else {
             echo 'Illegal version argument.' . PHP_EOL;
+
             return;
         }
 
@@ -81,12 +83,20 @@ END;
                 $version = (int) explode('-', $file, 1)[0];
                 echo 'Found migration version ' . $version;
 
-                if ($version <= $min_version || $version > $max_version) {
+                if ($version > $latest) {
+                    $latest = $version;
+                }
+
+                if ($version <= $min_version ||
+                    $version > $max_version ||
+                    ($target === 'new' && $version !== 2023020100)
+                ) {
                     echo '...skip' . PHP_EOL;
                     continue;
                 }
 
                 echo PHP_EOL;
+
                 $object = require_once BASE_PATH . '/db/migrations/' . $file;
 
                 if ($object instanceof MigrationInterface) {
@@ -96,15 +106,18 @@ END;
         }
 
         echo PHP_EOL;
+        echo 'Latest database version ' . $latest . PHP_EOL . PHP_EOL;
 
         if ($reverse) {
             krsort($queue);
+
             foreach ($queue as $version => $object) {
                 echo 'Reverse on ' . $version . PHP_EOL;
                 $current = $object->down();
             }
         } else {
             ksort($queue);
+
             foreach ($queue as $version => $object) {
                 echo 'Forward to ' . $version . PHP_EOL;
                 $current = $object->up();
@@ -118,7 +131,13 @@ END;
         };
 
         $stat = DB::getPdo()->prepare($sql);
-        $stat->execute([$current]);
+
+        if ($target === 'new') {
+            $stat->execute([$latest]);
+        } else {
+            $stat->execute([$current]);
+        }
+
         $count = count($queue);
 
         echo 'Migration completed. ' . $count . ' file(s) processed.' . PHP_EOL