I write about Python, Go, Node.js,
cloud infrastructure, and data.

Laravel Database Migration for Slack OAuth Bot Installations

Slack bots are ubiquitous nowadays. If you haven’t created one, you should! They’re sometimes useful, but always fun to make. There are so many ways to get started from the series of “Bolt” SDKs from Slack to all the great community contributed packages.

For one example, the official Python SDK has a SQLAlchemy model that is used for the installations database table. This is critical to track your bot installations if you plan on offering it up in more than just your own workspace.

Now I’m no php developer, but have taken a liking to Laravel recently and so am building another bot with it for the learning experience. So for you Laravel users out there, here’s that useful SQLAlchemy table translated to a Laravel migration.


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateSlackInstallationsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('slack_installations', function (Blueprint $table) {
            // PostgreSQL
            // MySQL
            // $table->uuid('id')->unique()->default(DB::raw('(UUID())'));
            $table->string('client_id', 32);
            $table->string('app_id', 32);
            $table->string('enterprise_id', 32)->nullable();
            $table->string('team_id', 32)->nullable();
            $table->string('bot_id', 32)->nullable();
            $table->string('bot_user_id', 32)->nullable();
            $table->string('user_id', 32);
            $table->string('token_type', 32)->nullable();
            $table->index(['client_id', 'enterprise_id', 'team_id', 'user_id', 'installed_at']);

     * Reverse the migrations.
     * @return void
    public function down()

If you’re encrypting your tokens (which you should!), you should make those fields the text type so as they don’t overflow the 255 character limit for a default string.

Consider using the nice and simple package Crudly/Encrypted for automatically encrypting and decrypting these fields.


That’s all for now, but it should give you a start. Watch here for more Laravel Slack blog related posts in the future!

, ,