FEATURE #1423: add uploading of title photo for content pages
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ChangeContentTitleImageIdForFilename extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
try {
|
||||
Schema::table('contents', function (Blueprint $table) {
|
||||
$table->dropForeign('fk_content_file1');
|
||||
});
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
// probably foreign does not exist, try to remove one from migration
|
||||
|
||||
try {
|
||||
Schema::table('contents', function (Blueprint $table) {
|
||||
$table->dropForeign('contents_title_photo_foreign');
|
||||
});
|
||||
} catch (\Illuminate\Database\QueryException $ex) {
|
||||
// ignore this error
|
||||
}
|
||||
}
|
||||
|
||||
// force Doctrine to consider enum type as string
|
||||
$platform = Schema::getConnection()
|
||||
->getDoctrineSchemaManager()
|
||||
->getDatabasePlatform();
|
||||
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
Schema::table('contents', function (Blueprint $table) {
|
||||
$table->string('title_photo', 128)
|
||||
->nullable()
|
||||
->default(null)
|
||||
->comment('This photo is supposed to be displayed e.g. on list of all pages.')
|
||||
->change();
|
||||
|
||||
$table->foreign('title_photo')
|
||||
->references('filename')
|
||||
->on('files')
|
||||
->onUpdate('cascade')
|
||||
->onDelete('set null');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// force Doctrine to consider enum type as string
|
||||
$platform = Schema::getConnection()
|
||||
->getDoctrineSchemaManager()
|
||||
->getDatabasePlatform();
|
||||
$platform->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
// delete all title photos
|
||||
DB::statement('UPDATE contents SET title_photo = NULL');
|
||||
|
||||
Schema::table('contents', function (Blueprint $table) {
|
||||
$table->dropForeign('contents_title_photo_foreign');
|
||||
});
|
||||
|
||||
Schema::table('contents', function (Blueprint $table) {
|
||||
$table->integer('title_photo', false)
|
||||
->change();
|
||||
});
|
||||
|
||||
Schema::table('contents', function (Blueprint $table) {
|
||||
$table->foreign('title_photo')
|
||||
->references('id')
|
||||
->on('files');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user