Files
sprinkle-organisations/src/Database/Migrations/v1_0_0/OrganisationMembersTable.php

69 lines
2.4 KiB
PHP

<?php
/*
* AVSDev UF Organisations (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-organisations
* @license https://git.avsdev.uk/avsdev/sprinkle-organisations/blob/master/LICENSE.md (LGPL-3.0 License)
*/
namespace UserFrosting\Sprinkle\Organisations\Database\Migrations\v1_0_0;
use Illuminate\Database\Schema\Blueprint;
use UserFrosting\Sprinkle\Organisations\Database\Models\Organisation;
use UserFrosting\Sprinkle\Organisations\Database\Models\OrganisationMember;
use UserFrosting\Sprinkle\Core\Database\Migration;
use UserFrosting\Sprinkle\Core\Facades\Seeder;
/**
* Organisation members table migration
* "Organisations" are intended to replace groups by providing logical grouping where users may be in none or more organisations.
* The organisation members table is used to hold the many-to-many mapping as well as indicate if a user has admin privileges over the organisation.
* Version 1.0.0.
*
* @author Craig Williams (https://avsdev.uk)
*/
class OrganisationMembersTable extends Migration
{
/**
* {@inheritdoc}
*/
public static $dependencies = [
'\UserFrosting\Sprinkle\Account\Database\Migrations\v430\UpdateUsersTable',
'\UserFrosting\Sprinkle\Organisations\Database\Migrations\v1_0_0\OrganisationsTable',
];
/**
* {@inheritdoc}
*/
public function up()
{
if (!$this->schema->hasTable('organisation_members')) {
$this->schema->create('organisation_members', function (Blueprint $table) {
$table->increments('map_id');
$table->integer('user_id')->unsigned();
$table->integer('organisation_id')->unsigned();
$table->boolean('flag_admin');
$table->boolean('flag_approved')->default(1)->comment('Set to 1 if the user membership has been approved, 0 otherwise.');
$table->timestamps();
$table->engine = 'InnoDB';
$table->collation = 'utf8_unicode_ci';
$table->charset = 'utf8';
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('organisation_id')->references('id')->on('organisations');
$table->index('user_id');
$table->index('organisation_id');
});
}
}
/**
* {@inheritdoc}
*/
public function down()
{
$this->schema->drop('organisation_members');
}
}