Migrate database downwards?

Does Nextcloud only support apps migrating the database up, not down?

You mean for an app to undo a migration?

No, this is not possible at the moment as far as i know.

Reasoning: you are manually writing the migrations including the changes involved in the structure of the data. So, in fact, you are responsible for the migration itself. The core just triggers your code in the right moment. There is however no code provided by you too undo any migration. So, the core would not know what to do there.

I guess that’s an accurate description. I’m talking about when you have an app installed in version X and you uninstall that and install the same app in a lower version, e.g. X-1.

Generally speaking, a properly designed migration framework should IMO support migrating both up and down. A good example is the Yii framework migrations, here’s an super basic example code snippet:

<?php

use yii\db\Migration;

class m150101_185401_create_news_table extends Migration
{
    public function up()
    {
        $this->createTable('news', [
            'id' => $this->primaryKey(),
            'title' => $this->string()->notNull(),
            'content' => $this->text(),
        ]);
    }

    public function down()
    {
        $this->dropTable('news');
    }
}

One can of course write anything in these migrations, such as more detailed modifications of the database, processing of data as part of the migration, and even not just DB related stuff if that’s what floats your boat.

That’s exactly what I was wondering if it is supported by Nextcloud, but I take it then that Nextcloud only supports migrating up and not down.

That is exactly my understanding of the framework. Sorry

Thanks for always trying to help (and oftentimes succeeding ;)!

1 Like