package flyway.sample;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.flywaydb.core.api.migration.jdbc.JdbcMigration;

import fi.nls.oskari.util.FlywayHelper;
import fi.nls.oskari.util.PropertyUtil;
import fi.nls.oskari.map.view.ViewService;
import fi.nls.oskari.map.view.ViewServiceIbatisImpl;

public class V1_0_12__add_download_basket_to_views implements JdbcMigration {

	private static final ViewService VIEW_SERVICE = new ViewServiceIbatisImpl();
	private static final String DOWNLOAD_BASKET = "download-basket";

	public void migrate(Connection connection) throws Exception {
        if(PropertyUtil.getOptional("flyway.sample.1_0_12.skip", true)) {
            return;
        }
		long viewId = VIEW_SERVICE.getDefaultViewId();
		makeInsert(viewId,connection);
	}

	private void makeInsert(long viewId, Connection connection) throws Exception {

		final PreparedStatement statement = connection.prepareStatement("INSERT INTO portti_view_bundle_seq"
				+ "(view_id, bundle_id, seqno, config, state, startup, bundleinstance) " + "VALUES (" + "?, "
				+ "(SELECT id FROM portti_bundle WHERE name=?), "
				+ "(SELECT max(seqno)+1 FROM portti_view_bundle_seq WHERE view_id=?), " + "?, ?, "
				+ "(SELECT startup FROM portti_bundle WHERE name=?), " + "?)");

		statement.setLong(1, viewId);
		statement.setString(2, DOWNLOAD_BASKET);
		statement.setLong(3, viewId);
		statement.setString(4, "{}");
		statement.setString(5, "{}");
		statement.setString(6, DOWNLOAD_BASKET);
		statement.setString(7, DOWNLOAD_BASKET);

		try {
			statement.execute();
		} finally {
			statement.close();
		}
	}
}

package flyway.sample;

import fi.nls.oskari.util.FlywayHelper;
import fi.nls.oskari.util.PropertyUtil;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;

import java.sql.Connection;
import java.util.List;

/**
 * Migration is skipped by default!
 *
 * Add "flyway.sample.1_0_12.skip=false" in oskari-ext.properties to add
 * download-basket for all default and user views.
 *
 */
public class V1_0_12__add_download_basket_to_views implements JdbcMigration {

    private static final String BUNDLE_ID = "download-basket";

    public void migrate(Connection connection) throws Exception {
        if (PropertyUtil.getOptional("flyway.sample.1_0_12.skip", true)) {
            return;
        }

        final List<Long> views = FlywayHelper.getUserAndDefaultViewIds(connection);
        for (Long viewId : views) {
            if (FlywayHelper.viewContainsBundle(connection, BUNDLE_ID, viewId)) {
                continue;
            }
            FlywayHelper.addBundleWithDefaults(connection, viewId, BUNDLE_ID);
        }
    }
}

Add download-basket to personal views as well as default view