Installation: Added migrations for install.sql and update.sql files
This commit is contained in:
parent
175c335810
commit
2bebbeb191
|
@ -29,15 +29,14 @@ before_script:
|
|||
- &before_install_xdebug |-
|
||||
pecl install xdebug
|
||||
docker-php-ext-enable xdebug
|
||||
# MySQL DB
|
||||
- &before_setup_mysql |-
|
||||
apt install -yqq mariadb-client
|
||||
mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < db/install.sql
|
||||
mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < db/update.sql
|
||||
# Install Composer
|
||||
- &before_install_composer |-
|
||||
curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer
|
||||
composer --no-ansi install
|
||||
# MySQL DB
|
||||
- &before_setup_mysql |-
|
||||
chmod +x ./bin/migrate
|
||||
./bin/migrate
|
||||
# Install Node.js and Yarn
|
||||
- &before_install_yarn |-
|
||||
apt -yqq install gnupg2 apt-transport-https
|
||||
|
|
|
@ -41,8 +41,8 @@ To report bugs use [engelsystem/issues](https://github.com/engelsystem/engelsyst
|
|||
|
||||
* Recommended: Directory Listing should be disabled.
|
||||
* There must a be MySQL database created with a user who has full rights to that database.
|
||||
* It must be created by the ```db/install.sql``` and ```db/update.sql``` files.
|
||||
* If necessary, create a ```config/config.php``` to override values from ```config/config.default.php```.
|
||||
* To import the database the ```bin/migrate``` script has to be called.
|
||||
* In the browser, login with credentials ```admin```:```asdfasdf``` and change the password.
|
||||
|
||||
Engelsystem can now be used.
|
||||
|
@ -109,5 +109,10 @@ The `bin/deploy.sh` script can be used to deploy the engelsystem. It uses rsync
|
|||
|
||||
For usage see `./bin/deploy.sh -h`
|
||||
|
||||
##### bin/migrate
|
||||
The `bin/migrate` script can be used to import and update the database of the engelsystem.
|
||||
|
||||
For more information on how to use it call `bin/migrate help`
|
||||
|
||||
### Codestyle
|
||||
Please ensure that your pull requests follow [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/).
|
||||
|
|
19
bin/migrate
19
bin/migrate
|
@ -18,4 +18,21 @@ $app->register(MigrationServiceProvider::class);
|
|||
/** @var Migrate $migration */
|
||||
$migration = $app->get('db.migration');
|
||||
$migration->setOutput(function ($text) { echo $text . PHP_EOL; });
|
||||
$migration->run($baseDir, Migrate::UP);
|
||||
|
||||
if (isset($argv[1]) && strtolower($argv[1]) == 'help') {
|
||||
echo PHP_EOL . 'Usage: ' . $argv[1] . ' [up|down] [one-step]' . PHP_EOL . PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
$method = Migrate::UP;
|
||||
if (isset($argv[1]) && strtolower($argv[1]) == 'down') {
|
||||
$argv = array_values($argv);
|
||||
$method = Migrate::DOWN;
|
||||
}
|
||||
|
||||
$oneStep = false;
|
||||
if (isset($argv[2]) && strtolower($argv[2]) == 'one-step') {
|
||||
$oneStep = true;
|
||||
}
|
||||
|
||||
$migration->run($baseDir, $method, $oneStep);
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
use Engelsystem\Database\Migration\Migration;
|
||||
|
||||
class ImportInstallSql extends Migration
|
||||
{
|
||||
protected $oldTables = [
|
||||
'AngelTypes',
|
||||
'EventConfig',
|
||||
'GroupPrivileges',
|
||||
'Groups',
|
||||
'LogEntries',
|
||||
'Messages',
|
||||
'NeededAngelTypes',
|
||||
'News',
|
||||
'NewsComments',
|
||||
'Privileges',
|
||||
'Questions',
|
||||
'Room',
|
||||
'ShiftEntry',
|
||||
'Shifts',
|
||||
'ShiftTypes',
|
||||
'User',
|
||||
'UserAngelTypes',
|
||||
'UserDriverLicenses',
|
||||
'UserGroups',
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
foreach ($this->oldTables as $table) {
|
||||
if ($this->schema->hasTable($table)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = file_get_contents(__DIR__ . '/../install.sql');
|
||||
$this->schema->getConnection()->unprepared($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reverse the migration
|
||||
*/
|
||||
public
|
||||
function down()
|
||||
{
|
||||
$this->schema->getConnection()->statement('SET FOREIGN_KEY_CHECKS=0;');
|
||||
|
||||
foreach ($this->oldTables as $table) {
|
||||
if ($this->schema->hasTable($table)) {
|
||||
$this->schema->dropIfExists($table);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
use Engelsystem\Database\Migration\Migration;
|
||||
|
||||
class ImportUpdateSql extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if ($this->schema->hasTable('UserWorkLog')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = file_get_contents(__DIR__ . '/../update.sql');
|
||||
$this->schema->getConnection()->unprepared($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->schema->dropIfExists('UserWorkLog');
|
||||
}
|
||||
}
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
// Check for autoloader
|
||||
if (!is_readable(__DIR__ . '/../vendor/autoload.php')) {
|
||||
die('Please run composer.phar install');
|
||||
echo 'Please run composer.phar install';
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Include composer autoloader
|
||||
|
|
Loading…
Reference in New Issue