@Test public void testExpandForCopyingTable() { CreateTable operation = SchemaOperations.createTable("users") .with("id", integer(), IDENTITY, AUTO_INCREMENT, NOT_NULL) .with("name", varchar(255), NOT_NULL); changelog.addChangeSet("Michael de Jong", "Creating 'users' table.", operation); migrator.migrate(catalog, refLog, changelog.getLastAdded(), operation); TableRef tableRef = refLog.getTableRef(changelog.getLastAdded(), "users"); String refId = tableRef.getRefId(); Table ghostTable = catalog.getTable(refId); Table expectedGhostTable = new Table(refId) .addColumn(new Column("id", integer(), IDENTITY, NOT_NULL, AUTO_INCREMENT)) .addColumn(new Column("name", varchar(255), NOT_NULL)); assertEquals(expectedGhostTable, ghostTable); assertEquals("users", refLog.getTableRefById(ghostTable.getName()).getName()); }
@Override public void migrate(Catalog catalog, RefLog refLog, Version version, CreateTable operation) { String refId = RandomHasher.generateRefId(refLog); String tableName = operation.getTableName(); refLog.fork(version); refLog.addTable(tableName, refId, version, operation.getColumns().stream() .map(column -> new ColumnRef(column.getName())) .collect(Collectors.toList())); Table table = new Table(refId); operation.getColumns().forEach(c -> table.addColumn(c.createColumn())); catalog.addTable(table); }
CreateTableMigrator implements SchemaOperationMigrator<CreateTable> { @Override public void migrate(Catalog catalog, RefLog refLog, Version version, CreateTable operation) { String refId = RandomHasher.generateRefId(refLog); String tableName = operation.getTableName(); refLog.fork(version); refLog.addTable(tableName, refId, version, operation.getColumns().stream() .map(column -> new ColumnRef(column.getName())) .collect(Collectors.toList())); Table table = new Table(refId); operation.getColumns().forEach(c -> table.addColumn(c.createColumn())); catalog.addTable(table); } }
CreateTableMigrator implements SchemaOperationMigrator<CreateTable> { @Override public void migrate(Catalog catalog, RefLog refLog, Version version, CreateTable operation) { String refId = RandomHasher.generateRefId(refLog); String tableName = operation.getTableName(); refLog.fork(version); refLog.addTable(tableName, refId, version, operation.getColumns().stream() .map(column -> new ColumnRef(column.getName())) .collect(Collectors.toList())); Table table = new Table(refId); operation.getColumns().forEach(c -> table.addColumn(c.createColumn())); catalog.addTable(table); }  }
CreateTableMigrator implements SchemaOperationMigrator<CreateTable> { @Override public void migrate(Catalog catalog, RefLog refLog, Version version, CreateTable operation) { String refId = RandomHasher.generateRefId(refLog); String tableName = operation.getTableName(); refLog.fork(version); refLog.addTable(tableName, refId, version, operation.getColumns().stream() .map(column -> new ColumnRef(column.getName())) .collect(Collectors.toList())); Table table = new Table(refId); operation.getColumns().forEach(c -> table.addColumn(c.createColumn())); catalog.addTable(table); }  @Override void migrate(Catalog catalog, RefLog refLog, Version version, CreateTable operation); }
CreateTableMigrator implements SchemaOperationMigrator<CreateTable> { @Override public void migrate(Catalog catalog, RefLog refLog, Version version, CreateTable operation) { String refId = RandomHasher.generateRefId(refLog); String tableName = operation.getTableName(); refLog.fork(version); refLog.addTable(tableName, refId, version, operation.getColumns().stream() .map(column -> new ColumnRef(column.getName())) .collect(Collectors.toList())); Table table = new Table(refId); operation.getColumns().forEach(c -> table.addColumn(c.createColumn())); catalog.addTable(table); }  @Override void migrate(Catalog catalog, RefLog refLog, Version version, CreateTable operation);  }