use of liquibase.ext.opennms.setsequence.SetSequenceGenerator in project opennms by OpenNMS.
the class SetSequenceGeneratorTest method testWithMultipleTables.
@Test
public void testWithMultipleTables() {
for (final Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof PostgresDatabase) {
final SetSequenceStatement statement = new SetSequenceStatement("SEQUENCE_NAME");
statement.addTable("TABLE1_NAME", "COLUMN1_NAME");
statement.addTable("TABLE2_NAME", "COLUMN2_NAME");
if (shouldBeImplementation(database)) {
final SqlGenerator<SetSequenceStatement> generator = this.generatorUnderTest;
final String tempTableName = ((SetSequenceGenerator) generator).getTempTableName();
final Sql[] sql = generator.generateSql(statement, database, null);
assertEquals("SELECT pg_catalog.setval('SEQUENCE_NAME',(SELECT max(" + tempTableName + ".id)+1 AS id FROM ((SELECT max(COLUMN1_NAME) AS id FROM TABLE1_NAME LIMIT 1) UNION (SELECT max(COLUMN2_NAME) AS id FROM TABLE2_NAME LIMIT 1)) AS " + tempTableName + " LIMIT 1),true);", sql[0].toSql());
}
}
}
}
use of liquibase.ext.opennms.setsequence.SetSequenceGenerator in project opennms by OpenNMS.
the class SetSequenceGeneratorTest method testBasicOperation.
@Test
public void testBasicOperation() {
for (final Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof PostgresDatabase) {
final SetSequenceStatement statement = new SetSequenceStatement("SEQUENCE_NAME");
statement.addTable("TABLE_NAME", "COLUMN1_NAME");
if (shouldBeImplementation(database)) {
final SqlGenerator<SetSequenceStatement> generator = this.generatorUnderTest;
final String tempTableName = ((SetSequenceGenerator) generator).getTempTableName();
final Sql[] sql = generator.generateSql(statement, database, null);
assertEquals("SELECT pg_catalog.setval('SEQUENCE_NAME',(SELECT max(" + tempTableName + ".id)+1 AS id FROM ((SELECT max(COLUMN1_NAME) AS id FROM TABLE_NAME LIMIT 1)) AS " + tempTableName + " LIMIT 1),true);", sql[0].toSql());
}
}
}
}
Aggregations