protected String normalizeTableName(liquibase.structure.core.Table table, DatabaseSnapshot databaseSnapshot) { //Work around MySQL & case-insensitive dbs liquibase.structure.core.Table fkTable = databaseSnapshot.get(table); String fkTableName; if(fkTable != null) { fkTableName = fkTable.getName(); } else { logger.warn("Could not normalize table name: " + table.getName() + "; most probably this is a sign of a foreign key to another schema, which is not supported at the moment."); fkTableName = null; } return fkTableName; }
protected String normalizeTableName(liquibase.structure.core.Table table, DatabaseSnapshot databaseSnapshot) { //Work around MySQL & case-insensitive dbs liquibase.structure.core.Table fkTable = databaseSnapshot.get(table); String fkTableName; if(fkTable != null) { fkTableName = fkTable.getName(); } else { logger.warn("Could not normalize table name: " + table.getName() + "; most probably this is a sign of a foreign key to another schema, which is not supported at the moment."); fkTableName = null; } return fkTableName; }
protected void syncTables(DatabaseSnapshot databaseSnapshot, Schema sourceSchema, Schema targetSchema) { logger.info("Synchronizing tables"); for (liquibase.structure.core.Table liquibaseTable : databaseSnapshot.get(liquibase.structure.core.Table.class)) { String tableName = liquibaseTable.getName(); logger.info("Processing table: {}", tableName); Table sourceTable = DatabaseLogic.findTableByNameIgnoreCase(sourceSchema, tableName); if(sourceTable == null) { logger.debug("Added new table: {}", tableName); sourceTable = new Table(); } Table targetTable = new Table(targetSchema); targetSchema.getTables().add(targetTable); targetTable.setTableName(tableName); logger.debug("Merging table attributes and annotations"); targetTable.setEntityName(sourceTable.getEntityName()); targetTable.setJavaClass(sourceTable.getJavaClass()); targetTable.setShortName(sourceTable.getShortName()); copyAnnotations(sourceTable, targetTable); syncColumns(liquibaseTable, sourceTable, targetTable); copySelectionProviders(sourceTable, targetTable); } }
protected void syncTables(DatabaseSnapshot databaseSnapshot, Schema sourceSchema, Schema targetSchema) { logger.info("Synchronizing tables"); for (liquibase.structure.core.Table liquibaseTable : databaseSnapshot.get(liquibase.structure.core.Table.class)) { String tableName = liquibaseTable.getName(); logger.info("Processing table: {}", tableName); Table sourceTable = DatabaseLogic.findTableByNameIgnoreCase(sourceSchema, tableName); if(sourceTable == null) { logger.debug("Added new table: {}", tableName); sourceTable = new Table(); } Table targetTable = new Table(targetSchema); targetSchema.getTables().add(targetTable); targetTable.setTableName(tableName); logger.debug("Merging table attributes and annotations"); targetTable.setEntityName(sourceTable.getEntityName()); targetTable.setJavaClass(sourceTable.getJavaClass()); targetTable.setShortName(sourceTable.getShortName()); copyAnnotations(sourceTable, targetTable); syncColumns(liquibaseTable, sourceTable, targetTable); copySelectionProviders(sourceTable, targetTable); } }
protected void syncPrimaryKeys(DatabaseSnapshot databaseSnapshot, Schema sourceSchema, Schema targetSchema) { logger.info("Synchronizing primary keys"); for(liquibase.structure.core.PrimaryKey liquibasePK : databaseSnapshot.get(liquibase.structure.core.PrimaryKey.class)) { String pkTableName = liquibasePK.getTable().getName();
protected void syncPrimaryKeys(DatabaseSnapshot databaseSnapshot, Schema sourceSchema, Schema targetSchema) { logger.info("Synchronizing primary keys"); for(liquibase.structure.core.PrimaryKey liquibasePK : databaseSnapshot.get(liquibase.structure.core.PrimaryKey.class)) { String pkTableName = liquibasePK.getTable().getName();
UniqueConstraint uniqueConstraint = new UniqueConstraint(); uniqueConstraint.setTable(table); String name = "UC_" + table.getName().toUpperCase() + column.getName().toUpperCase() + "_COL"; if (name.length() > 64) { name = name.substring(0, 63); UniqueConstraint uc = ucIter.next(); if (uc.getName() == null || uc.getName().isEmpty()) { String name = table.getName() + uc.getColumnNames(); name = "UCIDX" + hashedName(name); uc.setName(name);
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(Table.class)) { return; } if (foundObject instanceof Schema) { Schema schema = (Schema) foundObject; HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase(); Configuration cfg = database.getConfiguration(); Iterator<org.hibernate.mapping.Table> tableMappings = cfg.getTableMappings(); while (tableMappings.hasNext()) { org.hibernate.mapping.Table hibernateTable = tableMappings.next(); if (hibernateTable.isPhysicalTable()) { Table table = new Table().setName(hibernateTable.getName()); table.setSchema(schema); LOG.info("Found table " + table.getName()); schema.addDatabaseObject(table); } } } } }
@Override protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (example.getSnapshotId() != null) { return example; } org.hibernate.mapping.Table hibernateTable = findHibernateTable(example, snapshot); if (hibernateTable == null) { return example; } Table table = new Table().setName(hibernateTable.getName()); LOG.info("Found table " + table.getName()); // table.setSnapshotId(SnapshotIdService.getInstance().generateId()); table.setSchema(example.getSchema()); return table; }
String deploymentId = changelogHistoryService.getDeploymentId(); logger.debugv("Adding missing column {0}={1} to {2} table", DEPLOYMENT_ID_COLUMN, deploymentId,changelogTable.getName()); changelogTable.getName(), DEPLOYMENT_ID_COLUMN, "VARCHAR(10)", null)); statementsToExecute.add(new UpdateStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), changelogTable.getName()) .addNewColumnValue(DEPLOYMENT_ID_COLUMN, deploymentId)); statementsToExecute.add(new SetNullableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), changelogTable.getName(), DEPLOYMENT_ID_COLUMN, "VARCHAR(10)", false));
Table table = new Table().setName(hibernateTable.getName()); table.setSchema(schema); LOG.info("Found table " + table.getName()); schema.addDatabaseObject(snapshotObject(table, snapshot)); Table table = new Table().setName(hTable.getName()); table.setSchema(schema); LOG.info("Found table " + table.getName()); schema.addDatabaseObject(snapshotObject(table, snapshot));
String fkName = liquibaseFK.getName(); logger.info("Synchronizing foreign key {}", fkName); String fkTableName = liquibaseFK.getForeignKeyTable().getName(); Table sourceTable = DatabaseLogic.findTableByNameIgnoreCase(sourceSchema, fkTableName);
String fkName = liquibaseFK.getName(); logger.info("Synchronizing foreign key {}", fkName); String fkTableName = liquibaseFK.getForeignKeyTable().getName(); Table sourceTable = DatabaseLogic.findTableByNameIgnoreCase(sourceSchema, fkTableName);
PrimaryKey primaryKey = null; int pkColumnPosition = 0; LOG.info("Found table " + table.getName());