Initial commit

This commit is contained in:
Julien Nahum
2022-09-20 21:59:52 +02:00
commit f8e6cd4dd6
479 changed files with 77078 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
}

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthProvidersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_providers', function (Blueprint $table) {
$table->id();
$table->bigInteger('user_id')->unsigned();
$table->string('provider');
$table->string('provider_user_id')->index();
$table->string('access_token')->nullable();
$table->string('refresh_token')->nullable();
$table->timestamps();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('oauth_providers');
}
}

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
}

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWorkspacesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('workspaces', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('access_token');
$table->string('name');
$table->text('icon')->nullable();
$table->foreignIdFor(\App\Models\User::class, 'user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('workspaces');
}
}

View File

@@ -0,0 +1,67 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFormsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('forms', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(\App\Models\Workspace::class,'workspace_id');
$table->string('title');
$table->string('slug');
$table->json('properties');
$table->timestamps();
$table->boolean('notifies')->default(false);
$table->text('description')->nullable();
$table->text('submit_button_text')->default('Submit');
$table->boolean('re_fillable')->default(false);
$table->text('re_fill_button_text')->default('Fill Again');
$table->string('color')->default('#3B82F6');
$table->boolean('uppercase_labels')->default(true);
$table->boolean('no_branding')->default(false);
$table->boolean('hide_title')->default(false);
$table->text('submitted_text')->default('Amazing, we saved your answers. Thank you for your time and have a great day!');
$table->string('dark_mode')->default('auto');
$table->string('webhook_url')->nullable();
$table->boolean('send_submission_confirmation')->default(false);
$table->string('logo_picture')->nullable();
$table->string('cover_picture')->nullable();
$table->string('redirect_url')->nullable();
$table->text('custom_code')->nullable();
$table->text('notification_emails')->nullable();
$table->string('theme')->default('default');
$table->jsonb('database_fields_update')->nullable();
$table->string('width')->default('centered');
$table->boolean('transparent_background')->default(false);
$table->timestamp('closes_at')->nullable();
$table->text('closed_text')->nullable();
$table->string('notification_subject')->default("We saved your answers");
$table->text('notification_body')->default('<p>Hello there 👋 <br>This is a confirmation that your submission was successfully saved.</p>');
$table->boolean('notifications_include_submission')->default(true);
$table->boolean('use_captcha')->default(false);
$table->boolean('can_be_indexed')->default(true);
$table->string('password')->nullable()->default(null);
$table->string('notification_sender')->default("OpenForm");
$table->jsonb('tags')->default('[]');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('forms');
}
}

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class MakeFormsSoftDeletable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('forms', function (Blueprint $table) {
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('forms', function (Blueprint $table) {
$table->dropSoftDeletes();
});
}
}

View File

@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFormSubmissionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('form_submissions', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(\App\Models\Forms\Form::class,'form_id');
$table->jsonb('data')->default('{}');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('form_submissions');
}
}

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddHearAboutUsToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('hear_about_us')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('hear_about_us');
});
}
}

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFormZapierWebhooksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('form_zapier_webhooks', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(\App\Models\Forms\Form::class,'form_id');
$table->string('hook_url');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('form_zapier_webhooks');
}
}

View File

