2020-04-03 23:40:20 -07:00
<? php
2020-09-01 20:24:25 -07:00
use Illuminate\Support\Facades\DB ;
2020-04-03 23:40:20 -07:00
use Illuminate\Support\Facades\Schema ;
2020-04-11 14:07:40 -06:00
use Illuminate\Database\Schema\Blueprint ;
use Illuminate\Database\Migrations\Migration ;
2020-04-03 23:40:20 -07:00
class CreateBackupsTable extends Migration
{
/**
* Run the migrations.
*/
2024-10-21 19:18:20 -06:00
public function up () : void
2020-04-03 23:40:20 -07:00
{
2020-09-01 20:24:25 -07: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 12:09:16 -08:00
'backup%' ,
2020-09-01 20:24:25 -07: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 12:09:16 -08:00
Schema :: rename ( $result -> TABLE_NAME , $result -> TABLE_NAME . '_plugin_bak' );
2020-09-01 20:24:25 -07:00
}
2020-04-03 23:40:20 -07:00
Schema :: create ( 'backups' , function ( Blueprint $table ) {
$table -> bigIncrements ( 'id' );
2020-04-04 10:59:25 -07:00
$table -> unsignedInteger ( 'server_id' );
2020-04-03 23:40:20 -07:00
$table -> char ( 'uuid' , 36 );
$table -> string ( 'name' );
2020-04-04 12:26:39 -07:00
$table -> text ( 'ignored_files' );
2020-04-03 23:40:20 -07: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 10:59:25 -07:00
$table -> unique ( 'uuid' );
$table -> foreign ( 'server_id' ) -> references ( 'id' ) -> on ( 'servers' ) -> onDelete ( 'cascade' );
2020-04-03 23:40:20 -07:00
});
}
/**
* Reverse the migrations.
*/
2024-10-21 19:18:20 -06:00
public function down () : void
2020-04-03 23:40:20 -07:00
{
Schema :: dropIfExists ( 'backups' );
}
}