Downgrade the database
346339
def db_downgrade(version):
    """"""
    v1 = get_db_version()
    migrate_api.downgrade(url=db_url, repository=db_repo, version=version)
    v2 = get_db_version()

    if v1 == v2:
        print 'No changes made.'
    else:
        print 'Downgraded: %s ... %s' % (v1, v2)
974411
public function down()
    {
        // Check if the table exists
        if (Schema::hasTable('translations')) {
            if (Schema::hasColumn('translations', 'translatable_type')) {
                $items = DB::select('select * from translations');
                foreach ($items as $item) {
                    // Points to old namespace Redooor\\Redminportal\\
                    $old_type_array = explode('\\', $item->translatable_type);
                    $last_model = array_pop($new_type_array);
                    $old_type = 'Redooor\\Redminportal\\' . $last_model;
                    DB::table('translations')->where('id', $item->id)
                        ->update([
                        'translatable_type' => $old_type
                    ]);
                }
            }
        }
    }
472183
public function down()
    {
        Schema::table('ticketit', function (Blueprint $table) {
            $table->dropColumn('html');
        });

        Schema::table('ticketit_comments', function (Blueprint $table) {
            $table->dropColumn('html');
            $table->text('content')->change();
        });
    }
574218
def downgrade(account):
    """"""
    d_account = dict(schema_version=1, metadata={'email': account['email']},
                     tags=list(set([account['environment']] + account.get('tags', []))))

    v1_services = {}
    for service in account.get('services', []):
        if service['name'] == 's3':
            if service['metadata'].get('name'):
                d_account['metadata']['s3_name'] = service['metadata']['name']

        elif service['name'] == 'cloudtrail':
            d_account['metadata']['cloudtrail_index'] = service['metadata']['esIndex']
            d_account['metadata']['cloudtrail_kibana_url'] = service['metadata']['kibanaUrl']

        elif service['name'] == 'bastion':
            d_account['bastion'] = service['metadata']['hostname']

        elif service['name'] == 'titus':
            v1_services['titus'] = {
                'stacks': service['metadata']['stacks'],
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'spinnaker':
            v1_services['spinnaker'] = {
                'name': service['metadata'].get('name', account["name"]),
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'awwwdit':
            v1_services['awwwdit'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'security_monkey':
            v1_services['security_monkey'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'poseidon':
            v1_services['poseidon'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'rolliepollie':
            v1_services['rolliepollie'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'lazyfalcon':
            owner = None

            if service.get('metadata'):
                if service['metadata'].get('owner'):
                    owner = service['metadata']['owner']

            v1_services['lazyfalcon'] = {
                'enabled': service['status'][0]['enabled'],
                'owner': owner
            }

    if account['provider'] == 'aws':
        d_account['metadata']['account_number'] = account['id']

    elif account['provider'] == 'gcp':
        d_account['metadata']['project_id'] = account['id']

    d_account['id'] = account['provider'] + '-' + account['id']
    d_account['cmc_required'] = account['sensitive']
    d_account['name'] = account['name']
    d_account['alias'] = account['aliases']
    d_account['description'] = account['description']
    d_account['owners'] = account['contacts']
    d_account['type'] = account['provider']
    d_account['ours'] = True if account['owner'] == 'netflix' else False
    d_account['netflix'] = True if account['owner'] == 'netflix' else False
    d_account['services'] = v1_services
    d_account['account_status'] = account['account_status']

    return d_account
872782
public function down()
	{
        // Create the old table
        if (! Schema::hasTable('user_pricelists')) {
            Schema::create('user_pricelists', function(Blueprint $table) {
                $table->increments('id');
                $table->integer('user_id')->unsigned();
                $table->foreign('user_id')->references('id')->on('users');
                $table->integer('pricelist_id')->unsigned();
                $table->foreign('pricelist_id')->references('id')->on('pricelists');
                $table->unique(array('user_id', 'pricelist_id'));
                $table->decimal('paid', 8, 2)->default(0);
                $table->string('transaction_id')->default('Unknown')->nullable();
                $table->string('payment_status')->default('Completed')->nullable();
                $table->text('options')->nullable();
                $table->timestamps();
            });
        }
        
        // Transfer existing data to old table, at the end of it drop table order_pricelist
        if (Schema::hasTable('user_pricelists') and Schema::hasTable('order_pricelist')) {
            $orders = DB::table('orders')
                ->join('order_pricelist', 'orders.id', '=', 'order_pricelist.order_id')
                ->select('orders.*', 'order_pricelist.pricelist_id')
                ->get();
            
            foreach ($orders as $item) {
				// Check if user exists
				if (DB::table('users')->where('id', $item->user_id)->count() > 0) {
					$order_id = DB::table('user_pricelists')->insertGetId([
						'user_id' => $item->user_id,
						'paid' => $item->paid,
						'transaction_id' => $item->transaction_id,
						'payment_status' => $item->payment_status,
						'options' => $item->options,
						'created_at' => $item->created_at,
						'updated_at' => $item->updated_at,
						'pricelist_id' => $item->pricelist_id
					]);
				}
            }
            
            Schema::dropIfExists('order_pricelist');
        }
	}
715878
def downgrade():
    """"""
    ctx = op.get_context()
    insp = Inspector.from_engine(ctx.connection.engine)

    for fk in insp.get_foreign_keys('transaction'):
        if fk['referred_table'] == 'accounts_user':
            op.drop_constraint(
                op.f(fk['name']), 'transaction', type_='foreignkey'
            )

    with op.batch_alter_table('transaction') as batch_op:
        batch_op.drop_index(op.f('ix_transaction_user_id'))
        batch_op.drop_column('user_id')
    op.drop_table('accounts_userrole')
    op.drop_table('accounts_user_session_activity')
    op.drop_table('accounts_user')
    op.drop_table('accounts_role')
922101
def revert(self, snapshot: Tuple[Hash32, UUID]) -> None:
        
        state_root, account_snapshot = snapshot

        # first revert the database state root.
        self._account_db.state_root = state_root
        # now roll the underlying database back
        self._account_db.discard(account_snapshot)
869596
public function down()
    {
        // Check if the 2 tables exist
        if (Schema::hasTable('tags') && Schema::hasTable('taggables')) {
            if (! Schema::hasColumn('tags', 'tagable_id') && ! Schema::hasColumn('tags', 'tagable_type')) {
                Schema::table('tags', function($table) {
                    $table->integer('tagable_id')->default(1);
                    $table->string('tagable_type', 32)->default('type');
                });
                $tags = DB::table('tags')->get();
                foreach ($tags as $tag) {
                    $tagable = DB::table('taggables')->where('tag_id', '=', $tag->id)->first();
                    if ($tagable) {
                        // Points to old namespace Redooor\\Redminportal\\
                        $old_type_array = explode('\\', $tagable->taggable_type);
                        $last_model = array_pop($old_type_array);
                        $old_type = 'Redooor\\Redminportal\\' . $last_model;
                        DB::table('tags')
                            ->where('id', $tag->id)
                            ->update([
                                'tagable_id' => $tagable->taggable_id,
                                'tagable_type' => $old_type
                            ]);
                    }
                }
            }
        }
    }
421537
def down(tag, sql, revision):
    
    alembic_command.downgrade(
        config=get_config(),
        revision=revision,
        sql=sql,
        tag=tag
    )
857662
public function down()
    {
        Schema::table(
            'contents',
            function (Blueprint $table) {
                $table->removeColumn('type');
                $table->removeColumn('published');
            }
        );

        Schema::table(
            'revisions',
            function (Blueprint $table) {
                $table->removeColumn('published');
            }
        );
    }
217783
public function down()
    {
        // Remove columns from products
        if (Schema::hasTable('products')) {
            Schema::table('products', function(Blueprint $table)
            {
                if (Schema::hasColumn('products', 'weight_unit')) {
                    $table->dropColumn('weight_unit');
                }
                if (Schema::hasColumn('products', 'volume_unit')) {
                    $table->dropColumn('volume_unit');
                }
                if (Schema::hasColumn('products', 'length')) {
                    $table->dropColumn('length');
                }
                if (Schema::hasColumn('products', 'width')) {
                    $table->dropColumn('width');
                }
                if (Schema::hasColumn('products', 'height')) {
                    $table->dropColumn('height');
                }
                if (Schema::hasColumn('products', 'weight')) {
                    $table->dropColumn('weight');
                }
            });
        }
    }
982832
public function down()
    {
        Schema::drop('watched_items');
        Schema::drop('failed_jobs');
        Schema::drop('delivery_options');
        Schema::drop('item_categories');
        Schema::drop('items');
        Schema::drop('item_conditions');
        Schema::drop('listing_durations');
        Schema::drop('categories');

        Schema::table('users', function (Blueprint $table) {
            $table->string('username', 255)->change();
            $table->string('email', 255)->change();
            $table->string('password', 60)->change();
            $table->dropColumn('locale');
            $table->dropColumn('currency');
            $table->dropColumn('joined');
            $table->dropColumn('last_login');
            $table->dropColumn('notifications');
            $table->timestamps();

            $table->renameColumn('user_id', 'id');
            $table->renameColumn('username', 'name');
        });
    }
360151
public function down()
    {
        if ( ! $this->hasConnection()) {
            Schema::dropIfExists($this->getTableName());

            return;
        }

        Schema::connection($this->getConnection())->dropIfExists($this->getTableName());
    }
376148
public function down()
    {
        $controller = DB::table('admin_controllers')->select('id')->where('controller', '=', 'adminsearch')->first();
        DB::table('admin_actions')->where('controller_id', '=', $controller->id)->where('action', '=', 'index')->delete();
        DB::table('admin_controllers')->where('id', '=', $controller->id)->delete();
    }
1250400
public function down()
    {
        // remove DB Table:
        $manager = $this->modx->getManager();

        // the class table object name
        $table_class = $this->blender->getBlendClassObject();
        //foreach ($this->blender_table_classes as $table_class) {
            if ($manager->removeObjectContainer($table_class)) {
                $this->blender->out($table_class.' table class has been dropped');

            } else {
                $this->blender->out($table_class.' table class was not dropped', true);
            }
        //}

        // remove events:
        foreach ($this->blender_events as $event_name) {
            $this->removeSystemEvents($event_name);
        }

        /** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */
        $systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('blend.version');
        $systemSetting
            ->setSeedsDir($this->getSeedsDir())
            ->revertBlend();

        foreach ($this->empty_settings as $key) {
            /** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */
            $systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting($key);
            $systemSetting
                ->setSeedsDir($this->getSeedsDir())
                ->revertBlend();
        }

        $this->modx->cacheManager->refresh();
    }
244707
public function down()
    {
        // remove DB Table:
        $manager = $this->modx->getManager();

        // 4. plugin
        $plugin = $this->blender->getBlendableLoader()->getBlendablePlugin('requireComposerAutoloader');

        if ($plugin->revertBlend()) {
            $this->blender->outSuccess('requireComposerAutoloader Plugin has been reverted');
        } else {
            $this->blender->out('requireComposerAutoloader Plugin could not be reverted', true);
        }

        // 3. System setting
        /** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */
        $systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('orchestrator.vendor_path');
        if ($systemSetting->revertBlend()) {
            $this->blender->outSuccess('orchestrator.vendor_path System Setting has been reverted');
        } else {
            $this->blender->out('orchestrator.vendor_path System Setting could not be reverted', true);
        }

        // 2. Media source
        $orchestratorMediaSource = $this->blender->getBlendableLoader()->getBlendableMediaSource('orchestrator');
        if ($orchestratorMediaSource->revertBlend()) {
            $this->blender->outSuccess('orchestrator MediaSource has been reverted');
        } else {
            $this->blender->out('orchestrator MediaSource could not be reverted', true);
        }

        // 1. MODX namespace
        /** @var \modNamespace $orchestratorNamespace */
        $orchestratorNamespace = $this->modx->getObject('modNamespace', 'orchestrator');

        if ($orchestratorNamespace instanceof \modNamespace) {
            if ($orchestratorNamespace->remove()) {
                $this->blender->outSuccess('orchestrator modNamespace has been removed');
            } else {
                $this->blender->out('orchestrator modNamespace could not be removed', true);
            }
        }

        $this->modx->cacheManager->refresh();
    }
485804
def dropdb():
    """"""
    manager.db.engine.echo = True
    if prompt_bool("Are you sure you want to lose all your data"):
        manager.db.drop_all()
        metadata, alembic_version = alembic_table_metadata()
        alembic_version.drop()
        manager.db.session.commit()