{"id":37262884,"url":"https://github.com/tinyappsde/db-updater","last_synced_at":"2026-01-15T23:24:14.773Z","repository":{"id":57070122,"uuid":"347068238","full_name":"tinyappsde/db-updater","owner":"tinyappsde","description":"Simple PHP library for managing database updates","archived":false,"fork":false,"pushed_at":"2021-11-25T21:00:09.000Z","size":113,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T13:59:29.518Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinyappsde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-12T13:02:05.000Z","updated_at":"2023-09-28T22:00:52.000Z","dependencies_parsed_at":"2022-08-24T14:54:20.843Z","dependency_job_id":null,"html_url":"https://github.com/tinyappsde/db-updater","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/tinyappsde/db-updater","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyappsde%2Fdb-updater","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyappsde%2Fdb-updater/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyappsde%2Fdb-updater/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyappsde%2Fdb-updater/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyappsde","download_url":"https://codeload.github.com/tinyappsde/db-updater/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyappsde%2Fdb-updater/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28473974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T22:27:41.514Z","status":"ssl_error","status_checked_at":"2026-01-15T21:54:47.910Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":[],"created_at":"2026-01-15T23:24:14.141Z","updated_at":"2026-01-15T23:24:14.764Z","avatar_url":"https://github.com/tinyappsde.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Unit Tests](https://github.com/tinyappsde/db-updater/actions/workflows/unit-test.yml/badge.svg?branch=master)](https://github.com/tinyappsde/db-updater/actions/workflows/unit-test.yml)\n\n# Database Updater\nThis is a simple PHP library for managing and executing database updates.\nIt allows you to store database updates in a directory or a single config\nfile and easily execute them in different environments.\n\nEach update needs a unique id. Unlike an incremental versioning this makes it possible\nto have independent updates (e.g. from different features and development branches)\nthat can be automatically executed once the feature is merged or deployed.\n\n## Installation\n`composer require tinyapps/db-updater`\n\nThe following modes are supported: _Directory_, _JSON Config_ and _PHP Config_.\nYou'll find examples for each in the examples folder.\n\nIn JSON/PHP modes an empty config file will be created if no file exists at the\ngiven file path. Alternatively you'll find configs in the examples folder.\n\n## Getting Started\nAfter following the installation instructions above, you’ll need to decide which config mode to use. The directory mode, where each update is stored in a dedicated file in an updates folder, is enabled by default. Alternatively you can use the single config mode with a JSON or PHP file.\n\n### Pick your config mode\n* Directory Mode\n\t* Create an empty folder where you will store the updates in – e.g. `db/updates/` . You’ll need to pass this directory to the updater later.\n* JSON/PHP Config Mode\n\t* When initializing the updater for the first time, the config is automatically generated at your given path. Make sure this path points to a writable folder and no file with that name exists. You’ll need to pass the ` Updater::MODE_JSON` or `Updater::MODE_PHP` as the third argument for the updater’s constructor ( `new Updater(...)`) to enable the mode.\n\n### Execute Updates\n* Create a script file that runs outstanding updates. In this example we’ll create a new PHP file here: `scripts/db-updates.php`.\n* At first you’ll need a PDO instance for your database connection. In case you don’t have a helper class or similar that returns the PDO instance in your project just yet, please read this documentation: [PHP: PDO::__construct - Manual](https://www.php.net/manual/pdo.construct.php)\n* Create a new updater instance with your PDO connection in your script using `$updater = new Updater($pdo, __DIR__ . '/../db/updates');`\n\t* If using the JSON/PHP mode you’ll need to pass the third argument\n* Run outstanding updates (with output) using `$updater-\u003eexecuteOutstandingUpdates(false);`  (see more details in the examples below)\n\n### Save a new update\nThere are two options for adding an update:\n* Programmatically create an update by using  the `saveNewUpdate` method of the updater. (see example below)\n* Manually create a file containing the update queries. The file name is used as the ID of the update and is inevitably unique in the directory mode. E.g. create a file `my-first-update.sql`  in your updates folder and put your queries in there (separated by a semicolon `;` ).\n\n## Example Code\n\n### Initialization\n```php\nuse TinyApps\\DbUpdater\\Updater;\n\n$pdo = new PDO(...); // Your PDO instance\n$updater = new Updater($pdo, __DIR__ . '/path/to/updates', Updater::MODE_DIR);\n```\n\n### Execute outstanding updates\n```php\nuse TinyApps\\DbUpdater\\Exceptions\\UpdateFailureException;\n\ntry {\n\t$executedUpdates = $updater-\u003eexecuteOutstandingUpdates();\n\techo count($executedUpdates) . ' outstanding updates were executed';\n} catch (UpdateFailureException $e) {\n\t// An update failed\n\techo $e-\u003egetMessage();\n}\n```\n\n### Execute a single update\n```php\nuse TinyApps\\DbUpdater\\Exceptions\\UpdateFailureException;\n\ntry {\n\t$updater-\u003eexecuteUpdateWithId('example-update');\n\techo 'Update #example-update executed';\n} catch (UpdateFailureException $e) {\n\techo $e-\u003egetMessage();\n}\n```\n\n### Programmatically add an update\nThe `saveNewUpdate` method optionally takes a second argument containing the ID of the update. If left out, a new unique ID containing the date and a random hash (suggested) is used instead.\n\n```php\n$updater-\u003esaveNewUpdate([\n\t'CREATE TABLE ...',\n\t'ALTER TABLE ...',\n]);\n```\n\n## Unit Tests\n\nThe library contains some unit tests for each mode. To execute them, set the following environment variables and execute `composer test`:\n\n* DB\n* DB_HOST\n* DB_USER\n* DB_PASS\n* DB_PORT\n\nYou can also adjust the phpunit.xml and enter your database credentials there.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyappsde%2Fdb-updater","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyappsde%2Fdb-updater","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyappsde%2Fdb-updater/lists"}