Perform database migrations
342660
def migrate(record, dry_run=False):
    ''''''
    handler = record_migration if record else execute_migration
    success = True
    for plugin, package, filename in available_migrations():
        migration = get_migration(plugin, filename)
        if migration or not success:
            log_status(plugin, filename, cyan('Skipped'))
        else:
            status = magenta('Recorded') if record else yellow('Apply')
            log_status(plugin, filename, status)
            script = resource_string(package, join('migrations', filename))
            success &= handler(plugin, filename, script, dryrun=dry_run)
1256674
def makemigrations(self):
        ''' 
        '''

        UNCHANGED = []

        with Session(self.settings) as conn:
            cursor = conn.cursor()
            for name, model in self.models.items():
                print("Running migrations... on table: %s"%model.__name__.lower())
                columns = self.description(model)
        
                table = name.lower()
                QUERY = "CREATE TABLE IF NOT EXISTS %s ("%table

                for field, FieldType in model.columns.items():
                    QUERY += "%s %s, " % (field, FieldType)
                    # If no columns --> Table not created yet
                    if columns:
                        self.UpdateColums(cursor, field, FieldType, 
                            model, columns, UNCHANGED)

                QUERY = QUERY[:-2] + ") ENGINE=InnoDB"
            
                print(QUERY)
                
                try:
                    cursor.execute(QUERY)
                except mysql.Error as e:
                    raise e

            return True
1288956
public function up()
    {
        // Create table for storing roles
        Schema::create('data_types', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('slug')->unique();
            $table->string('display_name_singular');
            $table->string('display_name_plural');
            $table->string('icon')->nullable();
            $table->string('model_name')->nullable();
            $table->string('description')->nullable();
            $table->boolean('generate_permissions')->default(false);
            $table->timestamps();
        });

        // Create table for storing roles
        Schema::create('data_rows', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('data_type_id')->unsigned();
            $table->string('field');
            $table->string('type');
            $table->string('display_name')->nullable();
            $table->boolean('required')->default(false);
            $table->boolean('browse')->default(true);
            $table->boolean('read')->default(true);
            $table->boolean('edit')->default(true);
            $table->boolean('add')->default(true);
            $table->boolean('delete')->default(true);
            $table->text('details')->nullable();

            $table->foreign('data_type_id')->references('id')->on('data_types')
                ->onUpdate('cascade')->onDelete('cascade');
        });
    }
176873
public function moveMigrationFiles()
    {
        $databaseDirectory = base_path('Modules/'.$this->module.'/database');
        if (!$this->files->exists($databaseDirectory.'/migrations')) {
            return;
        }
        $files = $this->files->files($databaseDirectory.'/migrations');
        foreach ($files as $from) {
            $file = basename($from);
            $to = base_path('database/migrations/'.$file);
            $this->files->move($from, $to);
        }
        $this->files->deleteDirectory($databaseDirectory);
    }
1148439
public function up()
    {
        // Create table for storing roles
        Schema::create('roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('display_name')->nullable();
            $table->string('description')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        // Create table for storing users
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('first_name');
            $table->string('last_name');
            $table->integer('country_id')->unsigned();
            $table->string('phone_number')->nullable();
            $table->string('username');
            $table->string('password');
            $table->string('email')->unique();
            $table->string('slug')->unique();
            $table->integer('points')->default(0);
            $table->timestamp('last_login')->nullable();
            $table->string('remember_token');
            $table->boolean('state')->default(1);
            $table->timestamps();
            $table->softDeletes();

            $table->foreign('country_id')->references('id')->on('countries');
        });

        // Create table for associating roles to users (Many-to-Many)
        Schema::create('role_user', function (Blueprint $table) {
            $table->integer('user_id')->unsigned();
            $table->integer('role_id')->unsigned();

            $table->foreign('user_id')->references('id')->on('users')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('role_id')->references('id')->on('roles')
                ->onUpdate('cascade')->onDelete('cascade');

            $table->primary(['user_id', 'role_id']);
            $table->softDeletes();
        });

        // Create table for storing permissions
        Schema::create('permissions', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('display_name')->nullable();
            $table->string('description')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        // Create table for associating permissions to roles (Many-to-Many)
        Schema::create('permission_role', function (Blueprint $table) {
            $table->integer('permission_id')->unsigned();
            $table->integer('role_id')->unsigned();

            $table->foreign('permission_id')->references('id')->on('permissions')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('role_id')->references('id')->on('roles')
                ->onUpdate('cascade')->onDelete('cascade');

            $table->primary(['permission_id', 'role_id']);
            $table->softDeletes();
        });
    }
394212
public function up()
	{
		$table_name = $this->getTableName();
		Schema::create($table_name, function($table)
		{
			$table->increments('id');
		});
		DB::statement('ALTER TABLE  `'.$table_name.'` ADD  `file_object` LONGBLOB NOT NULL');
	}
1276497
public function up()
    {
        if (Config::get('database')['default'] === 'mysql') {
            DB::statement('alter table ab_events change column instance_id instance_id integer(11)');
            DB::statement('alter table ab_events change column experiments_id experiments_id integer(11)');
    
            DB::statement('alter table ab_goal change column instance_id instance_id integer(11)');
        } else if (Config::get('database')['default'] === 'pgsql') {
            DB::statement('alter table ab_events alter column instance_id type integer using (instance_id::integer)');
            DB::statement('alter table ab_events alter column experiments_id type integer using (experiments_id::integer)');
            
            DB::statement('alter table ab_goal alter column instance_id type integer using (instance_id::integer)');
        }
    }
473068
public function up()
    {
        $file = dirname($this->getIdentifier()->filepath).'/'.$this->getVersion().'.sql';
        if (file_exists($file)) {
            dbexecfile($file);
        }
    }
29892
public function up()
    {
        DB::transaction(function() {
            $datetime = Carbon::now();
            DB::table('tbl_roles')->insert([
                'name'       => 'super-administrator',
                'full_name'  => 'Super Administrator',
                'area'       => 'admin',
                'created_at' => $datetime,
                'updated_at' => $datetime,
            ]);
            DB::table('tbl_roles')->insert([
                'parent_id'  => DB::getPdo()->lastInsertId(),
                'name'       => 'administrator',
                'area'       => 'admin',
                'full_name'  => 'Administrator',
                'created_at' => $datetime,
                'updated_at' => $datetime,
            ]);
            DB::table('tbl_roles')->insert([
                'parent_id'  => DB::getPdo()->lastInsertId(),
                'name'       => 'member',
                'area'       => 'users',
                'full_name'  => 'Member',
                'created_at' => $datetime,
                'updated_at' => $datetime,
            ]);
            DB::table('tbl_roles')->insert([
                'parent_id'  => DB::getPdo()->lastInsertId(),
                'name'       => 'guest',
                'full_name'  => 'Guest',
                'created_at' => $datetime,
                'updated_at' => $datetime,
            ]);
        });
    }
561387
public function up()
    {
        if (Schema::hasTable('service_type')) {
            $output = new \Symfony\Component\Console\Output\ConsoleOutput();
            $output->writeln('Scanning database for old sql_db service type...');
            $ids = DB::table('service')->where('type', 'sql_db')->pluck('id');
            if (!empty($ids)) {
                $configs = DB::table('sql_db_config')->whereIn('service_id', $ids)->get();
                $output->writeln('|--------------------------------------------------------------------');
                foreach ($configs as $entry) {
                    /** @type array $entry */
                    $entry = (array)$entry;
                    $newType = '';
                    $config = static::adaptConfig($entry, $newType);
                    $config = json_encode($config);
                    $id = array_get($entry, 'service_id');
                    $output->writeln('| Service ID: ' . $id . ' New Config: ' . $config);
                    DB::table('service')->where('id', $id)->update(['type' => $newType]);
                    DB::table('sql_db_config')->where('service_id', $id)->update(['connection' => $config]);
                }
                $output->writeln('|--------------------------------------------------------------------');
            }

            $output->writeln('Scanning database for old script service type...');
            $ids = DB::table('service')->where('type', 'script')->pluck('id');
            if (!empty($ids)) {
                $configs = DB::table('script_config')->whereIn('service_id', $ids)->pluck('type', 'service_id');
                $output->writeln('|--------------------------------------------------------------------');
                foreach ($configs as $id => $driver) {
                    $newType = $driver;
                    $output->writeln('| ID: ' . $id . ' New Type: ' . $newType);
                    DB::table('service')->where('id', $id)->update(['type' => $newType]);
                }
                $output->writeln('|--------------------------------------------------------------------');
            }
        }
    }
