Skip to content

Instantly share code, notes, and snippets.

@Swader
Created August 27, 2023 11:33
Show Gist options
  • Save Swader/f8bbb0aa5f88d1151fe2ca02fe6a8bf3 to your computer and use it in GitHub Desktop.
Save Swader/f8bbb0aa5f88d1151fe2ca02fe6a8bf3 to your computer and use it in GitHub Desktop.
ChatGPT Migration Output
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEditionsTable extends Migration
{
public function up()
{
Schema::create('editions', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('newsletter');
$table->string('subject');
$table->timestamps();
$table->foreign('newsletter')->references('id')->on('newsletters')->onDelete('restrict')->onUpdate('restrict');
});
}
public function down()
{
Schema::dropIfExists('editions');
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEditionSectionsTable extends Migration
{
public function up()
{
Schema::create('edition_sections', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('edition');
$table->unsignedBigInteger('section');
$table->mediumText('frontmatter')->nullable();
$table->mediumText('hz_pills_filled')->nullable();
$table->timestamps();
$table->foreign('edition')->references('id')->on('editions')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('section')->references('id')->on('sections')->onDelete('cascade')->onUpdate('cascade');
});
}
public function down()
{
Schema::dropIfExists('edition_sections');
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEditorsTable extends Migration
{
public function up()
{
Schema::create('editors', function (Blueprint $table) {
$table->unsignedBigInteger('user');
$table->unsignedInteger('role');
$table->unsignedTinyInteger('accepted')->default(0);
$table->unsignedBigInteger('invited_by');
$table->unsignedInteger('newsletter');
$table->dateTime('invited_on');
$table->dateTime('accepted_on')->nullable();
$table->timestamps();
$table->foreign('user')->references('id')->on('users')->onDelete('restrict')->onUpdate('cascade');
$table->foreign('role')->references('id')->on('roles')->onDelete('restrict')->onUpdate('cascade');
$table->foreign('invited_by')->references('id')->on('users')->onDelete('restrict')->onUpdate('cascade');
});
}
public function down()
{
Schema::dropIfExists('editors');
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateNewslettersTable extends Migration
{
public function up()
{
Schema::create('newsletters', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->unsignedBigInteger('admin');
$table->dateTime('created');
$table->json('settings');
$table->timestamps();
$table->foreign('admin')->references('id')->on('users')->onDelete('restrict')->onUpdate('cascade');
});
}
public function down()
{
Schema::dropIfExists('newsletters');
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePlansTable extends Migration
{
public function up()
{
Schema::create('plans', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->mediumText('description')->nullable();
$table->unsignedInteger('price_month');
$table->unsignedInteger('price_nl');
$table->unsignedInteger('price_per_user');
$table->unsignedInteger('annual_discount_percent');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('plans');
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('title')->unique();
$table->string('slug')->unique();
$table->mediumText('description')->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSectionsTable extends Migration
{
public function up()
{
Schema::create('sections', function (Blueprint $table) {
$table->id();
$table->string('heading');
$table->mediumText('frontmatter')->nullable();
$table->json('style_options')->nullable();
$table->unsignedBigInteger('newsletter');
$table->json('hz_pills')->nullable();
$table->timestamps();
$table->foreign('newsletter')->references('id')->on('newsletters')->onDelete('cascade')->onUpdate('cascade');
});
}
public function down()
{
Schema::dropIfExists('sections');
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ModifyUsersTable extends Migration
{
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->unsignedInteger('plan')->default(0)->after('updated_at');
$table->foreign('plan')->references('id')->on('plans')->onDelete('no action')->onUpdate('no action');
});
}
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['plan']);
$table->dropColumn('plan');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment