package com.atlassian.bitbucket.internal.key.ssh.dao.v2;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.activeobjects.external.ActiveObjectsUpgradeTask;
import com.atlassian.activeobjects.external.ModelVersion;
import com.atlassian.bitbucket.internal.key.ssh.dao.v1.AoSshAccessKeyV1;
import com.atlassian.bitbucket.internal.key.ssh.dao.v1.AoSshKeyV1;

import static com.google.common.base.Preconditions.checkState;

public class ApplySchemaChangesV2Task implements ActiveObjectsUpgradeTask {
    @Override
    public ModelVersion getModelVersion() {
        // This should always represent the version this upgrade task upgrades *to*
        return ModelVersion.valueOf("2");
    }

    @Override
    public void upgrade(ModelVersion currentVersion, ActiveObjects ao) {
        checkState(currentVersion.isSame(ModelVersion.valueOf("1")),
                "This upgrade task can only upgrade from version 1 to 2");

        ao.migrateDestructively(AoSshKeyV1.class, AoSshAccessKeyV1.class);
    }
}
