2020-04-04 08:40:20 +02:00
< ? php
2020-09-02 05:24:25 +02:00
use Illuminate\Support\Facades\DB ;
2020-04-04 08:40:20 +02:00
use Illuminate\Support\Facades\Schema ;
2020-04-11 22:07:40 +02:00
use Illuminate\Database\Schema\Blueprint ;
use Illuminate\Database\Migrations\Migration ;
2020-04-04 08:40:20 +02:00
class CreateBackupsTable extends Migration
{
/**
* Run the migrations .
*
* @ return void
*/
public function up ()
{
2020-09-02 05:24:25 +02:00
$db = config ( 'database.default' );
// There exists a backups plugin for the 0.7 version of the Panel. However, it didn't properly
// namespace itself so now we have to deal with these tables being in the way of tables we're trying
// to use. For now, just rename them to maintain the data.
$results = DB :: select ( 'SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = ? AND table_name LIKE ? AND table_name NOT LIKE \'%_plugin_bak\'' , [
config ( " database.connections. { $db } .database " ),
2021-01-23 21:09:16 +01:00
'backup%' ,
2020-09-02 05:24:25 +02:00
]);
// Take any of the results, most likely "backups" and "backup_logs" and rename them to have a
// suffix so data isn't completely lost, but they're no longer in the way of this migration...
foreach ( $results as $result ) {
2021-01-23 21:09:16 +01:00
Schema :: rename ( $result -> TABLE_NAME , $result -> TABLE_NAME . '_plugin_bak' );
2020-09-02 05:24:25 +02:00
}
2020-04-04 08:40:20 +02:00
Schema :: create ( 'backups' , function ( Blueprint $table ) {
$table -> bigIncrements ( 'id' );
2020-04-04 19:59:25 +02:00
$table -> unsignedInteger ( 'server_id' );
2020-04-04 08:40:20 +02:00
$table -> char ( 'uuid' , 36 );
$table -> string ( 'name' );
2020-04-04 21:26:39 +02:00
$table -> text ( 'ignored_files' );
2020-04-04 08:40:20 +02:00
$table -> string ( 'disk' );
$table -> string ( 'sha256_hash' ) -> nullable ();
$table -> integer ( 'bytes' ) -> default ( 0 );
$table -> timestamp ( 'completed_at' ) -> nullable ();
$table -> timestamps ();
$table -> softDeletes ();
2020-04-04 19:59:25 +02:00
$table -> unique ( 'uuid' );
$table -> foreign ( 'server_id' ) -> references ( 'id' ) -> on ( 'servers' ) -> onDelete ( 'cascade' );
2020-04-04 08:40:20 +02:00
});
}
/**
* Reverse the migrations .
*
* @ return void
*/
public function down ()
{
Schema :: dropIfExists ( 'backups' );
}
}