Skip to content

Instantly share code, notes, and snippets.

@Swader
Created August 27, 2023 19:42
Show Gist options
  • Save Swader/25c274d04b825c35edd1a7a7984f75c3 to your computer and use it in GitHub Desktop.
Save Swader/25c274d04b825c35edd1a7a7984f75c3 to your computer and use it in GitHub Desktop.
Code Llama Migration Output
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSectionsAndEditionSectionsTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Sections table
Schema::create('sections', function (Blueprint $table) {
$table->id();
$table->string('heading', 45);
$table->mediumText('frontmatter')->nullable();
$table->json('style_options')->nullable();
$table->unsignedBigInteger('newsletter_id');
$table->json('hz_pills')->nullable();
$table->timestamps();
$table->unique(['id', 'newsletter_id']);
$table->index(['newsletter_id']);
$table->foreign('newsletter_id')
->references('id')
->on('newsletters')
->onDelete('cascade')
->onUpdate('cascade');
});
// Edition sections table
Schema::create('edition_sections', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('edition_id');
$table->unsignedBigInteger('section_id');
$table->mediumText('frontmatter')->nullable();
$table->mediumText('hz_pills_filled')->nullable();
$table->timestamps();
$table->unique(['edition_id', 'section_id']);
$table->index(['section_id']);
$table->foreign('edition_id')
->references('id')
->on('editions')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('section_id')
->references('id')
->on('sections')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sections');
Schema::dropIfExists('edition_sections');
}
}
<?php
// editors migration
public function up()
{
Schema::create('editors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user')->unsigned()->nullable();
$table->integer('role')->unsigned()->nullable();
$table->tinyInteger('accepted')->default(false);
$table->integer('invited_by')->unsigned()->nullable();
$table->integer('newsletter')->unsigned()->nullable();
$table->dateTime('invited_on')->nullable();
$table->dateTime('accepted_on')->nullable();
$table->index(['user', 'role', 'newsletter'], 'mainkey');
$table->index(['invited_by'], 'inviter_idx');
$table->index(['role'], 'role_idx');
$table->foreign('invited_by')
->references('id')
->on('users')
->onDelete('restrict')
->onUpdate('cascade');
$table->foreign('user')
->references('id')
->on('users')
->onDelete('restrict')
->onUpdate('cascade');
$table->foreign('role')
->references('id')
->on('roles')
->onDelete('restrict')
->onUpdate('cascade');
});
}
// editions migration
public function up()
{
Schema::create('editions', function (Blueprint $table) {
$table->increments('id');
$table->integer('newsletter')->unsigned()->nullable();
$table->string('subject', 150)->nullable();
$table->primary(['id', 'newsletter']);
$table->index(['newsletter'], 'nl_idx');
$table->foreign('newsletter')
->references('id')
->on('newsletters')
->onDelete('restrict')
->onUpdate('restrict');
});
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class FailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('uuid', 255)->nullable();
$table->text('connection')->nullable();
$table->text('queue')->nullable();
$table->longText('payload')->nullable();
$table->longText('exception')->nullable();
$table->timestamp('failed_at')->default(\Illuminate\Support\Carbon::now());
$table->primary('id');
$table->unique('failed_jobs_uuid_unique');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
}
<?php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class MigrationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('migrations', function (Blueprint $table) {
$table->integer('id')->autoIncrement();
$table->string('migration', 255)->nullable();
$table->integer('batch')->nullable();
$table->primary('id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('migrations');
}
}
<?php
// newsletters migration
public function up()
{
Schema::create('newsletters', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->bigInteger('admin')->unsigned();
$table->datetime('created');
$table->json('settings');
$table->primary(['id']);
$table->unique(['id'], 'id_UNIQUE');
$table->index(['admin'], 'admin_idx');
$table->foreign('admin')
->references('id')
->on('users')
->onDelete('restrict')
->onUpdate('cascade');
});
}
// roles migration
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug');
$table->mediumText('description')->nullable();
$table->primary(['id']);
$table->unique(['title'], 'title_UNIQUE');
$table->unique(['slug'], 'slug_UNIQUE');
});
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class PasswordResetTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email', 255)->nullable();
$table->string('token', 255)->nullable();
$table->timestamp('created_at')->nullable();
$table->primary('email');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_reset_tokens');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class PersonalAccessTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('tokenable_type', 255)->nullable();
$table->bigInteger('tokenable_id')->nullable();
$table->string('name', 255)->nullable();
$table->string('token', 64)->nullable();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
$table->primary('id');
$table->unique('personal_access_tokens_token_unique');
$table->index('personal_access_tokens_tokenable_type_tokenable_id_index');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('personal_access_tokens');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePlansTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('plans', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('slug')->unique()->index();
$table->text('description')->nullable();
$table->integer('price_month')->unsigned()->default(0);
$table->integer('price_nl')->unsigned()->default(0);
$table->integer('price_per_user')->unsigned()->default(0);
$table->integer('annual_discount_percent')->unsigned()->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('plans');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
$table->unsignedBigInteger('plan_id')->nullable();
$table->foreign('plan_id')
->references('id')
->on('plans')
->onDelete('NO ACTION')
->onUpdate('NO ACTION');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment