From deacd0dfc195bca41af631114804d29937337cd8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 17 Jan 2024 02:11:31 +0900 Subject: . --- services/app/src/Migrations/MigrationManager.php | 248 +++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 services/app/src/Migrations/MigrationManager.php (limited to 'services/app/src/Migrations/MigrationManager.php') diff --git a/services/app/src/Migrations/MigrationManager.php b/services/app/src/Migrations/MigrationManager.php new file mode 100644 index 0000000..88073db --- /dev/null +++ b/services/app/src/Migrations/MigrationManager.php @@ -0,0 +1,248 @@ +conn->transaction(function () { + $version = $this->fetchSchemaVersion(); + while (method_exists($this, "execute$version")) { + $method = "execute$version"; + // @phpstan-ignore-next-line + $this->$method(); + $this->conn + ->query() + ->insert('migrations') + ->values([]) + ->execute(); + $version++; + } + }); + } + + private function fetchSchemaVersion(): int + { + $this->conn->query()->schema(<<conn + ->query() + ->select('migrations') + ->fields(['COALESCE(MAX(migration_id), 0) + 1 AS schema_version']) + ->first() + ->execute(); + assert(isset($result['schema_version'])); + return (int) $result['schema_version']; + } + + /** + * Create the initial schema. + */ + private function execute1(): void + { + $this->conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<conn->query()->schema(<<