Skip to content

Instantly share code, notes, and snippets.

@gamerwalt
Created October 2, 2015 19:19
Show Gist options
  • Save gamerwalt/9ad254586534ed46ce23 to your computer and use it in GitHub Desktop.
Save gamerwalt/9ad254586534ed46ce23 to your computer and use it in GitHub Desktop.
Migrations for multitenant
Users
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->string('user_uid', 50)->unique();
$table->string('fullname', 600);
$table->string('email_address', 255)->unique();
$table->string('password', 60);
$table->string('verify_token', 60)->nullable();
$table->integer('status_code_id')->unsigned();
$table->foreign('status_code_id')
->references('status_code_id')
->on('db_status_codes')
->onDelete('cascade');
$table->rememberToken();
$table->timestamps();
});
Tenants
Schema::create('tenants', function (Blueprint $table) {
$table->increments('tenant_id');
$table->string('tenant_uid', 50)->unique();
$table->string('company_name', 500)->unique();
$table->string('subdomain_name', 120)->unique();
$table->string('address_1', 200)->nullable();
$table->string('address_2', 250)->nullable();
$table->integer('country_id')->unsigned();
$table->integer('state_id')->unsigned();
$table->string('city', 120)->nullable();
$table->integer('status_code_id')->unsigned();
$table->foreign('status_code_id')
->references('status_code_id')
->on('db_status_codes')
->onDelete('cascade');
$table->dateTime('status_date');
$table->timestamps();
});
Tenants_users
Schema::create('tenant_users', function (Blueprint $table) {
$table->increments('tenant_user_id');
$table->integer('tenant_id')->unsigned();
$table->foreign('tenant_id')
->references('tenant_id')
->on('tenants')
->onDelete('cascade');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')
->references('user_id')
->on('users')
->onDelete('cascade');
$table->timestamps();
});
Ttenant_database
Schema::create('tenant_databases', function (Blueprint $table) {
$table->increments('tenant_database_id');
$table->string('tenant_database_uid', 50)->unique();
$table->integer('tenant_id')->unsigned();
$table->foreign('tenant_id')
->references('tenant_id')
->on('tenants')
->onDelete('cascade');
$table->integer('database_type_id')->unsigned();
$table->foreign('database_type_id')
->references('database_type_id')
->on('db_database_types')
->onDelete('cascade');
$table->string('host', 120);
$table->string('database_name', 500)->unique();
$table->string('username', 500)->unique();
$table->string('password', 500);
$table->string('driver', 500);
$table->string('port', 500);
$table->string('connection_string', 4000);
$table->integer('status_code_id')->unsigned();
$table->foreign('status_code_id')
->references('status_code_id')
->on('db_status_codes')
->onDelete('cascade');
$table->dateTime('status_date');
$table->timestamps();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment