PHPackages                             placebook/framework-selfupdate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. placebook/framework-selfupdate

ActiveLibrary[Database &amp; ORM](/categories/database)

placebook/framework-selfupdate
==============================

Semi-automatic work with SQL migrations

2.0.1(5y ago)03261MITPHPPHP ^7.1|^8.0

Since Sep 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/cri2net/placebook-framework-selfupdate)[ Packagist](https://packagist.org/packages/placebook/framework-selfupdate)[ RSS](/packages/placebook-framework-selfupdate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (13)Used By (1)

ReadMe
======

[](#readme)

The package is intended for semi-automatic updating of the database structure for the project core or third-party packages.

This package is part of the Placebook\\Framework, but it can be used for any of your own projects. Also, it can be used not only for sql migrations, but also for any other reversible migrations.

How it works for the kernel
---------------------------

[](#how-it-works-for-the-kernel)

The project contains a folder for this package. for example, /install The path to this folder was passed to the package:

```
use Placebook\Framework\Core\Install\SelfUpdate;

SelfUpdate::$installDir = ROOT . '/install';
```

This directory contains the versions.json file and custom\_versions.json with the following content:

```
{
    "details": {
        "0":     {"class": null},
        "1.0.0": {"class": "Migration_1"},
        "2.0.0": {"class": "Migration_2"},
        "3.0.0": {"class": "Migration_3", "namespace": "\\YourProject\\Test\\Migration"}
    }
}
```

Here is the version description. By default, class names are in namespace Placebook\\Framework\\Core\\Install, but another namespace can be specified. Kernel versions will always increase only the first version number and be in **versions.json**. Then a specific site can take the current version of the kernel, eg, 3.0.0, and increase the versions as you like, but without increasing the major part of the version (3). And store your versions in a file **custom\_versions.json**. The package will merge both files and will be able to upgrade from scratch to the maximum kernel version, and then to the maximum version of a specific project. At the same time, a specific project that is already working and has its own migrations will be able to update its kernel version, and with it it will be updated and **versions.json**. For example, version 4.0.0 will appear there. Then the package will update the kernel, and then the project will have to assign versions &gt;4.0.0 to its migrations Placebook\\Framework core will not save its versions to file **custom\_versions.json**, he is only yours This way, the package will work well and automatically with both kernel and project migrations.

Update process
--------------

[](#update-process)

The specified folder contains the file **db\_version.lock**It stores the current version of the kernel. If there is no file, version is interpreted as 0

In the same folder there is a file **updating.lock**. If it exists, then the update is in progress, then the package will not start the update in another thread. Thus, if the migration goes on for a long time, then only the first request (after uploading new files) will start the migration. And the rest of the incoming requests will be processed on the base structure that is. The package reads all available versions and arranges them in ascending order. From one version to another, you need to go through all the intermediate ones. If the update is interrupted, the updating.lock file will remain, and the update will not start again until you sort out the situation manually.

For sites
---------

[](#for-sites)

Kernel update:

```
namespace Placebook\Framework\Core\Install;

SelfUpdate::$installDir = ROOT . '/install';
SelfUpdate::updateDbIfLessThen('6.0.0'); // update to a specific version
SelfUpdate::updateDbIfLessThen(SelfUpdate::getMaxVersion()); // upgrade to maximum version

// updateDbIfLessThen updates only upwards. If you need to roll back down, there is another method for this:
$current = SelfUpdate::getDbVersion();
SelfUpdate::updateFromTo($current, '0.0.7'); // update that will work up and down (downgrade)
```

### Adding migration

[](#adding-migration)

- The site needs to wrap the migration in a class that implements the interface *Placebook\\Framework\\Core\\Install\\MigrationInterface*
- You need to add the class name and namespace (if it is not Placebook\\Framework\\Core\\Install, which is the default) in custom\_versions.json under the new version
- In the class, it is desirable to implement both upward migration and migration rollback

### Migration class example

[](#migration-class-example)

```
