Skip to content

Instantly share code, notes, and snippets.

@suwardany
Last active August 29, 2015 14:04
Show Gist options
  • Save suwardany/36b799127aed5952236a to your computer and use it in GitHub Desktop.
Save suwardany/36b799127aed5952236a to your computer and use it in GitHub Desktop.
Sentinel Migration Guide (master to 1.0.0)

Sentinel upgrade guide master to 1.0.*

WARNING 1: Make sure you have a backup of your application and database before attempting any upgrades.

WARNING 2: All active sessions will be flushed. Logged users will have to login again.

  1. Require "doctrine/dbal": "*", on your composer.json
  2. Run composer update
  3. Copy the class below into your routes file.
  4. Add MigrateSentinel::run(); to your routes file.
  5. Hit the app in the browser to trigger the migration.
  6. Remove the class and the MigrateSentinel::run(); call.
  7. Remove 'doctrine/dbal'.
  8. Run composer update.
  9. Republish sentinel's configuration (only required if you have it published already)
  10. Groups have been renamed to Roles, make sure you update any references accordingly.
<?php
use Illuminate\Database\Schema\Blueprint;
class MigrateSentinel {
public static function run()
{
$migrator = app('migrator');
$migratorRepository = $migrator->getRepository();
$migrations = [
'2012_12_06_225921_migration_cartalyst_sentinel_install_users',
'2012_12_06_225929_migration_cartalyst_sentinel_install_groups',
'2012_12_06_225945_migration_cartalyst_sentinel_install_users_groups_pivot',
'2012_12_06_225988_migration_cartalyst_sentinel_install_throttle',
'2013_11_26_014954_migration_cartalyst_sentinel_install_activations',
'2013_11_26_022418_migration_cartalyst_sentinel_install_reminders',
'2013_11_26_023520_migration_cartalyst_sentinel_alter_users',
'2013_11_26_023945_migration_cartalyst_sentinel_rename_alter_groups',
'2013_11_26_024557_migration_cartalyst_sentinel_rename_alter_groups_users_pivot',
'2013_11_26_025024_migration_cartalyst_sentinel_alter_throttle',
];
// Get the batch to replace on the new migration
$migration = $migratorRepository->getConnection()->table('migrations')->where('migration', $migrations[0])->first();
if ( ! $migration)
{
throw new RuntimeException('Cannot find the old migrations');
}
$batch = $migration->batch;
// Modify the tables
// Requires `doctrine/dbal`
Schema::table('groups_users', function(Blueprint $table)
{
$table->renameColumn('group_id', 'role_id');
});
Schema::create('persistences', function(Blueprint $table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('code');
$table->timestamps();
$table->engine = 'InnoDB';
$table->unique('code');
});
Schema::table('users', function(Blueprint $table)
{
$table->dropColumn('persistence_codes');
});
Schema::rename('groups', 'roles');
Schema::rename('groups_users', 'role_users');
$mig = new StdClass;
$mig->migration = '2014_07_02_230147_migration_cartalyst_sentinel';
$migratorRepository->delete($mig);
foreach ($migrations as $migration)
{
$mig = new StdClass;
$mig->migration = $migration;
$migratorRepository->delete($mig);
}
// Log new migration
$migratorRepository->log('2014_07_02_230147_migration_cartalyst_sentinel', $batch);
}
}
@huglester
Copy link

'lottery' => [2, 100],

should be added to both reminders and activations arrays in the config (if you use custom config in app/config/cartalyst/sentinel)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment