sidvind / php-migrations
Database migration scripts for PHP
Installs: 3 852
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 3
pkg:composer/sidvind/php-migrations
Requires
- ulrichsg/getopt-php: ^3.0
This package is auto-updated.
Last update: 2025-10-10 08:20:48 UTC
README
This is a php-script that helps you handling versions of your database in a format that works well with code versioning.
This is a fork of torandi/php_migrations with breaking changes.
Differences
update_databasewill exit with error codes on any error.--checkis renamed--dry-run.- Misc additional CLI options such as
--config. - Uses
getopt-phpinstead of custom argument parsing.
Configuration and setup
composer require sidvind/php-migrations- Create a directory in your project named
migrations(or whatever) - Symlink
update_database.phpandcreate_migration.phpinto the directory. - Copy
config-example.phptoconfig.phpand edit it to fit your project (seeconfig-example.phpfor more info)
Usage
Use migrations/create_migration.php migration_name to create a new migration.
This creates a empty migration with a name like
20110821231945_migration_name.sql. The file name (including the date) is the
version name, and must be unique.
You may also specify a second argument to create_migration to select file format (sql or php):
- SQL: SQL to be run for the migration (multiple lines separated by ;)
- PHP: PHP code to be executed, the environment you loaded in
config.phpis available, remember<?phpand be verbose. Not run in global scope.
To then run the migrations execute migrations/update_database.php which runs
all unrun migrations. The table schema_migrations are created (if not exist)
containing all run migrations.
PHP-migration-script-helper-functions
migration_sql(query): Print and run queryrun_sql(query): Run query in silence
update_database.php usage
Usage: migrations/update_database.php [options] [<username>]
Options:
-c, --config <arg> Configuration file to use. Default: "config.php".
-h, --help Show this text.
-n, --dry-run Only checks if there are migrations to run, won't perform
any modifications.
Username may be optional, depending on your config.php