Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/console-helpers/db-migration
Database migrations made simple
https://github.com/console-helpers/db-migration
Last synced: 2 months ago
JSON representation
Database migrations made simple
- Host: GitHub
- URL: https://github.com/console-helpers/db-migration
- Owner: console-helpers
- License: bsd-3-clause
- Created: 2016-06-09T18:08:43.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-08T18:25:22.000Z (over 3 years ago)
- Last Synced: 2024-04-26T06:20:46.670Z (10 months ago)
- Language: PHP
- Size: 34.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# DB-Migration
[![CI](https://github.com/console-helpers/db-migration/actions/workflows/tests.yml/badge.svg)](https://github.com/console-helpers/db-migration/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/console-helpers/db-migration/branch/master/graph/badge.svg?token=U4gksfjYYj)](https://codecov.io/gh/console-helpers/db-migration)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/console-helpers/db-migration/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/console-helpers/db-migration/?branch=master)[![Latest Stable Version](https://poser.pugx.org/console-helpers/db-migration/v/stable)](https://packagist.org/packages/console-helpers/db-migration)
[![Total Downloads](https://poser.pugx.org/console-helpers/db-migration/downloads)](https://packagist.org/packages/console-helpers/db-migration)
[![License](https://poser.pugx.org/console-helpers/db-migration/license)](https://packagist.org/packages/console-helpers/db-migration)DB-Migration is a library allows to run migrations on SQLite databases with ease.
Goals, when developing the library:
* allow initializing library without knowing database connection details upfront
* allow creating new migration file without knowing database connection details upfront
* allow using several databases in parallel
* being framework agnostic## Usage
### Initialization
```php
use ConsoleHelpers\DatabaseMigration\MigrationManager;
use ConsoleHelpers\DatabaseMigration\PhpMigrationRunner;
use ConsoleHelpers\DatabaseMigration\SqlMigrationRunner;
use Pimple\Container;// 1. Create migration manager instance.
$migration_manager = new MigrationManager(
'/path/to/migrations', // Directory containing migrations.
new Container() // Anything implementing "ArrayAccess".
);// 2. Register migration runners.
$migration_manager->registerMigrationRunner(new SqlMigrationRunner());
$migration_manager->registerMigrationRunner(new PhpMigrationRunner());
```### Creating new migration
The following code will create `YYYYMMDD_HHMM_name.ext` migration file in configured migration folder and return it's name.
```php
use ConsoleHelpers\DatabaseMigration\MigrationManager;$migration_name = $migration_manager->createMigration(
'example_migration', // any valid filename
'sql' // 'php' or 'sql' (comes from migration runner)
);
```As a result:
* the `/path/to/migrations/20160519_2155_example_migration.sql` file would be created
* the `20160519_2155_example_migration.sql` would be returned to `$migration_name` variable#### Migration Templates
__SQL:__
Empty file.
__PHP:__
```php
runMigrations(
// Context consists of the database and container.
new MigrationContext($database)
);
```## Installation
Execute this command to add dependencies:
```bash
php composer.phar require console-helpers/db-migration:^0.1
```## Requirements
* [Aura.Sql](https://github.com/auraphp/Aura.Sql)
## Contributing
See [CONTRIBUTING](CONTRIBUTING.md) file.
## License
DB-Migration is released under the BSD-3-Clause License. See the bundled [LICENSE](LICENSE) file for details.