@@ -0,0 +1,117 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersWorkspacesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Illuminate\Support\Facades\DB::transaction(function () {
Schema::create('user_workspace', function (Blueprint $table) {
$table->id();
$table->integer('workspace_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->unique(['workspace_id', 'user_id']);
$table->boolean('is_owner')->default(false);
$table->string('access_token')->nullable();
$table->foreign('workspace_id')->references('id')->on('workspaces')
->onDelete('cascade')->onUpdate('cascade');
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
// Add creator id to forms table
Schema::table('forms', function (Blueprint $table) {
$table->integer('creator_id')->unsigned()->nullable();
$table->foreign('creator_id')->references('id')->on('users')
->onDelete('cascade')->onUpdate('cascade');
});
// Create relation - can't use models because of new methods clash
\Illuminate\Support\Facades\DB::table('workspaces')
->orderBy('id')
->chunk(100, function ($workspaces) {
foreach ($workspaces as $workspace) {
echo '.';
// Make sure user wasn't deleted
if (!\Illuminate\Support\Facades\DB::table('users')->where('id',
$workspace->user_id)->exists()) {
continue;
}
// Create relation
$now = now();
\Illuminate\Support\Facades\DB::table('user_workspace')->insert([
'workspace_id' => $workspace->id,
'access_token' => $workspace->access_token,
'user_id' => $workspace->user_id,
'is_owner' => true,
'created_at' => $now,
'updated_at' => $now
]);
// Set form creator id
foreach (\App\Models\Forms\Form::withTrashed()->where('workspace_id',$workspace->id)->get() as $form) {
$form->update(['creator_id'=>$workspace->user_id]);
}
}
});
// Drop column
Schema::table('workspaces', function (Blueprint $table) {
$table->dropColumn(['user_id','access_token']);
});
Schema::table('user_workspace', function (Blueprint $table) {
$table->string('access_token')->nullable(false)->change();
});
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
\Illuminate\Support\Facades\DB::transaction(function () {
Schema::table('workspaces', function (Blueprint $table) {
$table->integer('user_id')->unsigned()->nullable();
$table->string('access_token')->nullable();
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade')->onUpdate('cascade');
});
// Remove relation
\App\Models\Workspace::orderBy('id')
->chunk(100, function ($workspaces) {
foreach ($workspaces as $workspace) {
if ($workspace->users()->count() == 0) {
$workspace->delete();
} else {
$workspace->user_id = $workspace->users->first()->id;
$workspace->access_token = $workspace->users()->withPivot('access_token')->first()->pivot->access_token;
$workspace->save();
}
}
});
// Add creator id to forms table
Schema::table('forms', function (Blueprint $table) {
$table->dropColumn('creator_id');
});
Schema::dropIfExists('user_workspace');
});
}
}

View File

@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateJobBatchesTable extends Migration
{
public function up()
{
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->text('failed_job_ids');
$table->text('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
}
}

View File

@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWebhookCallsTable extends Migration
{
public function up()
{
Schema::create('webhook_calls', function (Blueprint $table) {
$table->id();
$table->string('external_id')->nullable()->index();
$table->string('name');
$table->json('payload')->nullable();
$table->text('exception')->nullable();
$table->timestamp('processed_at')->nullable();
$table->timestamps();
});
}
}

View File

@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddIndexesToImportantTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('form_submissions', function (Blueprint $table) {
$table->index('form_id');
});
Schema::table('forms', function (Blueprint $table) {
$table->index('workspace_id');
$table->index('slug');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('form_submissions', function (Blueprint $table) {
$table->dropIndex('form_id');
});
Schema::table('forms', function (Blueprint $table) {
$table->dropIndex('workspace_id');
$table->dropIndex('slug');
});
}
}

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('form_views', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(\App\Models\Forms\Form::class,'form_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('form_views');
}
};

View File

@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('form_statistics', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(\App\Models\Forms\Form::class,'form_id');
$table->jsonb('data')->default('{}');
$table->date('date');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('form_statistics');
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('forms', function (Blueprint $table) {
$table->jsonb('removed_properties')->default('[]');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('forms', function (Blueprint $table) {
$table->dropColumn('removed_properties');
});
}
};

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('forms', function (Blueprint $table) {
$table->integer('max_submissions_count')->nullable()->default(null);
$table->string('max_submissions_reached_text')->nullable()->default('This form has now reached the maximum number of allowed submissions and is now closed.');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('forms', function (Blueprint $table) {
$table->dropColumn('max_submissions_count');
$table->dropColumn('max_submissions_reached_text');
});
}
};

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('user_workspace', function (Blueprint $table) {
$table->dropColumn('access_token');
$table->dropColumn('is_owner');
$table->string('role')->default('admin');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('workspaces', function (Blueprint $table) {
$table->string('access_token')->nullable();
$table->boolean('is_owner')->default(true);
$table->dropColumn('role');
});
}
};