From 0ef66bfc5fa9e23fac5303787458127052acd5b0 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Sat, 27 Apr 2019 17:22:27 +0800 Subject: [PATCH] =?UTF-8?q?[migration][=E6=96=B0=E5=A2=9E]:flyway=20java?= =?UTF-8?q?=20migration=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mallinkAdmin/pom.xml | 1 + .../V201904271650__Update_User_Role.java | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 mallinkAdmin/src/main/java/com/iformall/migration/V201904271650__Update_User_Role.java diff --git a/mallinkAdmin/pom.xml b/mallinkAdmin/pom.xml index e16314f1e..b2fe26629 100644 --- a/mallinkAdmin/pom.xml +++ b/mallinkAdmin/pom.xml @@ -49,6 +49,7 @@ org.flywaydb flyway-core + 5.2.4 diff --git a/mallinkAdmin/src/main/java/com/iformall/migration/V201904271650__Update_User_Role.java b/mallinkAdmin/src/main/java/com/iformall/migration/V201904271650__Update_User_Role.java new file mode 100644 index 000000000..977183761 --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/migration/V201904271650__Update_User_Role.java @@ -0,0 +1,48 @@ +package com.iformall.migration; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +public class V201904271650__Update_User_Role extends BaseJavaMigration { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final String getTenantIdList = "SELECT tenant_id FROM wx_mall WHERE tenant_id like '%100%'"; + + public void migrate(Context context) throws Exception { + // 获取 tenantId list + // 获取 mall_user_role + /* + try (Statement select = context.getConnection().createStatement()) { + try (ResultSet rows = select.executeQuery(getTenantIdList)) { + while (rows.next()) { + int id = rows.getInt(1); + String anonymizedName = "Anonymous" + id; + try (Statement update = context.getConnection().createStatement()) { + update.execute("UPDATE person SET name='" + anonymizedName + "' WHERE id=" + id); + } + } + } + } + */ + } + + private List getTenantList(Context context) throws Exception { + List tlist = new ArrayList(); + try (Statement select = context.getConnection().createStatement()) { + try (ResultSet rows = select.executeQuery(getTenantIdList)) { + while (rows.next()) { + tlist.add(rows.getString(0)); + } + } + } + return tlist; + } +}