UpgradeCatalog242 extends AbstractUpgradeCatalog { protected void updateTablesForMysql() throws SQLException { final Configuration.DatabaseType databaseType = configuration.getDatabaseType(); if (databaseType == Configuration.DatabaseType.MYSQL) { dbAccessor.alterColumn(EXTENSION_TABLE, new DBAccessor.DBColumnInfo(EXTENSION_NAME_COLUMN, String.class, 100, null, false)); dbAccessor.alterColumn(EXTENSION_TABLE, new DBAccessor.DBColumnInfo(EXTENSION_VERSION_COLUMN, String.class, 100, null, false)); dbAccessor.alterColumn(USERS_TABLE, new DBAccessor.DBColumnInfo(USER_TYPE_COLUMN, String.class, 100, null, false)); dbAccessor.alterColumn(USERS_TABLE, new DBAccessor.DBColumnInfo(USER_NAME_COLUMN, String.class, 100, null, false)); dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBAccessor.DBColumnInfo(ROLE_COLUMN, String.class, 100, null, true)); dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBAccessor.DBColumnInfo(STATUS_COLUMN, String.class, 100, null, true)); dbAccessor.dropFKConstraint(HOST_GROUP_TABLE, "FK_hg_blueprint_name"); dbAccessor.dropFKConstraint(HOST_GROUP_TABLE, "FK_hostgroup_blueprint_name"); dbAccessor.dropFKConstraint(BLUEPRINT_CONFIGURATION, "FK_cfg_blueprint_name"); dbAccessor.dropFKConstraint(BLUEPRINT_CONFIGURATION, "FK_blueprint_configuration_blueprint_name"); dbAccessor.dropFKConstraint(BLUEPRINT_SETTING, "FK_blueprint_setting_blueprint_name"); dbAccessor.dropFKConstraint(BLUEPRINT_SETTING, "FK_blueprint_setting_name"); dbAccessor.alterColumn(BLUEPRINT_TABLE, new DBAccessor.DBColumnInfo(BLUEPRINT_NAME_COLUMN, String.class, 100, null, false)); String[] uniqueColumns1 = new String[] { BLUEPRINT_NAME_COLUMN }; dbAccessor.addFKConstraint(HOST_GROUP_TABLE, "FK_hg_blueprint_name", uniqueColumns1, BLUEPRINT_TABLE, uniqueColumns1, false); dbAccessor.addFKConstraint(BLUEPRINT_CONFIGURATION, "FK_cfg_blueprint_name", uniqueColumns1, BLUEPRINT_TABLE, uniqueColumns1, false); dbAccessor.addFKConstraint(BLUEPRINT_SETTING, "FK_blueprint_setting_name", uniqueColumns1, BLUEPRINT_TABLE, uniqueColumns1, false); } } @Inject  UpgradeCatalog242(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion();  }
@Test public void testUpdateTablesForMysql() throws Exception{ final DBAccessor dbAccessor = createNiceMock(DBAccessor.class); final Configuration configuration = createNiceMock(Configuration.class); Capture<DBAccessor.DBColumnInfo> extensionExtensionNameColumnChangeSize = newCapture(); Capture<DBAccessor.DBColumnInfo> extensionExtensionVersionColumnChangeSize = newCapture(); Capture<DBAccessor.DBColumnInfo> usersUserTypeColumnChangeSize = newCapture(); Capture<DBAccessor.DBColumnInfo> usersUserNameColumnChangeSize = newCapture(); Capture<DBAccessor.DBColumnInfo> hostRoleCommandRoleColumnChangeSize = newCapture(); Capture<DBAccessor.DBColumnInfo> hostRoleCommandStatusColumnChangeSize = newCapture(); Capture<DBAccessor.DBColumnInfo> blueprintBlueprintNameColumnChangeSize = newCapture(); expect(configuration.getDatabaseType()).andReturn(Configuration.DatabaseType.MYSQL).once(); dbAccessor.alterColumn(eq(UpgradeCatalog242.EXTENSION_TABLE), capture(extensionExtensionNameColumnChangeSize)); dbAccessor.alterColumn(eq(UpgradeCatalog242.EXTENSION_TABLE), capture(extensionExtensionVersionColumnChangeSize)); dbAccessor.alterColumn(eq(UpgradeCatalog242.USERS_TABLE), capture(usersUserTypeColumnChangeSize)); dbAccessor.alterColumn(eq(UpgradeCatalog242.USERS_TABLE), capture(usersUserNameColumnChangeSize)); dbAccessor.alterColumn(eq(UpgradeCatalog242.HOST_ROLE_COMMAND_TABLE), capture(hostRoleCommandRoleColumnChangeSize)); dbAccessor.alterColumn(eq(UpgradeCatalog242.HOST_ROLE_COMMAND_TABLE), capture(hostRoleCommandStatusColumnChangeSize)); dbAccessor.dropFKConstraint(eq(UpgradeCatalog242.HOST_GROUP_TABLE), eq("FK_hg_blueprint_name")); dbAccessor.dropFKConstraint(eq(UpgradeCatalog242.HOST_GROUP_TABLE), eq("FK_hostgroup_blueprint_name")); dbAccessor.dropFKConstraint(eq(UpgradeCatalog242.BLUEPRINT_CONFIGURATION), eq("FK_cfg_blueprint_name")); dbAccessor.dropFKConstraint(eq(UpgradeCatalog242.BLUEPRINT_CONFIGURATION), eq("FK_blueprint_configuration_blueprint_name")); dbAccessor.dropFKConstraint(eq(UpgradeCatalog242.BLUEPRINT_SETTING), eq("FK_blueprint_setting_blueprint_name")); dbAccessor.dropFKConstraint(eq(UpgradeCatalog242.BLUEPRINT_SETTING), eq("FK_blueprint_setting_name")); dbAccessor.alterColumn(eq(UpgradeCatalog242.BLUEPRINT_TABLE), capture(blueprintBlueprintNameColumnChangeSize)); dbAccessor.addFKConstraint(eq(UpgradeCatalog242.HOST_GROUP_TABLE), eq("FK_hg_blueprint_name"), aryEq(new String[]{"blueprint_name"}), eq(UpgradeCatalog242.BLUEPRINT_TABLE), aryEq(new String[]{"blueprint_name"}), eq(false)); dbAccessor.addFKConstraint(eq(UpgradeCatalog242.BLUEPRINT_CONFIGURATION), eq("FK_cfg_blueprint_name"), aryEq(new String[]{"blueprint_name"}), eq(UpgradeCatalog242.BLUEPRINT_TABLE), aryEq(new String[]{"blueprint_name"}), eq(false)); dbAccessor.addFKConstraint(eq(UpgradeCatalog242.BLUEPRINT_SETTING), eq("FK_blueprint_setting_name"), aryEq(new String[]{"blueprint_name"}), eq(UpgradeCatalog242.BLUEPRINT_TABLE), aryEq(new String[]{"blueprint_name"}), eq(false)); replay(dbAccessor, configuration); Module module = new Module() { @Override public void configure(Binder binder) { binder.bind(DBAccessor.class).toInstance(dbAccessor); binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); binder.bind(EntityManager.class).toInstance(entityManager); binder.bind(Configuration.class).toInstance(configuration); } }; Injector injector = Guice.createInjector(module); UpgradeCatalog242 upgradeCatalog242 = injector.getInstance(UpgradeCatalog242.class); upgradeCatalog242.executeDDLUpdates(); DBAccessor.DBColumnInfo extensionExtensionNameInfo = extensionExtensionNameColumnChangeSize.getValue(); Assert.assertNotNull(extensionExtensionNameInfo); Assert.assertEquals(UpgradeCatalog242.EXTENSION_NAME_COLUMN, extensionExtensionNameInfo.getName()); Assert.assertEquals(new Integer(100), extensionExtensionNameInfo.getLength()); Assert.assertEquals(String.class, extensionExtensionNameInfo.getType()); Assert.assertEquals(null, extensionExtensionNameInfo.getDefaultValue()); Assert.assertEquals(false, extensionExtensionNameInfo.isNullable()); DBAccessor.DBColumnInfo extensionExtensionVersionInfo = extensionExtensionVersionColumnChangeSize.getValue(); Assert.assertNotNull(extensionExtensionVersionInfo); Assert.assertEquals(UpgradeCatalog242.EXTENSION_VERSION_COLUMN, extensionExtensionVersionInfo.getName()); Assert.assertEquals(new Integer(100), extensionExtensionVersionInfo.getLength()); Assert.assertEquals(String.class, extensionExtensionVersionInfo.getType()); Assert.assertEquals(null, extensionExtensionVersionInfo.getDefaultValue()); Assert.assertEquals(false, extensionExtensionVersionInfo.isNullable()); DBAccessor.DBColumnInfo usersUserTypeInfo = usersUserTypeColumnChangeSize.getValue(); Assert.assertNotNull(usersUserTypeInfo); Assert.assertEquals(UpgradeCatalog242.USER_TYPE_COLUMN, usersUserTypeInfo.getName()); Assert.assertEquals(new Integer(100), usersUserTypeInfo.getLength()); Assert.assertEquals(String.class, usersUserTypeInfo.getType()); Assert.assertEquals(null, usersUserTypeInfo.getDefaultValue()); Assert.assertEquals(false, usersUserTypeInfo.isNullable()); DBAccessor.DBColumnInfo usersUserNameInfo = usersUserNameColumnChangeSize.getValue(); Assert.assertNotNull(usersUserNameInfo); Assert.assertEquals(UpgradeCatalog242.USER_NAME_COLUMN, usersUserNameInfo.getName()); Assert.assertEquals(new Integer(100), usersUserNameInfo.getLength()); Assert.assertEquals(String.class, usersUserNameInfo.getType()); Assert.assertEquals(null, usersUserNameInfo.getDefaultValue()); Assert.assertEquals(false, usersUserNameInfo.isNullable()); DBAccessor.DBColumnInfo hostRoleCommandRoleInfo = hostRoleCommandRoleColumnChangeSize.getValue(); Assert.assertNotNull(hostRoleCommandRoleInfo); Assert.assertEquals(UpgradeCatalog242.ROLE_COLUMN, hostRoleCommandRoleInfo.getName()); Assert.assertEquals(new Integer(100), hostRoleCommandRoleInfo.getLength()); Assert.assertEquals(String.class, hostRoleCommandRoleInfo.getType()); Assert.assertEquals(null, hostRoleCommandRoleInfo.getDefaultValue()); Assert.assertEquals(true, hostRoleCommandRoleInfo.isNullable()); DBAccessor.DBColumnInfo hostRoleCommandStatusInfo = hostRoleCommandStatusColumnChangeSize.getValue(); Assert.assertNotNull(hostRoleCommandStatusInfo); Assert.assertEquals(UpgradeCatalog242.STATUS_COLUMN, hostRoleCommandStatusInfo.getName()); Assert.assertEquals(new Integer(100), hostRoleCommandStatusInfo.getLength()); Assert.assertEquals(String.class, hostRoleCommandStatusInfo.getType()); Assert.assertEquals(null, hostRoleCommandStatusInfo.getDefaultValue()); Assert.assertEquals(true, hostRoleCommandStatusInfo.isNullable()); DBAccessor.DBColumnInfo blueprintBlueprintNameInfo = blueprintBlueprintNameColumnChangeSize.getValue(); Assert.assertNotNull(blueprintBlueprintNameInfo); Assert.assertEquals(UpgradeCatalog242.BLUEPRINT_NAME_COLUMN, blueprintBlueprintNameInfo.getName()); Assert.assertEquals(new Integer(100), blueprintBlueprintNameInfo.getLength()); Assert.assertEquals(String.class, blueprintBlueprintNameInfo.getType()); Assert.assertEquals(null, blueprintBlueprintNameInfo.getDefaultValue()); Assert.assertEquals(false, blueprintBlueprintNameInfo.isNullable()); verify(dbAccessor, configuration); }