238038
public function up()
    {
        \Schema::create('config', function (Blueprint $table) {
            $table->engine = 'InnoDB';

            $table->increments('id');
            $table->string('namespace')
                  ->default('');
            $table->string('key');
            $table->string('value');
            $table->enum('type', ['int', 'bool', 'string']);
            $table->unsignedInteger('modified_by_user_id');
            $table->timestamp('modified_at');

            $table->unique(['namespace', 'key']);
        });
    }
500474
public function migrateUp()
    {
        Schema::table('tddd_runs', function (Blueprint $table) {
            $table->mediumText('log_new')->nullable()->after('was_ok');
        });

        Database::statement('update tddd_runs set log_new = log;');

        Schema::table('tddd_runs', function (Blueprint $table) {
            $table->dropColumn('log');
            $table->renameColumn('log_new', 'log');
        });
    }
404472
public function up()
	{
		if(Schema::hasColumn('001_026_field', 'field_type_026'))
		{
			// change column name
			DB::select(DB::raw('ALTER TABLE 001_026_field CHANGE field_type_026 field_type_id_026 TINYINT(3) UNSIGNED NOT NULL'));
		}

		if(Schema::hasColumn('001_026_field', 'field_type_text_026'))
		{
			// change column name
			DB::select(DB::raw('ALTER TABLE 001_026_field CHANGE field_type_text_026 field_type_name_026 VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL'));
		}

		if(Schema::hasColumn('001_026_field', 'data_type_026'))
		{
			// change column name
			DB::select(DB::raw('ALTER TABLE 001_026_field CHANGE data_type_026 data_type_id_026 TINYINT(3) UNSIGNED NOT NULL'));
		}

		if(Schema::hasColumn('001_026_field', 'data_type_text_026'))
		{
			// change column name
			DB::select(DB::raw('ALTER TABLE 001_026_field CHANGE data_type_text_026 data_type_name_026 VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL'));
		}

		if(Schema::hasColumn('001_028_field_result', 'data_type_028'))
		{
			// change column name
			DB::select(DB::raw('ALTER TABLE 001_028_field_result CHANGE data_type_028 data_type_type_028 VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL'));
		}
	}
482809
public function up()
    {
        DB::statement('create index sites_default on sites(`default`)');
        DB::statement('create index album_asset_asset_id on album_asset(asset_id)');
        DB::statement('create index assets_created_at_asc on assets(created_at asc)');
        DB::statement('create index assets_created_at_desc on assets(created_at desc)');
        DB::statement('create index albums_deleted_at on albums(deleted_at)');
        DB::statement('create index albums_name_asc_deleted_at on albums(name asc, deleted_at)');

        try {
            DB::statement('alter table assets drop index asset_v_rid');
        } catch (\Exception $e) {
        }
    }
1332825
public function up()
    {
        $connection = config('admin.database.connection') ?: config('database.default');

        $table = config('admin.extensions.config.table', 'admin_config');

        Schema::connection($connection)->create($table, function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('value');
            $table->text('description')->nullable();
            $table->timestamps();
        });
    }
191146
public function up()
    {
        $this->create('migrations', function ($table) {
            // Place table rows here
            $table->increments('id');
            $table->string('migration');
            $table->integer('migrated');
            $table->timestamps();
        });
    }
27516
public function up() {
		$db = Database::get();
		$db->query("
			ALTER TABLE `file`
			ADD `path` varchar(128) COLLATE 'utf8_unicode_ci' NOT NULL AFTER `name`;
		", []);

		$data = $db->get_all('SELECT * FROM file WHERE path = "" AND md5sum != ""', []);
		foreach ($data as $row) {
			$path = $this->get_path($row);
			$db->query('UPDATE file SET path=? WHERE id=?', [ $path, $row['id'] ]);
		}
	}