Verified Commit b0ac1641 authored by Maxime FRIESS's avatar Maxime FRIESS 💙
Browse files

[db] Added events

parent 01940241
Pipeline #65442 passed with stages
in 3 minutes and 49 seconds
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
use HasFactory;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class EventParticipation extends Model
{
use HasFactory;
}
......@@ -5,6 +5,7 @@ use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
use Illuminate\Support\Facades\DB;
class CreateUsersTable extends Migration
{
......@@ -28,13 +29,13 @@ class CreateUsersTable extends Migration
$table->timestamp('password_changed_at')->nullable()->default(null);
});
$user = User::create([
DB::table('users')->insert([
'username' => 'root',
'firstname' => 'Chuck',
'lastname' => 'NORRIS',
'email' => 'root@localhost',
'password' => Hash::make('rootroot'),
'permissions' => ["*.*"]
'permissions' => '["*.*"]'
]);
// Ensure next IDs are > 1000.
......
......@@ -4,6 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\Account;
use Illuminate\Support\Facades\DB;
class CreateAccountsTable extends Migration
{
......
<?php
use App\Models\Person;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
......@@ -27,6 +28,10 @@ class AddPeopleUser extends Migration
->where('firstname', $user->firstname)
->where('lastname', $user->lastname)->first();
if ($person == null) {
$person = Person::create(["firstname" => $user->firstname, "lastname" => $user->lastname]);
}
DB::table('users')->where('id', $user->id)->update(['person_id' => $person->id]);
}
});
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEventsTable extends Migration
{
/*
[
{
name: "Pizza",
type: "boolean",
price: 8,
price_member: 5
},
{
name: "Type pizza"
type: "select",
values: [
"Reine", "Savoyarde"
]
},
{
type: "string",
name: "Pseudonyme"
}
]
*/
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(
'events',
function (Blueprint $table) {
$table->id();
$table->string("name");
$table->string("location");
$table->dateTime("inscriptions_closed_at");
$table->dateTime("start");
$table->dateTime("end");
$table->decimal("max_people");
$table->decimal('price', $precision = 12, $scale = 3)->default(0);
$table->decimal('price_member', $precision = 12, $scale = 3)->default(0);
$table->json("additional_data");
$table->foreignId("category_id");
$table->timestamps();
}
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('events');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEventParticipationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(
'event_participations',
function (Blueprint $table) {
$table->id();
$table->foreignId("event_id");
$table->foreignId("person_id");
$table->foreignId("transaction_id")->nullable()->default(null);
$table->json("additional_data");
$table->timestamps();
}
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('event_participations');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment