Skip to content
Snippets Groups Projects
Commit 7df371bc authored by Thomas Flori's avatar Thomas Flori
Browse files

create migration for creating the migration table

parent 05059938
No related branches found
No related tags found
No related merge requests found
/composer.lock
/vendor/
/coverage
.env
......@@ -9,7 +9,8 @@
"require-dev": {
"mockery/mockery": "^1.1",
"phpunit/phpunit": "^7.2",
"squizlabs/php_codesniffer": "^3.3"
"squizlabs/php_codesniffer": "^3.3",
"symfony/dotenv": "^4.1"
},
"autoload": {
"psr-4": {
......
<?php
require_once __DIR__ . '/vendor/autoload.php';
$envFile = __DIR__ . '/.env';
if (file_exists($envFile)) {
$dotenv = new Symfony\Component\Dotenv\Dotenv();
$dotenv->load($envFile);
}
// connect to your database...
$dsn = 'mysql:host=127.0.0.1;dbname=testdb;port=3307';
$username = getenv('DB_USERNAME') ?: 'root';
$password = getenv('DB_PASSWORD') ?: 'password';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
);
$db = new PDO($dsn, $username, $password, $options);
$adapter = new Breyta\Adapter\BasicAdapter(function ($statement) use ($db) {
var_dump($statement);
return $db->exec($statement);
});
$migration = new Breyta\Migration\CreateMigrationTable($adapter);
$migration->up();
<?php
namespace Breyta\Migration;
use Breyta\AbstractMigration;
class CreateMigrationTable extends AbstractMigration
{
public function up(): void
{
$this->exec('CREATE TABLE migrations (
file CHARACTER VARYING (64) NOT NULL,
executed TIMESTAMP NOT NULL,
status CHARACTER VARYING (16) NOT NULL DEFAULT \'done\',
info TEXT,
PRIMARY KEY (file)
)');
}
public function down(): void
{
$this->exec('DROP TABLE migrations');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment