001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.upgrade.v6_0_0;
016    
017    import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018    import com.liferay.portal.kernel.upgrade.util.TempUpgradeColumnImpl;
019    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
020    import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
021    import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
022    import com.liferay.portal.kernel.util.LoggingTimer;
023    import com.liferay.portal.upgrade.util.BlogsEntryUrlTitleUpgradeColumnImpl;
024    import com.liferay.portal.upgrade.v6_0_0.util.BlogsEntryTable;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class UpgradeBlogs extends UpgradeProcess {
030    
031            @Override
032            protected void doUpgrade() throws Exception {
033                    upgradeBlogEntryTable();
034            }
035    
036            protected void upgradeBlogEntryTable() throws Exception {
037                    try (LoggingTimer loggingTimer = new LoggingTimer()) {
038                            try {
039                                    runSQL("drop index IX_E0D90212 on BlogsEntry");
040                                    runSQL("drop index IX_DA53AFD4 on BlogsEntry");
041                                    runSQL("drop index IX_B88E740E on BlogsEntry");
042    
043                                    runSQL("alter table BlogsEntry drop column draft");
044                            }
045                            catch (Exception e) {
046                            }
047    
048                            UpgradeColumn entryIdColumn = new TempUpgradeColumnImpl("entryId");
049    
050                            UpgradeColumn titleColumn = new TempUpgradeColumnImpl("title");
051    
052                            UpgradeColumn urlTitleColumn =
053                                    new BlogsEntryUrlTitleUpgradeColumnImpl(
054                                            entryIdColumn, titleColumn);
055    
056                            UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
057                                    BlogsEntryTable.TABLE_NAME, BlogsEntryTable.TABLE_COLUMNS,
058                                    entryIdColumn, titleColumn, urlTitleColumn);
059    
060                            upgradeTable.updateTable();
061                    }
062            }
063    
064    }