-
-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade from 1.x
Barbarian 2.0 is a modernisation and bug-fix release that contains breaking changes. This page summarises what changed and how to adapt.
| Area | 1.x | 2.0 |
|---|---|---|
| Minimum PHP | 7.4 | 8.1 |
initphp/console |
^1.0 |
^2.1 |
| CLI flags | -version= |
--version= |
json command |
json |
init |
Migrations & query gateway |
one class | separate QueryRunner |
getError() |
array | renamed getErrors() |
QueryInterface::query() |
false|PDOStatement |
PDOStatement, throws |
- Upgrade to PHP 8.1+.
-
composer require initphp/barbarian:^2.0— this also pulls ininitphp/console:^2.1.
- foreach ($migrations->getError() as $error) { ... }
+ foreach ($migrations->getErrors() as $error) { ... }Migrations no longer implements QueryInterface. The object passed to your
up()/down() is now a QueryRunner (still a
QueryInterface). If you only ever called
$query->query(...), no change is needed. If you relied on the manager being
passed in, update accordingly.
The connection runs in PDO::ERRMODE_EXCEPTION mode and
query() returns a PDOStatement, throwing
\PDOException on failure. Remove any === false checks:
- $stmt = $query->query($sql);
- if ($stmt === false) { /* handle */ }
+ $stmt = $query->query($sql); // throws on failureUse double-dash arguments:
- vendor/bin/barbarian up -version=20221230091500
+ vendor/bin/barbarian up --version=20221230091500- vendor/bin/barbarian json
+ vendor/bin/barbarian initinit also creates the migrations/ folder referenced by the generated config.
If any of these bit you in 1.x, they are now resolved (and covered by tests):
-
Namespaced migrations are discovered. The
namespaceoption previously had no effect. -
downactually runs. The status comparison no longer breaks under drivers that return the column as a string (e.g. MySQL). - Selecting a migration by full class name no longer crashes the CLI.
-
PostgreSQL works. The version table DDL is valid (
SERIALprimary key). table_nameinbarbarian.jsonis honoured.-
up()/down()return values are honoured — returningfalseno longer records a state change. - Bulk
downruns in reverse order. createno longer needs a database connection.-
Invalid
barbarian.jsonis reported instead of slipping through.
- A
statuscommand, plusMigrations::status()andgetStatuses(). - A
forceargument ondownMigration()(symmetric withupMigration()). - Read accessors:
getFolder(),getNamespace(),getMigrationTable(). - A reusable console layer:
Config,ConfigLoader,ManagerFactory,MigrationTemplate.
initphp/barbarian · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Guide
Reference
Practical Guides
Help