This is an automated email from the git hooks/post-receive script. New commit to branch feature/44_several_email_address in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 36c7fa73ad5ee0e2b7263392e617784d2c3ecc70 Author: Kevin Morin <morin@codelutin.com> Date: Mon Oct 9 18:15:06 2017 +0200 refs #44 correction de la migration --- .../V3_1_0_5__Extract_email_addresses.java} | 30 ++++++++++++---------- .../h2/V3_1_0_4__add_email_address_table.sql | 13 ++++++++++ .../h2/V3_1_0_6__drop_email_from_user.sql | 2 ++ .../V3_1_0_4__add_email_address_table.sql | 13 ++++++++++ .../postgresql/V3_1_0_6__drop_email_from_user.sql | 2 ++ pollen-persistence/src/main/xmi/pollen.properties | 2 +- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/pollen-persistence/src/main/java/db/migration/V3_0_1_4__Extract_email_addresses.java b/pollen-persistence/src/main/java/db/migration/common/V3_1_0_5__Extract_email_addresses.java similarity index 68% rename from pollen-persistence/src/main/java/db/migration/V3_0_1_4__Extract_email_addresses.java rename to pollen-persistence/src/main/java/db/migration/common/V3_1_0_5__Extract_email_addresses.java index ea0fb3a4..677ab47b 100644 --- a/pollen-persistence/src/main/java/db/migration/V3_0_1_4__Extract_email_addresses.java +++ b/pollen-persistence/src/main/java/db/migration/common/V3_1_0_5__Extract_email_addresses.java @@ -11,20 +11,20 @@ import org.nuiton.topia.persistence.internal.ShortTopiaIdFactory; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.Statement; +import java.sql.Timestamp; /** * @author Kevin Morin (Code Lutin) */ -public class V3_0_1_4__Extract_email_addresses implements JdbcMigration { +public class V3_1_0_5__Extract_email_addresses implements JdbcMigration { /** Logger. */ - private static final Log log = LogFactory.getLog(V3_0_1_4__Extract_email_addresses.class); + private static final Log log = LogFactory.getLog(V3_1_0_5__Extract_email_addresses.class); @Override public void migrate(Connection connection) throws Exception { - Statement insertStatement = null; + PreparedStatement insertStatement = null; PreparedStatement updateStatement = null; ResultSet resultSet = null; @@ -33,9 +33,9 @@ public class V3_0_1_4__Extract_email_addresses implements JdbcMigration { try { connection.setAutoCommit(false); - insertStatement = connection.createStatement(); - StringBuilder query = new StringBuilder("INSERT INTO POLLENUSEREMAILADDRESS VALUES "); - + insertStatement = connection.prepareStatement("INSERT INTO POLLENUSEREMAILADDRESS " + + "(TOPIAID, TOPIAVERSION, TOPIACREATEDATE, EMAILADDRESS, ACTIVATIONTOKEN, POLLENUSER) " + + "VALUES (?, ?, ?, ?, ?, ?)"); updateStatement = connection.prepareStatement("UPDATE pollenuser SET DEFAULTEMAILADDRESS = ? WHERE topiaid = ?"); @@ -47,20 +47,22 @@ public class V3_0_1_4__Extract_email_addresses implements JdbcMigration { String userTopiaId = resultSet.getString(1); String emailAddress = resultSet.getString(2); String emailTokenActivation = resultSet.getString(3); - String addressTopiaId = shortTopiaIdFactory.newTopiaId(PollenUserEmailAddress.class, (TopiaEntity) null); - query.append("(").append(addressTopiaId).append(",") - .append("1 , NOW(),") - .append("'").append(emailAddress).append("',") - .append("'").append(emailTokenActivation).append("',") - .append("'").append(userTopiaId).append("')"); + + insertStatement.setString(1, addressTopiaId); + insertStatement.setInt(2, 1); + insertStatement.setTimestamp(3, new Timestamp(System.currentTimeMillis())); + insertStatement.setString(4,emailAddress); + insertStatement.setString(5, emailTokenActivation); + insertStatement.setString(6, userTopiaId); + insertStatement.addBatch(); updateStatement.setString(1, addressTopiaId); updateStatement.setString(2, userTopiaId); updateStatement.addBatch(); } - insertStatement.execute(query.toString()); + insertStatement.executeBatch(); updateStatement.executeBatch(); resultSet.close(); diff --git a/pollen-persistence/src/main/resources/db/migration/h2/V3_1_0_4__add_email_address_table.sql b/pollen-persistence/src/main/resources/db/migration/h2/V3_1_0_4__add_email_address_table.sql new file mode 100644 index 00000000..e5031ae4 --- /dev/null +++ b/pollen-persistence/src/main/resources/db/migration/h2/V3_1_0_4__add_email_address_table.sql @@ -0,0 +1,13 @@ +CREATE TABLE POLLENUSEREMAILADDRESS ( + TOPIAID VARCHAR(255) NOT NULL PRIMARY KEY, + TOPIAVERSION BIGINT NOT NULL, + TOPIACREATEDATE TIMESTAMP, + EMAILADDRESS VARCHAR(255), + ACTIVATIONTOKEN VARCHAR(255), + POLLENUSER VARCHAR(255), + FOREIGN KEY (ACTIVATIONTOKEN) REFERENCES POLLENTOKEN(TOPIAID), + FOREIGN KEY (POLLENUSER) REFERENCES POLLENUSER(TOPIAID) +); + +ALTER TABLE POLLENUSER ADD DEFAULTEMAILADDRESS VARCHAR(255); +ALTER TABLE POLLENUSER ADD FOREIGN KEY (DEFAULTEMAILADDRESS) REFERENCES POLLENUSEREMAILADDRESS(TOPIAID); \ No newline at end of file diff --git a/pollen-persistence/src/main/resources/db/migration/h2/V3_1_0_6__drop_email_from_user.sql b/pollen-persistence/src/main/resources/db/migration/h2/V3_1_0_6__drop_email_from_user.sql new file mode 100644 index 00000000..5a6f68ab --- /dev/null +++ b/pollen-persistence/src/main/resources/db/migration/h2/V3_1_0_6__drop_email_from_user.sql @@ -0,0 +1,2 @@ +ALTER TABLE POLLENUSER DROP EMAIL; +ALTER TABLE POLLENUSER DROP EMAILACTIVATIONTOKEN; \ No newline at end of file diff --git a/pollen-persistence/src/main/resources/db/migration/postgresql/V3_1_0_4__add_email_address_table.sql b/pollen-persistence/src/main/resources/db/migration/postgresql/V3_1_0_4__add_email_address_table.sql new file mode 100644 index 00000000..e5031ae4 --- /dev/null +++ b/pollen-persistence/src/main/resources/db/migration/postgresql/V3_1_0_4__add_email_address_table.sql @@ -0,0 +1,13 @@ +CREATE TABLE POLLENUSEREMAILADDRESS ( + TOPIAID VARCHAR(255) NOT NULL PRIMARY KEY, + TOPIAVERSION BIGINT NOT NULL, + TOPIACREATEDATE TIMESTAMP, + EMAILADDRESS VARCHAR(255), + ACTIVATIONTOKEN VARCHAR(255), + POLLENUSER VARCHAR(255), + FOREIGN KEY (ACTIVATIONTOKEN) REFERENCES POLLENTOKEN(TOPIAID), + FOREIGN KEY (POLLENUSER) REFERENCES POLLENUSER(TOPIAID) +); + +ALTER TABLE POLLENUSER ADD DEFAULTEMAILADDRESS VARCHAR(255); +ALTER TABLE POLLENUSER ADD FOREIGN KEY (DEFAULTEMAILADDRESS) REFERENCES POLLENUSEREMAILADDRESS(TOPIAID); \ No newline at end of file diff --git a/pollen-persistence/src/main/resources/db/migration/postgresql/V3_1_0_6__drop_email_from_user.sql b/pollen-persistence/src/main/resources/db/migration/postgresql/V3_1_0_6__drop_email_from_user.sql new file mode 100644 index 00000000..5a6f68ab --- /dev/null +++ b/pollen-persistence/src/main/resources/db/migration/postgresql/V3_1_0_6__drop_email_from_user.sql @@ -0,0 +1,2 @@ +ALTER TABLE POLLENUSER DROP EMAIL; +ALTER TABLE POLLENUSER DROP EMAILACTIVATIONTOKEN; \ No newline at end of file diff --git a/pollen-persistence/src/main/xmi/pollen.properties b/pollen-persistence/src/main/xmi/pollen.properties index f20c6e9f..ca28eb99 100644 --- a/pollen-persistence/src/main/xmi/pollen.properties +++ b/pollen-persistence/src/main/xmi/pollen.properties @@ -18,7 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # #L% ###m -model.tagvalue.version=3.1.0.5 +model.tagvalue.version=3.1.0.6 #model.tagValue.notGenerateToString=true #model.tagValue.constantPrefix=PROPERTY_ #model.tagValue.useEnumerationName=true -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.