feat(database): simplify index creation for images table
This commit is contained in:
parent
cfcf954a4c
commit
b90954c0d4
@ -1,10 +1,6 @@
|
||||
package db.migration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.Statement;
|
||||
import javax.sql.DataSource;
|
||||
import org.flywaydb.core.api.configuration.Configuration;
|
||||
import org.flywaydb.core.api.migration.BaseJavaMigration;
|
||||
import org.flywaydb.core.api.migration.Context;
|
||||
|
||||
@ -12,25 +8,8 @@ public class V0017__AddIndexImagesObjectKey extends BaseJavaMigration {
|
||||
|
||||
@Override
|
||||
public void migrate(Context context) throws Exception {
|
||||
Configuration config = context.getConfiguration();
|
||||
|
||||
try (Connection conn = getFreshConnection(config);
|
||||
Statement stmt = conn.createStatement()) {
|
||||
stmt.execute(
|
||||
"CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_images_object_key ON images(object_key)");
|
||||
try (Statement stmt = context.getConnection().createStatement()) {
|
||||
stmt.execute("CREATE INDEX IF NOT EXISTS idx_images_object_key ON images(object_key)");
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getFreshConnection(Configuration config) throws Exception {
|
||||
DataSource dataSource = config.getDataSource();
|
||||
if (dataSource != null) {
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
return DriverManager.getConnection(config.getUrl(), config.getUser(), config.getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteInTransaction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user