new db migration

This commit is contained in:
RundelhausCode 2021-03-05 11:23:10 +01:00
parent 01f6e16283
commit d2182f5020
10 changed files with 29 additions and 50 deletions

View File

@ -10,6 +10,7 @@ Capsule::schema()->create("game_data", function (Blueprint $table){
$table->id();
$table->string("gameLink");
$table->boolean("isWebBased");
$table->string("img");
$table->timestamps();
});

View File

@ -11,8 +11,6 @@ Capsule::schema()->create("groups", function (Blueprint $table){
$table->string("groupName");
$table->integer("groupAmount");
$table->foreignId("game_jam_id")->constrained("game_jams");
$table->integer("votes")->nullable();
$table->foreignId("password_id")->constrained("passwords");
$table->foreignId("game_data_id")->nullable()->constrained("game_data");
$table->timestamps();
});

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Schema;
//Create password table with the rows as id, password, rememberToken and timestamps
Capsule::schema()->create("passwords", function (Blueprint $table){
$table->id();
$table->foreignId("group_id")->constrained("groups");
$table->string('password');
$table->rememberToken();
$table->timestamps();

14
Backend/Database/Vote.php Normal file
View File

@ -0,0 +1,14 @@
<?php
require_once "../../bootstrap.php";
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Capsule::schema()->create("votes", function (Blueprint $table){
$table->id();
$table->foreignId("group_id")->constrained("groups");
$table->tinyInteger("points");
$table->text("comment")->nullable();
$table->timestamps();
});

View File

@ -15,6 +15,7 @@
require "GameJam.php"; //GameJam has no foreign key
require "GameData.php"; //GameData has no foreign key
require "Password.php"; //Password has no foreign key
require "Group.php"; //Group has foreign keys to the GameJam, GameData and Password tables hence we create it as one of the last tables in the database
require "Password.php"; //Password has no foreign key
require "KeyWord.php"; //Group has foreign keys to the Group
require "Vote.php";

View File

@ -1,23 +0,0 @@
<?php
//require bootstrap aka our database connection
require_once "../../bootstrap.php";
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//Create has_voted table with the rows as id and timestamp
Capsule::schema()->create("has_voted", function (Blueprint $table){
$table->id();
$table->timestamps();
});
/*
Syntex to create table in database
$table->string("texts");
$table => valuable;
string => datatype;
("texts") => name for the row in the database
*/

View File

@ -17,6 +17,6 @@ class Group extends Eloquent
return $this->belongsTo(GameData::class);
}
public function password(){
return $this->belongsTo(Password::class);
return $this->hasOne(Password::class);
}
}

View File

@ -8,7 +8,7 @@ class Password extends Eloquent{
public function group(){
return $this->hasOne(Group::class);
return $this->belongsTo(Group::class);
}
}

View File

@ -1,12 +0,0 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class hasVoted extends Eloquent{
protected $fillable =[
'ipaddress'
];
public function gameData(){
return $this->belongsTo(GameData::class);
}
}

View File

@ -14,29 +14,28 @@ $errors = array();
if(isset($_POST['reg_group'])){
$password = New Password();
$password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT);
if(!$password->save()){
return;
}
$group = new Group();
$group->password()->associate($password);
$group->gameJam()->associate(GameJam::find($_POST['gameJamId']));
$group->groupName = $groupName = $_POST['groupName'];
$group->groupAmount = $_POST['groupAmount'];
$group->votes = 0;
if(!$group->save()){
return;
}
$password = New Password();
$password->group()->associate($group);
$password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT);
if(!$password->save()){
return;
}
$_SESSION['groupName'] = $groupName;
$_SESSION['success'] = "You are now logged in";