{"id":26102481,"url":"https://github.com/babarbilal56/core-php-db-migration","last_synced_at":"2026-04-13T18:01:46.837Z","repository":{"id":281408575,"uuid":"944094551","full_name":"babarbilal56/core-php-db-migration","owner":"babarbilal56","description":"This script provides a simple migration system using PHP and MySQL. It allows applying and rolling back database migrations efficiently.","archived":false,"fork":false,"pushed_at":"2025-03-08T21:29:46.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-14T12:43:06.266Z","etag":null,"topics":["database","database-migrations","mysql","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/babarbilal56.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-06T19:21:39.000Z","updated_at":"2025-06-03T22:01:57.000Z","dependencies_parsed_at":"2025-03-08T22:34:18.339Z","dependency_job_id":null,"html_url":"https://github.com/babarbilal56/core-php-db-migration","commit_stats":null,"previous_names":["babarbilal56/core-php-db-migration"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/babarbilal56/core-php-db-migration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarbilal56%2Fcore-php-db-migration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarbilal56%2Fcore-php-db-migration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarbilal56%2Fcore-php-db-migration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarbilal56%2Fcore-php-db-migration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babarbilal56","download_url":"https://codeload.github.com/babarbilal56/core-php-db-migration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babarbilal56%2Fcore-php-db-migration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31764317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T15:25:13.801Z","status":"ssl_error","status_checked_at":"2026-04-13T15:25:09.162Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","database-migrations","mysql","php"],"created_at":"2025-03-09T19:41:46.996Z","updated_at":"2026-04-13T18:01:46.812Z","avatar_url":"https://github.com/babarbilal56.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Database Migration\n\nThis script provides a simple migration system using PHP and MySQL. It allows applying and rolling back database migrations efficiently.\n\n## 📌 Features\n- **Automatic migration tracking** using a `migrations` table.\n- **Prevents duplicate migrations** by checking if a migration has already been applied.\n- **Supports rollback of the last migration** or **all migrations**.\n- **Runs specific migrations** if needed.\n\n---\n\n## 🛠️ Setup Instructions\n\n### 1️⃣ **Clone the Repository \u0026 Configure Database**\nEnsure you have a `config.php` file with database credentials:\n```php\n// config.php\ndefine('DB_HOST', 'localhost');\ndefine('DB_USER', 'your_username');\ndefine('DB_PASSWORD', 'your_password');\ndefine('DB_NAME', 'your_database');\n```\n\n### 2️⃣ **Create the Migrations Folder**\nEnsure there is a `migrations` directory in the project root:\n```sh\nmkdir migrations\n```\n\n### 3️⃣ **Write a Migration File**\nCreate a PHP file inside `migrations/` (e.g., `2025_03_09_001_test.php`):\n```php\n\u003c?php\nclass Migration_2025_03_09_001_test\n{\n    public function up($pdo)\n    {\n        $sql = \"CREATE TABLE IF NOT EXISTS test_migration (\n                    id INT AUTO_INCREMENT PRIMARY KEY,\n                    description VARCHAR(255) NOT NULL,\n                    created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n                )\";\n        $pdo-\u003eexec($sql);\n        echo \"Migration applied successfully.\\n\";\n    }\n\n    public function down($pdo)\n    {\n        $sql = \"DROP TABLE IF EXISTS test_migration\";\n        $pdo-\u003eexec($sql);\n        echo \"Migration rolled back.\\n\";\n    }\n}\n```\n\n---\n\n## 🚀 Running Migrations\n\n### ✅ **Run All Pending Migrations**\n```sh\nphp migrate.php\n```\n\u003e This applies all migrations that haven't been executed yet.\n\n### 🎯 **Run a Specific Migration**\n```sh\nphp migrate.php 2025_03_09_001_test.php\n```\n\u003e This applies only the specified migration file if it hasn’t been applied yet.\n\n### ⏪ **Rollback the Last Migration**\n```sh\nphp migrate.php rollback\n```\n\u003e This rolls back **only the most recent migration**.\n\n### ⏪ **Rollback All Migrations**\n```sh\nphp migrate.php rollback all\n```\n\u003e This rolls back **all applied migrations** in reverse order.\n\n---\n\n## 📌 How It Works\n1. **Migration History Tracking**\n   - Applied migrations are stored in a `migrations` table to prevent duplicate execution.\n2. **Automatic Sorting**\n   - Migrations are run in ascending order based on filename.\n3. **Rollback System**\n   - Only executed migrations are rolled back based on the tracking table.\n4. **Error Handling**\n   - Ensures missing classes or duplicate execution do not break the process.\n\n---\n\n## 📌 Notes\n- **Migrations must follow the naming convention**: `YYYY_MM_DD_XXX_description.php`\n- Each migration file **must contain a class** named `Migration_YYYY_MM_DD_XXX_description`.\n- **Always test migrations in a development environment** before applying them in production.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabarbilal56%2Fcore-php-db-migration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabarbilal56%2Fcore-php-db-migration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabarbilal56%2Fcore-php-db-migration/lists"}