Search in sources :

Example 1 with SetSequenceGenerator

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());
            }
        }
    }
}
Also used : SetSequenceStatement(liquibase.ext.opennms.setsequence.SetSequenceStatement) SetSequenceGenerator(liquibase.ext.opennms.setsequence.SetSequenceGenerator) PostgresDatabase(liquibase.database.core.PostgresDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) Database(liquibase.database.Database) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 2 with SetSequenceGenerator

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());
            }
        }
    }
}
Also used : SetSequenceStatement(liquibase.ext.opennms.setsequence.SetSequenceStatement) SetSequenceGenerator(liquibase.ext.opennms.setsequence.SetSequenceGenerator) PostgresDatabase(liquibase.database.core.PostgresDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) Database(liquibase.database.Database) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Aggregations

Database (liquibase.database.Database)2 PostgresDatabase (liquibase.database.core.PostgresDatabase)2 SetSequenceGenerator (liquibase.ext.opennms.setsequence.SetSequenceGenerator)2 SetSequenceStatement (liquibase.ext.opennms.setsequence.SetSequenceStatement)2 Sql (liquibase.sql.Sql)2 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)2 Test (org.junit.Test)2