1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of the Phalcon Framework.
7 *
8 * (c) Phalcon Team <team@phalcon.io>
9 *
10 * For the full copyright and license information, please view the LICENSE.txt
11 * file that was distributed with this source code.
12 */
13
14use Phalcon\Test\Fixtures\Migrations\AbstractMigration;
15
16error_reporting(E_ALL);
17ini_set('display_errors', 'On');
18
19$root = dirname(dirname(__DIR__));
20
21require_once $root . '/vendor/autoload.php';
22
23$drivers = [
24    'mysql',
25    'sqlite',
26    'pgsql',
27    //    'sqlsrv',
28];
29
30$migrations     = getMigrations($root);
31$migrationClass = 'Phalcon\Test\Fixtures\Migrations\%s';
32
33foreach ($drivers as $driver) {
34    $schema = $root . '/tests/_data/assets/schemas/' . $driver . '.sql';
35    cleanFile($schema);
36    echo "Driver: " . $driver . " - ";
37    foreach ($migrations as $migration) {
38        $className  = sprintf($migrationClass, $migration);
39        /** @var AbstractMigration $class */
40        $class      = new $className();
41        $statements = $class->getSql($driver);
42
43        logStatements($statements, $schema);
44    }
45
46    echo PHP_EOL;
47}
48
49
50function cleanFile(string $schema)
51{
52    if (file_exists($schema)) {
53        $handle = fopen($schema, "r+");
54        if ($schema !== false) {
55            ftruncate($handle, 0);
56            fclose($handle);
57        }
58    }
59}
60
61/**
62 * @param string $root
63 *
64 * @return array
65 */
66function getMigrations(string $root): array
67{
68    $path       = $root . '/tests/_data/fixtures/Migrations/';
69    $migrations = [];
70    foreach (glob($path . '*.php') as $file) {
71        $file = str_replace([$path, '.php'], '', $file);
72        if ($file !== 'AbstractMigration') {
73            $migrations[] = $file;
74        }
75    }
76
77    asort($migrations);
78
79    return $migrations;
80}
81
82function logStatements(array $statements, string $schema)
83{
84
85    error_log(PHP_EOL, 3, $schema);
86
87    foreach ($statements as $statement) {
88        error_log($statement, 3, $schema);
89        echo ".";
90    }
91
92    error_log(PHP_EOL, 3, $schema);
93}
94