From 6fbc1fb4f511604f202ca53e43e6d0260b515176 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sun, 17 May 2026 21:50:24 +0300 Subject: [PATCH] add user migration --- backend/bin/migrate | 46 +++++++++++++++++++ backend/composer.json | 3 +- backend/database/Migration.php | 18 ++++++++ backend/database/UserModel.php | 21 +++++++++ .../2026_05_17_000001_create_users_table.php | 26 +++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100755 backend/bin/migrate create mode 100644 backend/database/Migration.php create mode 100644 backend/database/UserModel.php create mode 100644 backend/database/migrations/2026_05_17_000001_create_users_table.php diff --git a/backend/bin/migrate b/backend/bin/migrate new file mode 100755 index 0000000..98729b2 --- /dev/null +++ b/backend/bin/migrate @@ -0,0 +1,46 @@ +#!/usr/bin/env php +safeLoad(); + + require $root . '/config/database.php'; + + $migrationsDir = $root . '/database/migrations'; + $files = glob($migrationsDir . '/*.php'); + + if ($files === false || $files === []) { + echo "No migration files found.\n"; + exit(0); + } + + sort($files); + + foreach ($files as $file) { + $className = require $file; + + if (! class_exists($className)) { + echo "Migration file {$file} did not define class {$className}\n"; + exit(1); + } + + $migration = new $className(); + + if (! $migration instanceof Migration) { + echo "Class {$className} must extend " . Migration::class . "\n"; + exit(1); + } + + echo "Running {$className}...\n"; + $migration->up(); + } + + echo "Done.\n"; +})(); diff --git a/backend/composer.json b/backend/composer.json index 16119e5..2cbcd56 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -2,7 +2,8 @@ "name": "pilzno/rabbigerzi", "autoload": { "psr-4": { - "App\\": "app/" + "App\\": "app/", + "App\\Database\\": "database/" } }, "autoload-dev": { diff --git a/backend/database/Migration.php b/backend/database/Migration.php new file mode 100644 index 0000000..9e6b286 --- /dev/null +++ b/backend/database/Migration.php @@ -0,0 +1,18 @@ + 'int', + ]; +} diff --git a/backend/database/migrations/2026_05_17_000001_create_users_table.php b/backend/database/migrations/2026_05_17_000001_create_users_table.php new file mode 100644 index 0000000..117da05 --- /dev/null +++ b/backend/database/migrations/2026_05_17_000001_create_users_table.php @@ -0,0 +1,26 @@ +create('users', function ($table) { + $table->increments('id'); + $table->string('email', 255)->unique(); + $table->string('password_hash', 255); + $table->timestamps(); + }); + } + + public function down(): void + { + Capsule::schema()->dropIfExists('users'); + } +} + +return CreateUsersTable::class;